public MatchDetailContract(bool isBlue, MatchDetailEntity matchDetail, PlayerStatsEntity playerStats, List <AchievementEntity> achievements) { IsBlue = isBlue; MatchDetail = matchDetail; PlayerStats = playerStats; Achievements = achievements; }
public async Task CollectPlayerMatchDetailsAsync(MatchSubmissionView view, Match riotMatch, ChampionListStatic champions, GameInfo gameInfo, Dictionary <string, SummonerInfoEntity> registeredPlayers, TimeSpan gameDuration, SeasonInfoEntity seasonInfo, Dictionary <MatchDetailKey, MatchDetailEntity> matchDictionary, List <MatchDetailContract> matchList, Guid divisionId, List <ChampionStatsEntity> championDetails) { var blueTotalKills = riotMatch.Participants.Where(x => x.TeamId == 100).Sum(y => y.Stats.Kills); var redTotalKills = riotMatch.Participants.Where(x => x.TeamId == 200).Sum(y => y.Stats.Kills); foreach (var participant in riotMatch.Participants) { //Get champion by Riot Api var riotChampion = champions.Keys[participant.ChampionId].ToLowerInvariant(); //Get who played said champion and if they were blue side or not var gameInfoPlayer = gameInfo.PlayerName(riotChampion); //If the player listed doesn't match a champion, then we ignore it for purposes of stat tracking if (gameInfoPlayer == null) { continue; } //Check to make sure the player is officially registered, if not, this will send a red flag registeredPlayers.TryGetValue(gameInfoPlayer.PlayerName.ToLowerInvariant(), out var registeredPlayer); if (registeredPlayer == null) { var message = $"This player is not legal for a match as a player: {gameInfoPlayer.PlayerName}"; _logger.LogCritical(message); const string to = "*****@*****.**"; await _emailService.SendEmailAsync(to, message, $"Illegal player in match: {view.HomeTeamName} vs {view.AwayTeamName}"); throw new Exception(message); } var matchStat = CreatePlayerMatchStat(registeredPlayer, participant, gameDuration, seasonInfo); switch (participant.TeamId) { case 100: matchStat.TotalTeamKills = (int)blueTotalKills; break; case 200: matchStat.TotalTeamKills = (int)redTotalKills; break; } //will always create a new match detail var matchDetail = new MatchDetailEntity { Id = Guid.NewGuid(), Game = gameInfo.GameNum, PlayerId = registeredPlayer.Id, PlayerStatsId = matchStat.Id, SeasonInfoId = seasonInfo.Id, TeamScheduleId = view.ScheduleId, Winner = participant.Stats.Winner }; //per player var win = participant.Stats.Winner; var loss = !win; var ourChampion = GlobalVariables.ChampionDictionary[riotChampion]; var pickedChampionStat = CreateChampionStat(matchStat, seasonInfo, divisionId, win, loss, ourChampion.Id, matchDetail.Id, view.ScheduleId); championDetails.Add(pickedChampionStat); //Add special achievements here var achievements = await AddSpecialAchievements(participant, ourChampion, registeredPlayer, seasonInfo.Id, riotMatch, view, gameInfo.GameNum); matchList.Add(new MatchDetailContract(gameInfoPlayer.IsBlue, matchDetail, matchStat, achievements)); } }