コード例 #1
0
        public void GetTournamentMatchId_Test()
        {
            var id = api.GetTournamentMatchId(region, tournamentCode);

            Assert.AreEqual(matchId, id);
        }
コード例 #2
0
        public static void GetMatchDetails(TournamentRiotApi api, Match match, bool callNewMatchHook)
        {
            MatchDetail matchDetails;

            // Get more match details
            try
            {
                if (match.RiotMatchId != 0)
                {
                    matchDetails = api.GetTournamentMatch(Region.euw, match.RiotMatchId, match.TournamentCode, false);
                }
                else
                {
                    var matchId = api.GetTournamentMatchId(Region.euw, match.TournamentCode);
                    matchDetails      = api.GetTournamentMatch(Region.euw, matchId, match.TournamentCode, false);
                    match.RiotMatchId = matchId;
                }
            }
            catch (Exception)
            {
                try
                {
                    if (match.RiotMatchId != 0)
                    {
                        matchDetails = api.GetTournamentMatch(Region.euw, match.RiotMatchId, match.TournamentCodeBlind, false);
                    }
                    else
                    {
                        var matchId = api.GetTournamentMatchId(Region.euw, match.TournamentCodeBlind);
                        matchDetails      = api.GetTournamentMatch(Region.euw, matchId, match.TournamentCodeBlind, false);
                        match.RiotMatchId = matchId;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            // Get the players that were supposed to be on blue side
            var supposedToBeBluePlayers = matchDetails.Participants.Where(matchDetailParticipant => match.BlueTeam.Participants.Select(localMatchParticipant => localMatchParticipant.Summoner.Name.ToLower()).Contains(matchDetails.ParticipantIdentities.Single(identity => identity.ParticipantId == matchDetailParticipant.ParticipantId).Player.SummonerName.ToLower())).ToList();

            if (supposedToBeBluePlayers.Count == 0)
            {
                // Teams did not have correct summoners playing the match. Match invalid.
                match.Invalid       = true;
                match.InvalidReason = "INCORRECT_SUMMONER_COUNT_BLUE_TEAM";

                // Save to database
                Mongo.Matches.Save(match);
            }

            // Set the team id to the side they actually played
            var blueTeamId = supposedToBeBluePlayers.First().TeamId;

            // Get the players that were supposed to be on red side
            var supposedToBeRedPlayers = matchDetails.Participants.Where(matchDetailParticipant => match.RedTeam.Participants.Select(localMatchParticipant => localMatchParticipant.Summoner.Name.ToLower()).Contains(matchDetails.ParticipantIdentities.Single(identity => identity.ParticipantId == matchDetailParticipant.ParticipantId).Player.SummonerName.ToLower())).ToList();

            if (supposedToBeRedPlayers.Count == 0)
            {
                // Teams did not have correct summoners playing the match. Match invalid.
                match.Invalid       = true;
                match.InvalidReason = "INCORRECT_SUMMONER_COUNT_RED_TEAM";

                // Save to database
                Mongo.Matches.Save(match);
            }

            // Set the team id to the side they actually played
            var redTeamId = supposedToBeRedPlayers.First().TeamId;

            // Set statistics
            match.Duration     = matchDetails.MatchDuration;
            match.CreationTime = matchDetails.MatchCreation;
            match.RiotMatchId  = matchDetails.MatchId;

            match.ChampionIds = matchDetails.Participants.Select(x => x.ChampionId).ToArray();

            // Exclude null bans for blind pick and for teams that forgot all their bans
            match.BanIds = matchDetails.Teams.Where(x => x.Bans != null).SelectMany(x => x.Bans).Select(x => x.ChampionId).ToArray();

            match.AssistsBlueTeam = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Assists);
            match.KillsBlueTeam   = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Kills);
            match.DeathsBlueTeam  = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Deaths);

            match.AssistsRedTeam = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Assists);
            match.KillsRedTeam   = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Kills);
            match.DeathsRedTeam  = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Deaths);

            match.Invalid = false;

            if (blueTeamId == 200)
            {
                match.PlayedWrongSide = true;
            }

            // Save to database
            Mongo.Matches.Save(match);

            // Call the new match hook
            if (callNewMatchHook)
            {
                BracketHelper.NewMatch(match);
            }
        }