private async Task <PlayerOverview> UpdatePlayers(MatchFinishedEvent nextEvent, List <PlayerMMrChange> players)
        {
            var playerIds = players.Select(w => PlayerId.Create(w.battleTag)).ToList();

            var match = nextEvent.match;
            var playerRaceIfSingle = match.gameMode == GameMode.GM_1v1 && match.season >= 2 ? (Race?)players.Single().race : null;
            var winnerIdCombined   = new BattleTagIdCombined(
                players.Select(p =>
                               PlayerId.Create(p.battleTag)).ToList(),
                match.gateway,
                match.gameMode,
                match.season,
                playerRaceIfSingle);

            var winner = await _playerRepository.LoadOverview(winnerIdCombined.Id)
                         ?? PlayerOverview.Create(
                playerIds,
                match.gateway,
                match.gameMode,
                match.season,
                playerRaceIfSingle);

            winner.RecordWin(
                players.First().won,
                (int?)players.First().updatedMmr?.rating ?? (int?)players.First().mmr?.rating ?? 0);

            return(winner);
        }
 public static PlayerGameModeStatPerGateway Create(BattleTagIdCombined id)
 {
     return(new PlayerGameModeStatPerGateway
     {
         Id = id.Id,
         Season = id.Season,
         GateWay = id.GateWay,
         GameMode = id.GameMode,
         PlayerIds = id.BattleTags
     });
 }
        public void Player_RecentProgress_NewPlayer()
        {
            var btag = new BattleTagIdCombined(new List <PlayerId>
            {
                PlayerId.Create("Peter#12")
            },
                                               GateWay.America,
                                               GameMode.GM_1v1,
                                               0);
            var gameModeStatPerGateway = PlayerGameModeStatPerGateway.Create(btag);

            gameModeStatPerGateway.RecordRanking(100, 180);
            gameModeStatPerGateway.RecordRanking(100, 230);

            Assert.AreEqual(50, gameModeStatPerGateway.RankingPointsProgress.RankingPoints);
        }
        public void Player_RecentProgress_DoubleUpdate_NegativeThenPositive()
        {
            var btag = new BattleTagIdCombined(new List <PlayerId>
            {
                PlayerId.Create("Peter#12")
            },
                                               GateWay.America,
                                               GameMode.GM_1v1,
                                               0);
            var gameModeStatPerGateway = PlayerGameModeStatPerGateway.Create(btag);

            gameModeStatPerGateway.RankProgressionStart = RankProgression.Create(0, 200);
            gameModeStatPerGateway.RecordRanking(100, 180);
            gameModeStatPerGateway.RecordRanking(100, 230);

            Assert.AreEqual(30, gameModeStatPerGateway.RankingPointsProgress.RankingPoints);
        }
        public void Player_RecentProgress_Mapping()
        {
            var btag = new BattleTagIdCombined(new List <PlayerId>
            {
                PlayerId.Create("Peter#12")
            },
                                               GateWay.America,
                                               GameMode.GM_1v1,
                                               0);
            var gameModeStatPerGateway = PlayerGameModeStatPerGateway.Create(btag);

            gameModeStatPerGateway.RankProgressionStart = RankProgression.Create(90, 200);
            gameModeStatPerGateway.RecordRanking(100, 220);

            Assert.AreEqual(20, gameModeStatPerGateway.RankingPointsProgress.RankingPoints);
            Assert.AreEqual(10, gameModeStatPerGateway.RankingPointsProgress.MMR);
        }
        private async Task RecordWin(Match match, List <PlayerMMrChange> winners)
        {
            var winnerId = new BattleTagIdCombined(
                winners.Select(w => PlayerId.Create(w.battleTag)).ToList(),
                match.gateway,
                match.gameMode,
                match.season);

            var winner = await _playerRepository.LoadGameModeStatPerGateway(winnerId.Id) ?? PlayerGameModeStatPerGateway.Create(winnerId);

            winner.RecordWin(true);
            winner.RecordRanking(
                (int?)winners.First().updatedMmr?.rating ?? (int?)winners.First().mmr?.rating ?? 0,
                (int?)winners.First().updatedRanking?.rp ?? (int?)winners.First().ranking?.rp ?? 0);

            await _playerRepository.UpsertPlayerGameModeStatPerGateway(winner);
        }
        public void Player_RecentProgress_After8Hours()
        {
            var btag = new BattleTagIdCombined(new List <PlayerId>
            {
                PlayerId.Create("Peter#12")
            },
                                               GateWay.America,
                                               GameMode.GM_1v1,
                                               0);
            var gameModeStatPerGateway = PlayerGameModeStatPerGateway.Create(btag);

            gameModeStatPerGateway.RankProgressionStart = RankProgression.Create(0, 200);
            gameModeStatPerGateway.RecordRanking(100, 180);
            gameModeStatPerGateway.RankProgressionStart.Date = DateTimeOffset.UtcNow.AddDays(-1);
            gameModeStatPerGateway.RecordRanking(100, 230);

            Assert.AreEqual(0, gameModeStatPerGateway.RankingPointsProgress.RankingPoints);
        }
        private async Task RecordLoss(Match match, List <PlayerMMrChange> losingTeam)
        {
            var loserId = new BattleTagIdCombined(
                losingTeam.Select(w => PlayerId.Create(w.battleTag)).ToList(),
                match.gateway,
                match.gameMode,
                match.season);

            var loser = await _playerRepository.LoadGameModeStatPerGateway(loserId.Id) ?? PlayerGameModeStatPerGateway.Create(loserId);

            loser.RecordWin(false);

            var firstLooser = losingTeam.First();

            loser.RecordRanking(
                (int?)firstLooser.updatedMmr?.rating ?? (int?)firstLooser.mmr?.rating ?? 0,
                (int?)firstLooser.updatedRanking?.rp ?? (int?)firstLooser.ranking?.rp ?? 0);

            await _playerRepository.UpsertPlayerGameModeStatPerGateway(loser);
        }
예제 #9
0
        public async Task PlayerStatsMapping()
        {
            var playerRepository = new PlayerRepository(MongoClient);

            var battleTagIdCombined = new BattleTagIdCombined(new List <PlayerId>
            {
                PlayerId.Create("peter#123")
            },
                                                              GateWay.Europe,
                                                              GameMode.GM_1v1,
                                                              1);
            var player = PlayerGameModeStatPerGateway.Create(battleTagIdCombined);

            player.RecordRanking(234, 123);

            await playerRepository.UpsertPlayerGameModeStatPerGateway(player);

            var playerLoadedAgain = await playerRepository.LoadGameModeStatPerGateway("peter#123", GateWay.Europe, 1);

            Assert.AreEqual(234, playerLoadedAgain.Single().MMR);
            Assert.AreEqual(123, playerLoadedAgain.Single().RankingPoints);
        }