示例#1
0
        public void CollectMatchMvpData(MatchSubmissionView view, List <MatchDetailContract> matchList, Dictionary <string, SummonerInfoEntity> registeredPlayers,
                                        GameInfo gameInfo, Dictionary <int, MatchMvpEntity> mvpDetails, List <MatchMvpEntity> updateMvpDetails,
                                        List <MatchMvpEntity> insertMvpDetails, SummonerInfoEntity userPlayer)
        {
            var validMvpPlayers = new List <Guid>();

            validMvpPlayers.AddRange(matchList.Select(x => x.MatchDetail.PlayerId));

            registeredPlayers.TryGetValue(gameInfo.BlueMvp.ToLowerInvariant(), out var blueMvp);
            registeredPlayers.TryGetValue(gameInfo.RedMvp.ToLowerInvariant(), out var redMvp);
            registeredPlayers.TryGetValue(gameInfo.BlueMvp.ToLowerInvariant(), out var honoraryBlueOppMvp);
            registeredPlayers.TryGetValue(gameInfo.RedMvp.ToLowerInvariant(), out var honoraryRedOppMvp);

            if (mvpDetails.TryGetValue(gameInfo.GameNum, out var mvpEntity))
            {
                if (!string.IsNullOrEmpty(gameInfo.BlueMvp) && blueMvp != null && blueMvp.Id != mvpEntity.BlueMvp &&
                    validMvpPlayers.Contains(blueMvp.Id))
                {
                    mvpEntity.BlueMvp = blueMvp.Id;
                }

                if (!string.IsNullOrEmpty(gameInfo.RedMvp) && redMvp != null && redMvp.Id != mvpEntity.RedMvp &&
                    validMvpPlayers.Contains(redMvp.Id))
                {
                    mvpEntity.RedMvp = redMvp.Id;
                }
                if (!string.IsNullOrEmpty(gameInfo.HonoraryBlueOppMvp) && honoraryBlueOppMvp != null && honoraryBlueOppMvp.Id != mvpEntity.HonoraryBlueOppMvp &&
                    validMvpPlayers.Contains(honoraryBlueOppMvp.Id))
                {
                    mvpEntity.HonoraryBlueOppMvp = honoraryBlueOppMvp.Id;
                }

                if (!string.IsNullOrEmpty(gameInfo.HonoraryRedOppMvp) && honoraryRedOppMvp != null && honoraryRedOppMvp.Id != mvpEntity.HonoraryRedOppMvp &&
                    validMvpPlayers.Contains(honoraryRedOppMvp.Id))
                {
                    mvpEntity.HonoraryRedOppMvp = honoraryRedOppMvp.Id;
                }

                mvpEntity.UpdatedBy = userPlayer.SummonerName;
                mvpEntity.UpdatedOn = DateTime.Now;
                updateMvpDetails.Add(mvpEntity);
            }
            else
            {
                mvpEntity = new MatchMvpEntity
                {
                    Id             = Guid.NewGuid(),
                    BlueMvp        = blueMvp != null && validMvpPlayers.Contains(blueMvp.Id) ? blueMvp.Id : new Guid?(),
                    RedMvp         = redMvp != null && validMvpPlayers.Contains(redMvp.Id) ? redMvp.Id : new Guid?(),
                    Game           = gameInfo.GameNum,
                    TeamScheduleId = view.ScheduleId,
                    CreatedBy      = userPlayer.SummonerName,
                    CreatedOn      = DateTime.Now
                };
                insertMvpDetails.Add(mvpEntity);
            }
        }
示例#2
0
        public void CollectMatchMvpData(SimplifiedMatchSubmissionView view,
                                        Dictionary <string, SummonerInfoEntity> registeredPlayers,
                                        GameDetail gameInfo, Dictionary <int, MatchMvpEntity> mvpDetails, List <MatchMvpEntity> updateMvpDetails,
                                        List <MatchMvpEntity> insertMvpDetails, SummonerInfoEntity userPlayer)
        {
            registeredPlayers.TryGetValue(gameInfo.BlueMvp.ToLowerInvariant(), out var blueMvp);
            registeredPlayers.TryGetValue(gameInfo.RedMvp.ToLowerInvariant(), out var redMvp);
            registeredPlayers.TryGetValue(gameInfo.HonoraryBlueOppMvp.ToLowerInvariant(), out var honoraryBlueOppMvp);
            registeredPlayers.TryGetValue(gameInfo.HonoraryRedOppMvp.ToLowerInvariant(), out var honoraryRedOppMvp);

            if (mvpDetails.TryGetValue(gameInfo.GameNum, out var mvpEntity))
            {
                if (!string.IsNullOrEmpty(gameInfo.BlueMvp) && blueMvp != null && blueMvp.Id != mvpEntity.BlueMvp)
                {
                    mvpEntity.BlueMvp = blueMvp.Id;
                }

                if (!string.IsNullOrEmpty(gameInfo.RedMvp) && redMvp != null && redMvp.Id != mvpEntity.RedMvp)
                {
                    mvpEntity.RedMvp = redMvp.Id;
                }
                if (!string.IsNullOrEmpty(gameInfo.HonoraryBlueOppMvp) && honoraryBlueOppMvp != null &&
                    honoraryBlueOppMvp.Id != mvpEntity.HonoraryBlueOppMvp)
                {
                    mvpEntity.HonoraryBlueOppMvp = honoraryBlueOppMvp.Id;
                }

                if (!string.IsNullOrEmpty(gameInfo.HonoraryRedOppMvp) && honoraryRedOppMvp != null &&
                    honoraryRedOppMvp.Id != mvpEntity.HonoraryRedOppMvp)
                {
                    mvpEntity.HonoraryRedOppMvp = honoraryRedOppMvp.Id;
                }

                mvpEntity.UpdatedBy = userPlayer.SummonerName;
                mvpEntity.UpdatedOn = DateTime.Now;
                updateMvpDetails.Add(mvpEntity);
            }
            else
            {
                mvpEntity = new MatchMvpEntity
                {
                    Id                 = Guid.NewGuid(),
                    BlueMvp            = blueMvp?.Id,
                    RedMvp             = redMvp?.Id,
                    HonoraryBlueOppMvp = honoraryBlueOppMvp?.Id,
                    HonoraryRedOppMvp  = honoraryRedOppMvp?.Id,
                    Game               = gameInfo.GameNum,
                    TeamScheduleId     = view.ScheduleId,
                    CreatedBy          = userPlayer.SummonerName,
                    CreatedOn          = DateTime.Now
                };
                insertMvpDetails.Add(mvpEntity);
            }
        }
示例#3
0
        public async Task <bool> SendFileData(MatchSubmissionView view, SummonerInfoEntity userPlayer)
        {
            if (!GlobalVariables.ChampionDictionary.Any())
            {
                await GlobalVariables.SetupChampionCache(_lookupRepository);
            }
            var addMatchStats = await UpdateStatsAsync(view, userPlayer);

            if (!addMatchStats)
            {
                return(false);
            }

            var csvDataFile = CreateCsvDataFile(view);

            return(await SendRoflFilesAsync(view, csvDataFile));
        }
示例#4
0
        public async Task <bool> SendFileData(SimplifiedMatchSubmissionView view, SummonerInfoEntity userPlayer)
        {
            //var di = new DirectoryInfo(Path.Combine(_wwwRootDirectory, "MatchCsvs"));
            //foreach (var file in di.EnumerateFiles())
            //{
            //    file.Delete();
            //}

            var addMatchStats = await UpdateStatsAsync(view, userPlayer);

            if (!addMatchStats)
            {
                return(false);
            }

            var csvDataFile = CreateCsvDataFile(view);

            return(await SendRoflFilesAsync(view, csvDataFile));
        }
 public SummonerInfoView Map(SummonerInfoEntity entity)
 {
     return(new SummonerInfoView
     {
         SummonerName = entity.SummonerName,
         Role = _summonerRoleMapper.Map(entity.RoleId),
         OffRole = entity.OffRoleId.HasValue ? _summonerRoleMapper.Map(entity.OffRoleId.Value) : SummonerRoleEnum.None,
         TierDivision = _tierDivisionMapper.Map(entity.Tier_DivisionId),
         PreviousSeasonTierDivision = entity.PreviousSeasonRankId != null
             ? _tierDivisionMapper.Map(entity.PreviousSeasonRankId.Value)
             : default(TierDivisionEnum?),
         CurrentLp = entity.CurrentLp,
         OpGgUrl = entity.OpGGUrlLink,
         IsValid = entity.IsValidPlayer,
         IsSubOnly = entity.IsSubOnly ?? false,
         IsAcademyPlayer = entity.IsAcademyPlayer,
         DiscordHandle = entity.DiscordHandle
     });
 }
示例#6
0
        private static PlayerStatsEntity CreatePlayerMatchStat(SummonerInfoEntity registeredPlayer, Participant participant,
                                                               TimeSpan gameDuration, SeasonInfoEntity seasonInfo)
        {
            var matchStat = new PlayerStatsEntity
            {
                Id           = Guid.NewGuid(),
                SummonerId   = registeredPlayer.Id,
                Kills        = (int)participant.Stats.Kills,
                Deaths       = (int)participant.Stats.Deaths,
                Assists      = (int)participant.Stats.Assists,
                CS           = (int)(participant.Stats.TotalMinionsKilled + participant.Stats.NeutralMinionsKilled),
                Gold         = (int)participant.Stats.GoldEarned,
                VisionScore  = (int)participant.Stats.VisionScore,
                GameTime     = gameDuration,
                Games        = 1,
                SeasonInfoId = seasonInfo.Id
            };

            return(matchStat);
        }
 public DetailedSummonerInfoView MapDetailed(SummonerInfoEntity entity, IEnumerable <AlternateAccountEntity> alternates, PlayerStatsView stats = null)
 {
     return(new DetailedSummonerInfoView
     {
         Id = entity.Id,
         UserId = entity.UserId,
         SummonerName = entity.SummonerName,
         AlternateAccounts = alternates != null?_alternateAccountMapper.Map(alternates).ToList() : new List <AlternateAccountView>(),
                                 Role = _summonerRoleMapper.Map(entity.RoleId),
                                 OffRole = entity.OffRoleId.HasValue ? _summonerRoleMapper.Map(entity.OffRoleId.Value) : SummonerRoleEnum.None,
                                 TierDivision = _tierDivisionMapper.Map(entity.Tier_DivisionId),
                                 PreviousSeasonTierDivision = entity.PreviousSeasonRankId != null
             ? _tierDivisionMapper.Map(entity.PreviousSeasonRankId.Value)
             : default(TierDivisionEnum?),
                                 CurrentLp = entity.CurrentLp,
                                 OpGgUrl = entity.OpGGUrlLink,
                                 IsValid = entity.IsValidPlayer,
                                 PlayerStats = stats,
                                 IsSubOnly = entity.IsSubOnly ?? false,
                                 TeamRole = entity.TeamRoleId == null?_summonerRoleMapper.Map(entity.RoleId) : _summonerRoleMapper.Map(entity.TeamRoleId.Value),
                                                IsAcademyPlayer = entity.IsAcademyPlayer,
                                                DiscordHandle = entity.DiscordHandle
     });
 }
示例#8
0
        public async Task <List <AchievementEntity> > AddSpecialAchievements(Participant player, LookupEntity ourChampion, SummonerInfoEntity summonerInfo, Guid seasonInfoId, Match riotMatch, MatchSubmissionView view, int currentGame)
        {
            var achievements  = new List <AchievementEntity>();
            var teamName      = "N/a";
            var currentTeamId = (await _teamPlayerRepository.GetBySummonerAndSeasonIdAsync(summonerInfo.Id, seasonInfoId))?.TeamRosterId;

            if (currentTeamId != null)
            {
                var playerTeam = await _teamRosterRepository.GetByTeamIdAsync(currentTeamId.Value);

                if (playerTeam.TeamName == view.HomeTeamName || playerTeam.TeamName == view.AwayTeamName)
                {
                    teamName = playerTeam.TeamName;
                }
            }

            if (player.Stats.LargestMultiKill >= 5)
            {
                var achivement = new AchievementEntity
                {
                    Id           = Guid.NewGuid(),
                    UserId       = summonerInfo.UserId,
                    AchievedDate = DateTime.Today,
                    AchievedTeam = teamName,
                    Achievement  = $"Penta-kill on {ourChampion.Value} in game {currentGame}"
                };
                achievements.Add(achivement);
            }

            var blueTeamPlayers = riotMatch.Participants.Where(x => x.TeamId == 100);
            var redTeamPlayers  = riotMatch.Participants.Where(x => x.TeamId == 200);


            var blueTotalKills = blueTeamPlayers.Sum(y => y.Stats.Kills);
            var redTotalKills  = redTeamPlayers.Sum(y => y.Stats.Kills);
            var isBlue         = player.TeamId == 100;

            if (isBlue && redTotalKills == 0 || !isBlue && blueTotalKills == 0)
            {
                var blueTeam = riotMatch.Teams.First(x => x.TeamId == 100);
                var redTeam  = riotMatch.Teams.First(x => x.TeamId == 200);
                if (blueTeam.DragonKills == 0 && blueTeam.BaronKills == 0 && blueTeam.TowerKills == 0 && !isBlue ||
                    redTeam.DragonKills == 0 && redTeam.BaronKills == 0 && redTeam.TowerKills == 0 && isBlue)
                {
                    var achivement = new AchievementEntity
                    {
                        Id           = Guid.NewGuid(),
                        UserId       = summonerInfo.UserId,
                        AchievedDate = DateTime.Today,
                        AchievedTeam = teamName,
                        Achievement  = $"Perfect Game on {ourChampion.Value} in game {currentGame}"
                    };
                    achievements.Add(achivement);
                }
            }

            try
            {
                var oldAchievements = (await _achievementRepository.GetAchievementsForUserAsync(summonerInfo.UserId)).ToList();
                var tempList        = new List <AchievementEntity>(achievements);
                foreach (var newAchievement in tempList)
                {
                    var match = oldAchievements.FirstOrDefault(x => x.Equals(newAchievement));
                    if (match != null)
                    {
                        achievements.Remove(newAchievement);
                    }
                }
            }
            catch (Exception)
            {
                //ignore
            }

            return(achievements);
        }
示例#9
0
        private async Task <bool> UpdateStatsAsync(MatchSubmissionView view, SummonerInfoEntity userPlayer)
        {
            var divisionTask = _scheduleService.GetDivisionIdByScheduleAsync(view.ScheduleId);
            var matchesTask  = _matchDetailRepository.ReadForScheduleId(view.ScheduleId);
            var seasonInfo   = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var registeredPlayersTask  = _summonerInfoRepository.GetAllValidSummonersAsync();
            var previousListedMvpsTask = _matchMvpRepository.ReadAllForTeamScheduleId(view.ScheduleId);
            var registeredPlayers      = (await registeredPlayersTask).ToDictionary(x => x.SummonerName.ToLowerInvariant(), x => x);
            var matchDictionary        = (await matchesTask);
            var mvpDetails             = (await previousListedMvpsTask).OrderBy(x => x.Game).ToDictionary(x => x.Game, x => x);

            var divisionId       = await divisionTask;
            var insertMvpDetails = new List <MatchMvpEntity>();
            var updateMvpDetails = new List <MatchMvpEntity>();
            //Will always insert new records and never update, we will delete any old records first
            var insertDetailsList      = new List <MatchDetailEntity>();
            var insertStatsList        = new List <PlayerStatsEntity>();
            var championDetails        = new List <ChampionStatsEntity>();
            var insertAchievementsList = new List <AchievementEntity>();

            //List of Ids to hard delete

            foreach (var gameInfo in view.GameInfos)
            {
                if (gameInfo.HomeTeamForfeit || gameInfo.AwayTeamForfeit)
                {
                    continue;
                }

                //matchhistory.na.leagueoflegends.com/en/#match-details/NA1/{match id}/{dont care}?tab=overview
                var split = gameInfo.MatchHistoryLink.Split("/");
                //If an invalid match was submitted, will fail the entire process
                if (!uint.TryParse(split[6], out var matchId))
                {
                    return(false);
                }

                var version       = (await GlobalVariables.ChampsApi.Versions.GetAllAsync()).First();
                var championsTask = GlobalVariables.ChampsApi.Champions.GetAllAsync(version);
                var riotMatchTask = GlobalVariables.Api.Match.GetMatchAsync(RiotSharp.Misc.Region.Na, matchId);

                var riotMatch = await riotMatchTask;
                var champions = await championsTask;

                CollectBans(view, riotMatch, champions, seasonInfo, divisionId, championDetails);

                var gameDuration = riotMatch.GameDuration;

                var matchList = new List <MatchDetailContract>();

                await CollectPlayerMatchDetailsAsync(view, riotMatch, champions, gameInfo, registeredPlayers, gameDuration, seasonInfo, matchDictionary,
                                                     matchList, divisionId, championDetails);

                CollectMatchMvpData(view, matchList, registeredPlayers, gameInfo, mvpDetails, updateMvpDetails, insertMvpDetails, userPlayer);

                insertDetailsList.AddRange(matchList.Select(x => x.MatchDetail));
                insertStatsList.AddRange(matchList.Select(x => x.PlayerStats));
                insertAchievementsList.AddRange(matchList.SelectMany(x => x.Achievements));
            }

            if (!await DeleteOldRecords(view))
            {
                return(false);
            }

            var insertAchievementsResult = await _achievementRepository.InsertAsync(insertAchievementsList);

            var insertMvpResult = await _matchMvpRepository.CreateAsync(insertMvpDetails);

            var updateMvpResult = await _matchMvpRepository.UpdateAsync(updateMvpDetails);

            var insertStatsResult = await _playerStatsRepository.InsertAsync(insertStatsList);

            var insertDetailsResult = await _matchDetailRepository.InsertAsync(insertDetailsList);

            var insertChampionStatsResult = await _championStatsRepository.CreateAsync(championDetails);

            return(insertStatsResult && insertDetailsResult && insertMvpResult && updateMvpResult && insertChampionStatsResult && insertAchievementsResult);
        }
示例#10
0
        private async Task <bool> UpdateStatsAsync(SimplifiedMatchSubmissionView view, SummonerInfoEntity userPlayer)
        {
            var registeredPlayersTask  = _summonerInfoRepository.GetAllValidSummonersAsync();
            var previousListedMvpsTask = _matchMvpRepository.ReadAllForTeamScheduleId(view.ScheduleId);
            var registeredPlayers      = (await registeredPlayersTask).ToDictionary(x => x.SummonerName.ToLowerInvariant(), x => x);
            var mvpDetails             = (await previousListedMvpsTask).OrderBy(x => x.Game).ToDictionary(x => x.Game, x => x);

            var insertMvpDetails = new List <MatchMvpEntity>();
            var updateMvpDetails = new List <MatchMvpEntity>();

            foreach (var gameInfo in view.GameDetails)
            {
                if (gameInfo.HomeTeamForfeit || gameInfo.AwayTeamForfeit)
                {
                    continue;
                }

                var matchList = new List <MatchDetailContract>();

                CollectMatchMvpData(view, registeredPlayers, gameInfo, mvpDetails, updateMvpDetails, insertMvpDetails, userPlayer);
            }

            var insertMvpResult = await _matchMvpRepository.CreateAsync(insertMvpDetails);

            var updateMvpResult = await _matchMvpRepository.UpdateAsync(updateMvpDetails);

            return(insertMvpResult && updateMvpResult);
        }
示例#11
0
 public async Task <bool> InsertAsync(SummonerInfoEntity entity)
 {
     return(await _table.InsertAsync(entity) == 1);
 }