public override async Task <CommandBase> GetNewCommand()
        {
            if (await this.Validate())
            {
                IEnumerable <string> commands   = this.GetCommandStrings();
                UserRole             lowestRole = EnumHelper.GetEnumValueFromString <UserRole>((string)this.LowestRoleAllowedComboBox.SelectedItem);

                int cooldown = 0;
                if (!string.IsNullOrEmpty(this.CooldownTextBox.Text))
                {
                    cooldown = int.Parse(this.CooldownTextBox.Text);
                }

                UserCurrencyRequirementViewModel currencyRequirement = this.CurrencySelector.GetCurrencyRequirement();

                if (this.command == null)
                {
                    this.command = new ChatCommand(this.NameTextBox.Text, commands, lowestRole, cooldown, currencyRequirement);
                    ChannelSession.Settings.ChatCommands.Add(this.command);
                }
                else
                {
                    this.command.Name                = this.NameTextBox.Text;
                    this.command.Commands            = commands.ToList();
                    this.command.Permissions         = lowestRole;
                    this.command.CurrencyRequirement = currencyRequirement;
                    this.command.Cooldown            = cooldown;
                }
                return(this.command);
            }
            return(null);
        }
 public PermissionsCommandBase(string name, CommandTypeEnum type, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement, UserCurrencyRequirementViewModel rankRequirement)
     : base(name, type, commands)
 {
     this.Permissions         = lowestAllowedRole;
     this.Cooldown            = cooldown;
     this.CurrencyRequirement = currencyRequirement;
     this.RankRequirement     = rankRequirement;
 }
        public void SetCurrencyRequirement(UserCurrencyRequirementViewModel currencyRequirement)
        {
            if (currencyRequirement != null && ChannelSession.Settings.Currencies.ContainsKey(currencyRequirement.CurrencyID))
            {
                this.EnableDisableToggleSwitch.IsChecked = true;

                this.CurrencyTypeComboBox.ItemsSource  = ChannelSession.Settings.Currencies.Values;
                this.CurrencyTypeComboBox.SelectedItem = ChannelSession.Settings.Currencies[currencyRequirement.CurrencyID];

                this.CurrencyCostTextBox.IsEnabled = true;
                this.CurrencyCostTextBox.Text      = currencyRequirement.RequiredAmount.ToString();
            }
        }
        protected override Task OnLoaded()
        {
            UserCurrencyRequirementViewModel requirement = this.GetCurrencyRequirement();

            if (ChannelSession.Settings != null)
            {
                IEnumerable <UserCurrencyViewModel> ranks = ChannelSession.Settings.Currencies.Values.Where(c => c.IsRank);
                this.IsEnabled = (ranks.Count() > 0);
                this.RankTypeComboBox.ItemsSource = ranks;
            }

            this.SetCurrencyRequirement(requirement);

            return(Task.FromResult(0));
        }
        public void SetCurrencyRequirement(UserCurrencyRequirementViewModel currencyRequirement)
        {
            if (currencyRequirement != null && ChannelSession.Settings.Currencies.ContainsKey(currencyRequirement.CurrencyID))
            {
                this.EnableDisableToggleSwitch.IsChecked = true;

                this.RankTypeComboBox.ItemsSource  = ChannelSession.Settings.Currencies.Values.Where(c => c.IsRank);
                this.RankTypeComboBox.SelectedItem = ChannelSession.Settings.Currencies[currencyRequirement.CurrencyID];

                this.RankMustEqualComboBox.IsEnabled     = true;
                this.RankMustEqualComboBox.SelectedIndex = (currencyRequirement.MustEqual) ? 1 : 0;

                this.RankMinimumComboBox.IsEnabled    = true;
                this.RankMinimumComboBox.ItemsSource  = ChannelSession.Settings.Currencies[currencyRequirement.CurrencyID].Ranks;
                this.RankMinimumComboBox.SelectedItem = currencyRequirement.RequiredRank;
            }
        }
        public async Task <GameOutcomeGroup> GetOutcomeGroup()
        {
            GameOutcomeGroup group     = null;
            string           groupName = null;

            if (this.RankGroupGrid.Visibility != Visibility.Visible)
            {
                UserRole role = EnumHelper.GetEnumValueFromString <UserRole>((string)this.PreDefinedGroupNameTextBlock.Text);
                groupName = EnumHelper.GetEnumName(role);
                group     = new GameOutcomeGroup(role);
            }
            else if (this.RankTypeComboBox.SelectedIndex >= 0 && this.RankMinimumComboBox.SelectedIndex >= 0)
            {
                UserCurrencyRequirementViewModel rankRequirement = new UserCurrencyRequirementViewModel((UserCurrencyViewModel)this.RankTypeComboBox.SelectedItem, (UserRankViewModel)this.RankMinimumComboBox.SelectedItem);
                groupName = rankRequirement.GetCurrency().Name + " - " + rankRequirement.RankName;
                group     = new GameOutcomeGroup(rankRequirement);
            }
            else
            {
                await MessageBoxHelper.ShowMessageDialog("A group is missing the Rank Type & Rank Name");

                return(null);
            }

            if (group != null && !string.IsNullOrEmpty(groupName))
            {
                foreach (GameOutcomeProbabilityControl probabilityControl in this.outcomeProbabilityControls)
                {
                    group.Probabilities.Add(probabilityControl.GetOutcomeProbability());
                }

                if (group.Probabilities.Sum(p => p.Probability) > 100)
                {
                    await MessageBoxHelper.ShowMessageDialog("The group " + groupName + " can not have a combined probability of more than 100%");

                    return(null);
                }
            }

            return(group);
        }
Esempio n. 7
0
 public PreMadeChatCommand(string name, List <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyCost = null)
     : base(name, commands, lowestAllowedRole, cooldown, currencyCost)
 {
 }
Esempio n. 8
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;
 }
Esempio n. 9
0
 public GameOutcomeGroup(UserCurrencyRequirementViewModel rankRequirement) : this()
 {
     this.RankRequirement = rankRequirement;
 }
Esempio 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)
 {
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
 public OnlyOneWinnerGameCommand(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement,
                                 int gameLength, int minimumParticipants)
     : base(name, commands, lowestAllowedRole, cooldown, currencyRequirement, CurrencyRequirementTypeEnum.RequiredAmount)
 {
     this.GameLength          = gameLength;
     this.MinimumParticipants = minimumParticipants;
 }
Esempio n. 13
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;
 }
Esempio n. 14
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;
 }
Esempio n. 15
0
 public ChatCommand(string name, string command, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement)
     : this(name, new List <string>() { command }, lowestAllowedRole, cooldown, currencyRequirement)
 {
 }
Esempio n. 16
0
 public ChatCommand(string name, IEnumerable <string> commands, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement)
     : base(name, CommandTypeEnum.Chat, commands, lowestAllowedRole, cooldown, currencyRequirement, null)
 {
 }
 public PermissionsCommandBase(string name, CommandTypeEnum type, string command, UserRole lowestAllowedRole, int cooldown, UserCurrencyRequirementViewModel currencyRequirement, UserCurrencyRequirementViewModel rankRequirement)
     : this(name, type, new List <string>() { command }, lowestAllowedRole, cooldown, currencyRequirement, rankRequirement)
 {
 }
        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();
            });
        }