Пример #1
0
 public static IEnumerable <Player> GetSelectedPlayersByTeamId(int teamId, int matchId)
 {
     return(Players.Where(p => p.TeamId == teamId &&
                          p.Selected &&
                          !MatchEventsData.GetForMatch(matchId)
                          .Any(me => me.PlayerId == p.Id &&
                               me.Event == EventTypesEnum.RedCard)));
 }
Пример #2
0
        public static void UpdateWithMatch(Match match)
        {
            bool cleanSheet = (match.AwayTeamScore == 0);
            // add appearance/cleansheet for each player
            var players = PlayerData.GetPlayersByTeamId(match.HomeTeamId).Where(p => p.Selected);

            foreach (var homePlayer in players)
            {
                var homePlayerStat = GetByPlayerId(homePlayer.Id);
                homePlayerStat.Appearances++;
                if (cleanSheet)
                {
                    homePlayerStat.CleanSheets++;
                }
            }
            cleanSheet = (match.HomeTeamScore == 0);
            players    = PlayerData.GetPlayersByTeamId(match.AwayTeamId).Where(p => p.Selected);

            foreach (var awayPlayer in players)
            {
                var awayPlayerStat = GetByPlayerId(awayPlayer.Id);
                awayPlayerStat.Appearances++;
                if (cleanSheet)
                {
                    awayPlayerStat.CleanSheets++;
                }
            }

            // add match event stats
            foreach (var matchevent in MatchEventsData.GetForMatch(match.Id))
            {
                var playerStat = PlayerStats.FirstOrDefault(ps => ps.PlayerId == matchevent.PlayerId);

                switch (matchevent.Event)
                {
                case EventTypesEnum.Goal:
                    playerStat.Goals++;
                    break;

                case EventTypesEnum.Assist:
                    playerStat.Assists++;
                    break;

                case EventTypesEnum.RedCard:
                    playerStat.RedCards++;
                    break;

                case EventTypesEnum.YellowCard:
                    playerStat.YellowCards++;
                    break;
                }
            }
        }
Пример #3
0
        public static Match PlayMatch(int id)
        {
            var match = Matches.FirstOrDefault(m => m.Id == id);

            var homeTeam = TeamData.GetTeamById(match.HomeTeamId);
            var awayTeam = TeamData.GetTeamById(match.AwayTeamId);

            // auto-select teams and formation
            TeamData.AutoSelectTeam(match.HomeTeamId);
            TeamData.AutoSelectTeam(match.AwayTeamId);

            var ratingDiff   = homeTeam.TeamRating - awayTeam.TeamRating;
            var homeQuotient = 5
                               + (ratingDiff > 0 ? 1 : 0)
                               + (ratingDiff < 0 ? -1 : 0)
                               + (ratingDiff > 20 ? 1 : 0)
                               + (ratingDiff < -20 ? -1 : 0)
                               + (ratingDiff > 40 ? 1 : 0);

            var awayQuotient = 5
                               + (ratingDiff < 0 ? 1 : 0)
                               + (ratingDiff > 0 ? -1 : 0)
                               + (ratingDiff < 20 ? 1 : 0)
                               + (ratingDiff > -20 ? -1 : 0)
                               + (ratingDiff < 40 ? 1 : 0);

            match.HomeTeamScore = rnd.Next(1, homeQuotient) - 1;
            match.AwayTeamScore = rnd.Next(1, awayQuotient) - 1;

            match.Completed = "Yes";

            MatchEventsData.CreateMatchEvents(match);
            // TODO - Reverse this process so events are generated first
            // use all ratings, fitness, form to determine event flow

            TeamStatsData.UpdateWithMatch(match);
            PlayerStatsData.UpdateWithMatch(match);

            return(match);
        }