コード例 #1
0
        private static MatchResult GetMatchResult(ServerMatch serverMatch, bool isFirstTeam)
        {
            if (serverMatch.Team2 > serverMatch.Team3)
            {
                return(isFirstTeam ? MatchResult.Win : MatchResult.Lost);
            }

            if (serverMatch.Team3 > serverMatch.Team2)
            {
                return(isFirstTeam ? MatchResult.Lost : MatchResult.Win);
            }

            return(MatchResult.Draw);
        }
コード例 #2
0
        private async Task <Match> CreateMatch(ServerMatch serverMatch)
        {
            var matchDetails = await _serverStatsDbContext.MatchesDetails
                               .Where(x => x.MatchId == serverMatch.MatchId && !string.IsNullOrEmpty(x.SteamId))
                               .ToListAsync();

            var firstTeamMatchDetails  = matchDetails.Where(x => x.Team == 2).ToList();
            var secondTeamMatchDetails = matchDetails.Where(x => x.Team == 3).ToList();

            var firstTeamPlayers = await GetOrCreateTeamPlayers(firstTeamMatchDetails);

            var secondTeamPlayers = await GetOrCreateTeamPlayers(secondTeamMatchDetails);

            var firstTeam = await GetOrCreateTeamAsync(firstTeamPlayers, serverMatch.TeamFlag1);

            var secondTeam = await GetOrCreateTeamAsync(secondTeamPlayers, serverMatch.TeamFlag2);

            return(new Match
            {
                OriginalMatchId = serverMatch.MatchId,
                Map = serverMatch.Map,
                MatchFinishedAt = serverMatch.Timestamp,
                CreatedDate = DateTimeOffset.UtcNow,
                TeamInMatches = new List <TeamInMatch>
                {
                    new TeamInMatch
                    {
                        Team = firstTeam,
                        Result = GetMatchResult(serverMatch, true),
                        Score = serverMatch.Team2,
                        PlayerInTeamInMatches = firstTeamPlayers
                                                .Select(x => CreatePlayersInTeamInMatch(x, firstTeamMatchDetails)).ToList()
                    },
                    new TeamInMatch
                    {
                        Team = secondTeam,
                        Result = GetMatchResult(serverMatch, false),
                        Score = serverMatch.Team3,
                        PlayerInTeamInMatches = secondTeamPlayers
                                                .Select(x => CreatePlayersInTeamInMatch(x, secondTeamMatchDetails)).ToList()
                    }
                }
            });
        }