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); }
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); }