public CurrencyRequirementModel(CurrencyModel currency, CurrencyRequirementTypeEnum requirementType, int minAmount, int maxAmount)
 {
     this.CurrencyID      = currency.ID;
     this.RequirementType = requirementType;
     this.MinAmount       = minAmount;
     this.MaxAmount       = maxAmount;
 }
Ejemplo n.º 2
0
        public RequirementViewModel GetRequirements()
        {
            RequirementViewModel requirements = this.Requirements.GetRequirements();

            CurrencyModel currency = (CurrencyModel)this.CurrencyTypeComboBox.SelectedItem;
            CurrencyRequirementTypeEnum requirement = this.CurrencyUsage;

            if (requirement == CurrencyRequirementTypeEnum.NoCurrencyCost)
            {
                requirements.Currency = new CurrencyRequirementViewModel(currency, requirement, 0);
            }
            else if (requirement == CurrencyRequirementTypeEnum.RequiredAmount)
            {
                int.TryParse(this.RequiredAmountTextBox.Text, out int required);
                requirements.Currency = new CurrencyRequirementViewModel(currency, requirement, required);
            }
            else if (requirement == CurrencyRequirementTypeEnum.MinimumOnly)
            {
                int.TryParse(this.MinimumAmountTextBox.Text, out int minimum);
                requirements.Currency = new CurrencyRequirementViewModel(currency, requirement, minimum);
            }
            else if (requirement == CurrencyRequirementTypeEnum.MinimumAndMaximum)
            {
                int.TryParse(this.MinimumAmountTextBox.Text, out int minimum);
                int.TryParse(this.MaximumAmountTextBox.Text, out int maximum);
                requirements.Currency = new CurrencyRequirementViewModel(currency, minimum, maximum);
            }

            return(requirements);
        }
        private void CurrencyRequirementTypeComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (this.CurrencyRequirementTypeComboBox.SelectedIndex >= 0)
            {
                CurrencyRequirementTypeEnum requirementType = EnumHelper.GetEnumValueFromString <CurrencyRequirementTypeEnum>((string)this.CurrencyRequirementTypeComboBox.SelectedItem);
                if (requirementType == CurrencyRequirementTypeEnum.NoCurrencyCost)
                {
                    this.CurrencyCostsGrid.IsEnabled = false;
                }
                else
                {
                    this.CurrencyCostsGrid.IsEnabled          = true;
                    this.CurrencyMaximumCostTextBox.IsEnabled = (requirementType == CurrencyRequirementTypeEnum.MinimumAndMaximum);

                    if (requirementType == CurrencyRequirementTypeEnum.RequiredAmount)
                    {
                        HintAssist.SetHint(this.CurrencyMinimumCostTextBox, "Required Amount");
                    }
                    else
                    {
                        HintAssist.SetHint(this.CurrencyMinimumCostTextBox, "Minimum Amount");
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public OutcomeGameCommandBase(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                               CurrencyRequirementTypeEnum currencyRequirementType, IEnumerable <GameOutcome> outcomes, IEnumerable <GameOutcomeGroup> groups, CustomCommand loseLeftoverCommand)
     : base(name, commands, lowestAllowedRole, cooldown, currencyRequirement, currencyRequirementType)
 {
     this.Outcomes            = outcomes.ToList();
     this.Groups              = groups.ToList();
     this.LoseLeftoverCommand = loseLeftoverCommand;
 }
Ejemplo n.º 5
0
 public IndividualProbabilityGameCommand(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                                         CurrencyRequirementTypeEnum currencyRequirementType, IEnumerable <GameOutcome> outcomes, IEnumerable <GameOutcomeGroup> groups, CustomCommand loseLeftoverCommand, int gameLength,
                                         int minimumParticipants)
     : base(name, commands, lowestAllowedRole, cooldown, currencyRequirement, currencyRequirementType, outcomes, groups, loseLeftoverCommand)
 {
     this.GameLength          = gameLength;
     this.MinimumParticipants = minimumParticipants;
 }
Ejemplo n.º 6
0
 public void SetDefaultValues(string name, string triggers, CurrencyRequirementTypeEnum currencyRequirement, int minimum = 0, int maximum = 0)
 {
     this.NameTextBox.Text        = name;
     this.ChatCommandTextBox.Text = triggers;
     this.CurrencyRequirementComboBox.SelectedItem = EnumHelper.GetEnumName(currencyRequirement);
     this.RequiredAmountTextBox.Text = minimum.ToString();
     this.MinimumAmountTextBox.Text  = minimum.ToString();
     this.MaximumAmountTextBox.Text  = (maximum > 0) ? maximum.ToString() : string.Empty;
 }
Ejemplo n.º 7
0
 private void CurrencyRequirementComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (this.CurrencyRequirementComboBox.SelectedIndex >= 0)
     {
         CurrencyRequirementTypeEnum requirement = this.CurrencyUsage;
         this.RequiredAmountTextBox.Visibility = (requirement == CurrencyRequirementTypeEnum.RequiredAmount) ? Visibility.Visible : Visibility.Collapsed;
         this.MinimumAmountTextBox.Visibility  = (requirement == CurrencyRequirementTypeEnum.MinimumOnly || requirement == CurrencyRequirementTypeEnum.MinimumAndMaximum) ? Visibility.Visible : Visibility.Collapsed;
         this.MaximumAmountTextBox.Visibility  = (requirement == CurrencyRequirementTypeEnum.MinimumAndMaximum) ? Visibility.Visible : Visibility.Collapsed;
     }
 }
 public CurrencyRequirementViewModel(UserCurrencyViewModel currency, CurrencyRequirementTypeEnum requirementType, int amount)
 {
     this.CurrencyID      = currency.ID;
     this.RequiredAmount  = amount;
     this.RequirementType = requirementType;
 }
Ejemplo n.º 9
0
 public GameCommandBase(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                        CurrencyRequirementTypeEnum currencyRequirementType)
     : base(name, CommandTypeEnum.Game, commands, lowestAllowedRole, cooldown, currencyRequirement, null)
 {
     this.CurrencyRequirementType = currencyRequirementType;
 }
Ejemplo n.º 10
0
 public SinglePlayerGameCommand(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                                CurrencyRequirementTypeEnum currencyRequirementType, IEnumerable <GameOutcome> outcomes, IEnumerable <GameOutcomeGroup> groups, CustomCommand loseLeftoverCommand)
     : base(name, commands, lowestAllowedRole, cooldown, currencyRequirement, currencyRequirementType, outcomes, groups, loseLeftoverCommand)
 {
 }
Ejemplo n.º 11
0
 public UserCharityGameCommand(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                               CurrencyRequirementTypeEnum currencyRequirementType, bool giveToRandomUser)
     : base(name, commands, lowestAllowedRole, cooldown, currencyRequirement, currencyRequirementType)
 {
     this.GiveToRandomUser = giveToRandomUser;
 }
Ejemplo n.º 12
0
        public async Task <bool> Validate()
        {
            if (string.IsNullOrEmpty(this.NameTextBox.Text))
            {
                await DialogHelper.ShowMessage("A Game Name is required");

                return(false);
            }

            if (string.IsNullOrEmpty(this.ChatCommandTextBox.Text))
            {
                await DialogHelper.ShowMessage("At least 1 chat trigger must be specified");

                return(false);
            }

            if (!CommandBase.IsValidCommandString(this.ChatCommandTextBox.Text))
            {
                await DialogHelper.ShowMessage("The chat triggers contain an invalid character");

                return(false);
            }

            IEnumerable <string> commandStrings = this.ChatTriggers;

            if (commandStrings.GroupBy(c => c).Where(g => g.Count() > 1).Count() > 0)
            {
                await DialogHelper.ShowMessage("Each chat trigger must be unique");

                return(false);
            }

            if (!await this.Requirements.Validate())
            {
                return(false);
            }

            if (this.CurrencyTypeComboBox.SelectedIndex < 0)
            {
                await DialogHelper.ShowMessage("A currency must be selected");

                return(false);
            }

            if (this.CurrencyRequirementComboBox.SelectedIndex < 0)
            {
                await DialogHelper.ShowMessage("A currency usage must be selected");

                return(false);
            }
            CurrencyRequirementTypeEnum requirement = this.CurrencyUsage;

            int minimum = 0;
            int maximum = 0;

            if (requirement == CurrencyRequirementTypeEnum.MinimumOnly || requirement == CurrencyRequirementTypeEnum.MinimumAndMaximum)
            {
                if (string.IsNullOrEmpty(this.MinimumAmountTextBox.Text) || !int.TryParse(this.MinimumAmountTextBox.Text, out minimum) || minimum <= 0)
                {
                    await DialogHelper.ShowMessage("A valid minimum amount must be specified");

                    return(false);
                }
            }

            if (requirement == CurrencyRequirementTypeEnum.MinimumAndMaximum)
            {
                if (string.IsNullOrEmpty(this.MaximumAmountTextBox.Text) || !int.TryParse(this.MaximumAmountTextBox.Text, out maximum) || maximum <= 0)
                {
                    await DialogHelper.ShowMessage("A valid maximum amount must be specified");

                    return(false);
                }

                if (maximum > 0 && maximum < minimum)
                {
                    await DialogHelper.ShowMessage("Maximum amount must be greater than or equal to minimum amount");

                    return(false);
                }
            }

            if (requirement == CurrencyRequirementTypeEnum.RequiredAmount)
            {
                if (string.IsNullOrEmpty(this.RequiredAmountTextBox.Text) || !int.TryParse(this.RequiredAmountTextBox.Text, out minimum) || minimum <= 0)
                {
                    await DialogHelper.ShowMessage("A valid required amount must be specified");

                    return(false);
                }
            }

            foreach (PermissionsCommandBase command in ChannelSession.AllChatCommands)
            {
                if (command.IsEnabled && this.existingCommand != command)
                {
                    if (commandStrings.Any(c => command.Commands.Contains(c, StringComparer.InvariantCultureIgnoreCase)))
                    {
                        await DialogHelper.ShowMessage("There already exists a command that uses one of the chat triggers you have specified");

                        return(false);
                    }
                }
            }

            return(true);
        }
        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            await this.RunAsyncOperation(async() =>
            {
                if (string.IsNullOrEmpty(this.GameNameTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("Name is missing");
                    return;
                }

                if (string.IsNullOrEmpty(this.GameChatCommandTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("Commands is missing");
                    return;
                }

                if (this.GameChatCommandTextBox.Text.Any(c => !Char.IsLetterOrDigit(c) && !Char.IsWhiteSpace(c)))
                {
                    await MessageBoxHelper.ShowMessageDialog("Commands can only contain letters and numbers");
                    return;
                }

                foreach (PermissionsCommandBase command in ChannelSession.AllChatCommands)
                {
                    if (this.command != command && this.GameNameTextBox.Text.Equals(command.Name))
                    {
                        await MessageBoxHelper.ShowMessageDialog("There already exists a chat command with the same name");
                        return;
                    }
                }

                IEnumerable <string> commandStrings = this.GetCommandStrings();
                if (commandStrings.GroupBy(c => c).Where(g => g.Count() > 1).Count() > 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("Each command string must be unique");
                    return;
                }

                foreach (PermissionsCommandBase command in ChannelSession.AllChatCommands)
                {
                    if (command.IsEnabled && this.GetExistingCommand() != command)
                    {
                        if (commandStrings.Any(c => command.Commands.Contains(c)))
                        {
                            await MessageBoxHelper.ShowMessageDialog("There already exists a chat command that uses one of the command strings you have specified");
                            return;
                        }
                    }
                }

                int cooldown = 0;
                if (!int.TryParse(this.GameCooldownTextBox.Text, out cooldown) || cooldown < 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("Cooldown must be 0 or greater");
                    return;
                }

                if (this.GameLowestRoleAllowedComboBox.SelectedIndex < 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("A permission level must be selected");
                    return;
                }

                if (this.GameTypeComboBox.SelectedIndex < 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("A game type must be selected");
                    return;
                }
                GameTypeEnum gameType = EnumHelper.GetEnumValueFromString <GameTypeEnum>((string)this.GameTypeComboBox.SelectedItem);

                if (this.CurrencyTypeComboBox.SelectedIndex < 0 || this.CurrencyRequirementTypeComboBox.SelectedIndex < 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("A currency type and requirement must be selected");
                    return;
                }

                int minimum = 0;
                int maximum = 0;

                CurrencyRequirementTypeEnum currencyRequirementType = EnumHelper.GetEnumValueFromString <CurrencyRequirementTypeEnum>((string)this.CurrencyRequirementTypeComboBox.SelectedItem);
                if (currencyRequirementType != CurrencyRequirementTypeEnum.NoCurrencyCost && (!int.TryParse(this.CurrencyMinimumCostTextBox.Text, out minimum) || minimum < 0))
                {
                    await MessageBoxHelper.ShowMessageDialog("The currency minimum must be 0 or greater");
                    return;
                }

                if (currencyRequirementType == CurrencyRequirementTypeEnum.MinimumAndMaximum && (!int.TryParse(this.CurrencyMaximumCostTextBox.Text, out maximum) || maximum <= minimum))
                {
                    await MessageBoxHelper.ShowMessageDialog("The currency maximum must be greater than the minimum");
                    return;
                }

                int gameLength      = 0;
                int minParticipants = 0;
                if (this.MultiplayerGameDetailsGrid.Visibility == Visibility.Visible)
                {
                    if (!int.TryParse(this.GameLengthTextBox.Text, out gameLength) || gameLength < 0)
                    {
                        await MessageBoxHelper.ShowMessageDialog("Game length must be 0 or greater");
                        return;
                    }

                    if (!int.TryParse(this.GameMinimumParticipantsTextBox.Text, out minParticipants) || minParticipants < 1)
                    {
                        await MessageBoxHelper.ShowMessageDialog("Minimum participants must be 1 or greater");
                        return;
                    }
                }

                List <GameOutcome> outcomes           = new List <GameOutcome>();
                List <GameOutcomeGroup> outcomeGroups = new List <GameOutcomeGroup>();
                if (gameType == GameTypeEnum.SinglePlayer || gameType == GameTypeEnum.IndividualProbabilty)
                {
                    foreach (GameOutcomeCommandControl commandControl in this.outcomeCommandControls)
                    {
                        GameOutcome outcome = await commandControl.GetOutcome();
                        if (outcome == null)
                        {
                            return;
                        }
                        outcomes.Add(outcome);
                    }

                    if (outcomes.Select(o => o.Name).GroupBy(n => n).Where(g => g.Count() > 1).Count() > 0)
                    {
                        await MessageBoxHelper.ShowMessageDialog("Each outcome must have a unique name");
                        return;
                    }

                    foreach (GameOutcomeGroupControl groupControl in this.outcomeGroupControls)
                    {
                        GameOutcomeGroup group = await groupControl.GetOutcomeGroup();
                        if (group == null)
                        {
                            return;
                        }
                        outcomeGroups.Add(group);
                        for (int i = 0; i < outcomes.Count; i++)
                        {
                            group.Probabilities[i].OutcomeName = outcomes[i].Name;
                        }
                    }
                }

                UserRole permissionsRole = EnumHelper.GetEnumValueFromString <UserRole>((string)this.GameLowestRoleAllowedComboBox.SelectedItem);

                if (this.command != null)
                {
                    ChannelSession.Settings.GameCommands.Remove(this.command);
                }

                UserCurrencyRequirementViewModel currencyRequirement = new UserCurrencyRequirementViewModel((UserCurrencyViewModel)this.CurrencyTypeComboBox.SelectedItem, minimum, maximum);
                if (gameType == GameTypeEnum.SinglePlayer)
                {
                    this.command = new SinglePlayerGameCommand(this.GameNameTextBox.Text, this.GetCommandStrings(), permissionsRole, cooldown, currencyRequirement, currencyRequirementType, outcomes,
                                                               outcomeGroups, this.LoseLeftoverProbabilityCommandControl.GetCommand());
                }
                else if (gameType == GameTypeEnum.IndividualProbabilty)
                {
                    IndividualProbabilityGameCommand ipCommand = new IndividualProbabilityGameCommand(this.GameNameTextBox.Text, this.GetCommandStrings(), permissionsRole, cooldown,
                                                                                                      currencyRequirement, currencyRequirementType, outcomes, outcomeGroups, this.LoseLeftoverProbabilityCommandControl.GetCommand(), gameLength, minParticipants);
                    ipCommand.GameStartedCommand    = this.GameStartedCommandControl.GetCommand();
                    ipCommand.GameEndedCommand      = this.GameEndedCommandControl.GetCommand();
                    ipCommand.UserJoinedCommand     = this.UserJoinedCommandControl.GetCommand();
                    ipCommand.NotEnoughUsersCommand = this.NotEnoughUsersCommandControl.GetCommand();
                    this.command = ipCommand;
                }
                else if (gameType == GameTypeEnum.OnlyOneWinner)
                {
                    OnlyOneWinnerGameCommand oowCommand = new OnlyOneWinnerGameCommand(this.GameNameTextBox.Text, this.GetCommandStrings(), permissionsRole, cooldown, currencyRequirement,
                                                                                       gameLength, minParticipants);
                    oowCommand.GameStartedCommand    = this.GameStartedCommandControl.GetCommand();
                    oowCommand.GameEndedCommand      = this.GameEndedCommandControl.GetCommand();
                    oowCommand.UserJoinedCommand     = this.UserJoinedCommandControl.GetCommand();
                    oowCommand.NotEnoughUsersCommand = this.NotEnoughUsersCommandControl.GetCommand();
                    this.command = oowCommand;
                }
                else if (gameType == GameTypeEnum.UserCharity)
                {
                    UserCharityGameCommand ucCommand = new UserCharityGameCommand(this.GameNameTextBox.Text, this.GetCommandStrings(), permissionsRole, cooldown, currencyRequirement,
                                                                                  currencyRequirementType, this.GiveToRandomUserCharityToggleButton.IsChecked.GetValueOrDefault());
                    ucCommand.UserParticipatedCommand = this.UserParticipatedCommandControl.GetCommand();
                    this.command = ucCommand;
                }

                ChannelSession.Settings.GameCommands.Add(this.command);

                await ChannelSession.SaveSettings();

                this.Close();
            });
        }