Ejemplo n.º 1
0
        public async Task <ResponseWrapper <string> > Buy(FutbolPlayer futbolPlayer)
        {
            try
            {
                var budget = await fantasySoccerService.BuyFutbolPlayerAsync(futbolPlayer.ID, (int)futbolPlayer.Price);

                return(new ResponseWrapper <string>
                {
                    StatusCode = Models.Responses.StatusCode.OK,
                    Response = budget,
                    Message = $"{futbolPlayer.GetFullName()} was added to your team.",
                });
            }
            catch
            {
                return(new ResponseWrapper <string>
                {
                    StatusCode = Models.Responses.StatusCode.BadRequest,
                    Message = "Couldn't buy the player. \nTry again later"
                });
            }
        }
Ejemplo n.º 2
0
 public bool UserTeamContainsPlayer(FutbolPlayer player) => UserTeam?.Players != null && UserTeam.Players.Any(teamPlayer => teamPlayer.ID == player.ID);
Ejemplo n.º 3
0
        private static MatchFutbolPlayerPerformance SimulateMatchFutbolPlayerPerformance(MatchSimulationProcessState state, FutbolPlayer futbolPlayer)
        {
            var playerPerformance = new MatchFutbolPlayerPerformance
            {
                ID             = Guid.NewGuid().ToString(),
                MatchID        = state.Match.ID,
                FutbolPlayerID = futbolPlayer.ID,
                Round          = state.Match.Round,
                TournamentId   = state.Match.TournamentId
            };

            playerPerformance.Goals = AssignGoals(state, futbolPlayer);
            if (futbolPlayer.Position == Position.Forward)
            {
                state.CurrentState.ForwardGoals += playerPerformance.Goals;
            }
            else
            {
                state.CurrentState.OtherPositionGoals += playerPerformance.Goals;
            }

            if (futbolPlayer.Position == Position.Goalkeeper)
            {
                playerPerformance.Saves = GetIntBeetween(0, SimulatorConstants.MaxSaves);
            }

            playerPerformance.YellowCards = GetIntBeetween(0, state.CurrentState.RedCards == state.FinalState.RedCards ? 1 : 2);
            if (playerPerformance.YellowCards == 2)
            {
                playerPerformance.RedCards = 1;
            }
            else
            {
                playerPerformance.RedCards = state.CurrentState.RedCards == state.FinalState.RedCards ? 0 : GetIntBeetween(0, 1);
            }
            state.CurrentState.RedCards += playerPerformance.RedCards;

            playerPerformance.Faults = GetIntBeetween(0, SimulatorConstants.MaxFaults);

            if (playerPerformance.RedCards == 1 || HasToMakeAChange(state))
            {
                playerPerformance.PlayedMinutes = GetIntBeetween(0, SimulatorConstants.MatchMinutes - 1);

                if (playerPerformance.RedCards == 0)
                {
                    state.CurrentState.MinutesPlayedBySubs[^ state.CurrentState.Changes] = SimulatorConstants.MatchMinutes - playerPerformance.PlayedMinutes;