public DuelGameCommandModel(string name, HashSet <string> triggers, int timeLimit, GamePlayerSelectionType playerSelectionType, CustomCommandModel startedCommand, CustomCommandModel notAcceptedCommand,
                             GameOutcomeModel successfulOutcome, CustomCommandModel failedCommand)
     : base(name, triggers, GameCommandTypeEnum.Duel)
 {
     this.TimeLimit           = timeLimit;
     this.PlayerSelectionType = playerSelectionType;
     this.StartedCommand      = startedCommand;
     this.NotAcceptedCommand  = notAcceptedCommand;
     this.SuccessfulOutcome   = successfulOutcome;
     this.FailedCommand       = failedCommand;
 }
        protected async Task <int> PerformOutcome(CommandParametersModel parameters, GameOutcomeModel outcome)
        {
            int payout = this.PerformPrimaryMultiplierPayout(parameters, outcome.GetPayoutMultiplier(parameters.User));

            parameters.SpecialIdentifiers[GameCommandModelBase.GameBetSpecialIdentifier]    = this.GetPrimaryBetAmount(parameters).ToString();
            parameters.SpecialIdentifiers[GameCommandModelBase.GamePayoutSpecialIdentifier] = payout.ToString();
            if (outcome.Command != null)
            {
                await outcome.Command.Perform(parameters);
            }

            return(payout);
        }
Beispiel #3
0
 public StealGameCommandModel(string name, HashSet <string> triggers, GamePlayerSelectionType playerSelectionType, GameOutcomeModel successfulOutcome, CustomCommandModel failedCommand)
     : base(name, triggers, GameCommandTypeEnum.Steal)
 {
     this.PlayerSelectionType = playerSelectionType;
     this.SuccessfulOutcome   = successfulOutcome;
     this.FailedCommand       = failedCommand;
 }
        public override async Task <Result> CustomValidation(CommandParametersModel parameters)
        {
            this.SetPrimaryCurrencyRequirementArgumentIndex(argumentIndex: 1);

            if (this.gameActive)
            {
                if (this.betsClosed)
                {
                    if (parameters.User.HasPermissionsTo(this.StarterRole))
                    {
                        // At least to arguments
                        //      1st must be "answer"
                        //      2nd must be a number from 1 to option count
                        if (parameters.Arguments.Count == 2 && string.Equals(parameters.Arguments[0], MixItUp.Base.Resources.Answer, StringComparison.CurrentCultureIgnoreCase) && int.TryParse(parameters.Arguments[1], out int answer) && answer > 0 && answer <= this.BetOptions.Count)
                        {
                            this.gameActive = false;
                            this.betsClosed = false;
                            GameOutcomeModel winningOutcome = this.BetOptions[answer - 1];

                            List <CommandParametersModel> winners = new List <CommandParametersModel>(this.runUserSelections.Where(kvp => kvp.Value == answer).Select(kvp => this.runUsers[kvp.Key]));

                            this.SetGameWinners(this.runParameters, winners);
                            this.runParameters.SpecialIdentifiers[BetGameCommandModel.GameBetWinningOptionSpecialIdentifier] = winningOutcome.Name;
                            await this.RunSubCommand(this.GameCompleteCommand, this.runParameters);

                            foreach (CommandParametersModel winner in winners)
                            {
                                winner.SpecialIdentifiers[BetGameCommandModel.GameBetWinningOptionSpecialIdentifier] = winningOutcome.Name;
                                await this.RunOutcome(winner, winningOutcome);
                            }

                            await this.PerformCooldown(this.runParameters);

                            this.ClearData();

                            return(new Result(success: false));
                        }
                        else
                        {
                            string trigger = this.GetFullTriggers().FirstOrDefault() ?? "!bet";
                            return(new Result(string.Format(MixItUp.Base.Resources.GameCommandBetAnswerExample, trigger)));
                        }
                    }
                    else
                    {
                        return(new Result(string.Format(MixItUp.Base.Resources.RoleErrorInsufficientRole, this.StarterRole)));
                    }
                }
                else if (parameters.Arguments.Count == 0 || !int.TryParse(parameters.Arguments[0], out int choice) || choice <= 0 || choice > this.BetOptions.Count)
                {
                    return(new Result(string.Format(MixItUp.Base.Resources.GameCommandBetInvalidSelection, parameters.User.Username)));
                }
            }
            else
            {
                if (parameters.User.HasPermissionsTo(this.StarterRole))
                {
                    this.gameActive    = true;
                    this.runParameters = parameters;

                    int           i          = 1;
                    List <string> betOptions = new List <string>();
                    foreach (GameOutcomeModel betOption in this.BetOptions)
                    {
                        betOptions.Add($"{i}) {betOption.Name}");
                        i++;
                    }
                    this.runParameters.SpecialIdentifiers[BetGameCommandModel.GameBetOptionsSpecialIdentifier] = string.Join(", ", betOptions);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    AsyncRunner.RunAsyncBackground(async(cancellationToken) =>
                    {
                        await DelayNoThrow(this.TimeLimit * 1000, cancellationToken);

                        if (this.runUsers.Count < this.MinimumParticipants)
                        {
                            await this.RunSubCommand(this.NotEnoughPlayersCommand, this.runParameters);
                            foreach (var kvp in this.runUsers.ToList())
                            {
                                await this.Requirements.Refund(kvp.Value);
                            }
                            await this.PerformCooldown(this.runParameters);
                            this.ClearData();
                            return;
                        }

                        this.betsClosed = true;
                        await this.RunSubCommand(this.BetsClosedCommand, this.runParameters);
                    }, new CancellationToken());
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                    await this.RunSubCommand(this.StartedCommand, parameters);

                    return(new Result(success: false));
                }
                return(new Result(string.Format(MixItUp.Base.Resources.RoleErrorInsufficientRole, this.StarterRole)));
            }
            return(new Result());
        }
 public HeistGameCommandModel(string name, HashSet <string> triggers, int minimumParticipants, int timeLimit, CustomCommandModel startedCommand,
                              CustomCommandModel userJoinCommand, CustomCommandModel notEnoughPlayersCommand, GameOutcomeModel userSuccessOutcome, CustomCommandModel userFailureCommand,
                              CustomCommandModel allSucceedCommand, CustomCommandModel topThirdsSucceedCommand, CustomCommandModel middleThirdsSucceedCommand, CustomCommandModel lowThirdsSucceedCommand,
                              CustomCommandModel noneSucceedCommand)
     : base(name, triggers, GameCommandTypeEnum.Heist)
 {
     this.MinimumParticipants        = minimumParticipants;
     this.TimeLimit                  = timeLimit;
     this.StartedCommand             = startedCommand;
     this.UserJoinCommand            = userJoinCommand;
     this.NotEnoughPlayersCommand    = notEnoughPlayersCommand;
     this.UserSuccessOutcome         = userSuccessOutcome;
     this.UserFailureCommand         = userFailureCommand;
     this.AllSucceedCommand          = allSucceedCommand;
     this.TopThirdsSucceedCommand    = topThirdsSucceedCommand;
     this.MiddleThirdsSucceedCommand = middleThirdsSucceedCommand;
     this.LowThirdsSucceedCommand    = lowThirdsSucceedCommand;
     this.NoneSucceedCommand         = noneSucceedCommand;
 }
Beispiel #6
0
 public RouletteGameCommandModel(string name, HashSet <string> triggers, int minimumParticipants, int timeLimit, RouletteGameCommandBetType betType, HashSet <string> betOptions, CustomCommandModel startedCommand,
                                 CustomCommandModel userJoinCommand, CustomCommandModel notEnoughPlayersCommand, GameOutcomeModel userSuccessOutcome, CustomCommandModel userFailureCommand, CustomCommandModel gameCompleteCommand)
     : base(name, triggers, GameCommandTypeEnum.Roulette)
 {
     this.MinimumParticipants     = minimumParticipants;
     this.TimeLimit               = timeLimit;
     this.BetType                 = betType;
     this.BetOptions              = betOptions;
     this.StartedCommand          = startedCommand;
     this.UserJoinCommand         = userJoinCommand;
     this.NotEnoughPlayersCommand = notEnoughPlayersCommand;
     this.UserSuccessOutcome      = userSuccessOutcome;
     this.UserFailureCommand      = userFailureCommand;
     this.GameCompleteCommand     = gameCompleteCommand;
 }