示例#1
0
        public async Task Update(MatchFinishedEvent nextEvent)
        {
            if (nextEvent.WasFakeEvent)
            {
                return;
            }
            var matchup = Matchup.Create(nextEvent);
            await _matchRepository.Insert(matchup);

            await _matchRepository.DeleteOnGoingMatch(matchup.MatchId);
        }
        public static Matchup Create(MatchFinishedEvent matchFinishedEvent)
        {
            var match = matchFinishedEvent.match;

            var startTime = DateTimeOffset.FromUnixTimeMilliseconds(matchFinishedEvent.match.startTime);
            var endTime   = DateTimeOffset.FromUnixTimeMilliseconds(matchFinishedEvent.match.endTime);

            var result = new Matchup()
            {
                Id        = matchFinishedEvent.Id,
                Map       = new MapName(matchFinishedEvent.match.map).Name,
                MatchId   = match.id,
                GateWay   = match.gateway,
                GameMode  = matchFinishedEvent.match.gameMode,
                StartTime = startTime,
                EndTime   = endTime,
                Duration  = endTime - startTime,
                Season    = match.season
            };

            result.SetServerInfo(match);

            var players = match.players
                          .OrderByDescending(x => x.won)
                          .ThenBy(x => x.team)
                          .ToList();

            var teamGroups = SplitPlayersIntoTeams(players, match.gameMode);

            foreach (var team in teamGroups)
            {
                result.Teams.Add(CreateTeam(team.Value));
                result.Teams = result.Teams
                               .OrderByDescending(x => x.Players.Any(y => y.Won))
                               .ToList();
            }

            SetTeamPlayers(result);

            return(result);
        }
        protected static void SetTeamPlayers(Matchup result)
        {
            if (result.Teams.Count > 0)
            {
                result.Team1Players = string.Join(";", result.Teams[0].Players.Select(x => x.BattleTag));
            }

            if (result.Teams.Count > 1)
            {
                result.Team2Players = string.Join(";", result.Teams[1].Players.Select(x => x.BattleTag));
            }

            if (result.Teams.Count > 2)
            {
                result.Team3Players = string.Join(";", result.Teams[2].Players.Select(x => x.BattleTag));
            }

            if (result.Teams.Count > 3)
            {
                result.Team4Players = string.Join(";", result.Teams[3].Players.Select(x => x.BattleTag));
            }
        }
        public async Task Update(MatchFinishedEvent nextEvent)
        {
            try
            {
                if (nextEvent.WasFakeEvent)
                {
                    return;
                }
                var count = await _matchRepository.Count();

                var matchup = Matchup.Create(nextEvent);

                matchup.Number = count + 1;

                await _matchRepository.Insert(matchup);

                await _matchRepository.DeleteOnGoingMatch(matchup.MatchId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#5
0
 public Task Insert(Matchup matchup)
 {
     return(Upsert(matchup, m => m.MatchId == matchup.MatchId));
 }
示例#6
0
        public static Matchup Create(MatchFinishedEvent matchFinishedEvent)
        {
            var match = matchFinishedEvent.match;

            var startTime = DateTimeOffset.FromUnixTimeMilliseconds(matchFinishedEvent.match.startTime);
            var endTime   = DateTimeOffset.FromUnixTimeMilliseconds(matchFinishedEvent.match.endTime);

            var result = new Matchup()
            {
                Id        = matchFinishedEvent.Id,
                Map       = new MapName(matchFinishedEvent.match.map).Name,
                MatchId   = match.id,
                GateWay   = match.gateway,
                GameMode  = matchFinishedEvent.match.gameMode,
                StartTime = startTime,
                EndTime   = endTime,
                Duration  = endTime - startTime,
                Season    = match.season
            };

            result.SetServerInfo(match);

            var players = match.players
                          .OrderByDescending(x => x.won)
                          .ThenBy(x => x.team)
                          .ToList();

            foreach (var player in players)
            {
                if (player.race == Race.RnD)
                {
                    PlayerBlizzard resultPlayer = null;
                    player.rndRace = Race.RnD;

                    if (matchFinishedEvent.result != null)
                    {
                        resultPlayer = matchFinishedEvent.result.players?.FirstOrDefault(p => p.battleTag == player.battleTag);
                    }

                    if (resultPlayer != null)
                    {
                        // If the player chose random for the match,
                        // set their actual randomized race from the result.
                        player.rndRace = player.race.FromRaceId((RaceId)resultPlayer.raceId);
                    }
                }
            }

            var teamGroups = SplitPlayersIntoTeams(players, match.gameMode);

            foreach (var team in teamGroups)
            {
                result.Teams.Add(CreateTeam(team.Value));
                result.Teams = result.Teams
                               .OrderByDescending(x => x.Players.Any(y => y.Won))
                               .ToList();
            }

            SetTeamPlayers(result);

            return(result);
        }