Пример #1
0
 public CurrencyAction(StreamPassModel streamPass, CurrencyActionTypeEnum currencyActionType, string amount, string username = null,
                       UserRoleEnum roleRequirement = UserRoleEnum.User, bool deductFromUser = false)
     : this()
 {
     this.StreamPassID       = streamPass.ID;
     this.CurrencyActionType = currencyActionType;
     this.Amount             = amount;
     this.Username           = username;
     this.RoleRequirement    = roleRequirement;
     this.DeductFromUser     = deductFromUser;
 }
Пример #2
0
        public async Task <bool> Validate()
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                await DialogHelper.ShowMessage("A valid name must be specified");

                return(false);
            }

            if (this.Name.Any(c => !char.IsLetterOrDigit(c) && c != ' '))
            {
                await DialogHelper.ShowMessage("The name can only contain letters, numbers, or spaces");

                return(false);
            }

            StreamPassModel dupeStreamPass = ChannelSession.Settings.StreamPass.Values.FirstOrDefault(s => s.Name.Equals(this.Name));

            if (dupeStreamPass != null && (this.StreamPass == null || !this.StreamPass.ID.Equals(dupeStreamPass.ID)))
            {
                await DialogHelper.ShowMessage("There already exists a Stream Pass with this name");

                return(false);
            }

            if (this.MaxLevel <= 0)
            {
                await DialogHelper.ShowMessage("The Max Level must be greater than 0");

                return(false);
            }

            if (this.PointsForLevelUp <= 0)
            {
                await DialogHelper.ShowMessage("The Points for Level Up must be greater than 0");

                return(false);
            }

            if (this.SubMultiplier < 1.0)
            {
                await DialogHelper.ShowMessage("The Sub Multiplier must be greater than or equal to 1.0");

                return(false);
            }

            if (this.StartDate >= this.EndDate)
            {
                await DialogHelper.ShowMessage("The End Date must be after the Start Date");

                return(false);
            }

            if (this.ViewingRateAmount < 0)
            {
                await DialogHelper.ShowMessage("The Viewing Rate Amount must be greater than or equal to 0");

                return(false);
            }

            if (this.ViewingRateMinutes < 0)
            {
                await DialogHelper.ShowMessage("The Viewing Rate Minutes must be greater than or equal to 0");

                return(false);
            }

            if (this.ViewingRateAmount == 0 ^ this.ViewingRateMinutes == 0)
            {
                await DialogHelper.ShowMessage("The Viewing Rate Amount & Minutes must both be greater than 0 or both equal to 0");

                return(false);
            }

            if (this.FollowBonus < 0)
            {
                await DialogHelper.ShowMessage("The Follow Bonus must be greater than or equal to 0");

                return(false);
            }

            if (this.HostBonus < 0)
            {
                await DialogHelper.ShowMessage("The Host Bonus must be greater than or equal to 0");

                return(false);
            }

            if (this.SubscribeBonus < 0)
            {
                await DialogHelper.ShowMessage("The Subscribe Bonus must be greater than or equal to 0");

                return(false);
            }

            if (this.DonationBonus < 0)
            {
                await DialogHelper.ShowMessage("The Donation Bonus must be greater than or equal to 0");

                return(false);
            }

            if (this.BitsBonus < 0)
            {
                await DialogHelper.ShowMessage("The Bits Bonus must be greater than or equal to 0");

                return(false);
            }

            if (this.CustomLevelUpCommands.GroupBy(c => c.Level).Any(c => c.Count() > 1))
            {
                await DialogHelper.ShowMessage("There can only be 1 custom level up command per individual level");

                return(false);
            }

            if (this.CustomLevelUpCommands.Any(c => c.Level > this.MaxLevel))
            {
                await DialogHelper.ShowMessage("There can not be any custom level up commands that are greater than the Max Level");

                return(false);
            }

            return(true);
        }
Пример #3
0
        public async Task <bool> Validate()
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                await DialogHelper.ShowMessage(Resources.StreamPassNameRequired);

                return(false);
            }

            if (this.Name.Any(c => !char.IsLetterOrDigit(c) && c != ' '))
            {
                await DialogHelper.ShowMessage(Resources.StreamPassNameInvalid);

                return(false);
            }

            StreamPassModel dupeStreamPass = ChannelSession.Settings.StreamPass.Values.FirstOrDefault(s => s.Name.Equals(this.Name));

            if (dupeStreamPass != null && (this.StreamPass == null || !this.StreamPass.ID.Equals(dupeStreamPass.ID)))
            {
                await DialogHelper.ShowMessage(Resources.StreamPassNameDuplicate);

                return(false);
            }

            if (this.MaxLevel <= 0)
            {
                await DialogHelper.ShowMessage(Resources.MaxLevelGreaterThanZero);

                return(false);
            }

            if (this.PointsForLevelUp <= 0)
            {
                await DialogHelper.ShowMessage(Resources.PointsForLevelUpGreaterThanZero);

                return(false);
            }

            if (this.SubMultiplier < 1.0)
            {
                await DialogHelper.ShowMessage(Resources.SubMultiplierOneOrMore);

                return(false);
            }

            if (this.StartDate >= this.EndDate)
            {
                await DialogHelper.ShowMessage(Resources.EndDateInvalid);

                return(false);
            }

            if (this.ViewingRateAmount < 0)
            {
                await DialogHelper.ShowMessage(Resources.ViewingRateAmountZeroOrMore);

                return(false);
            }

            if (this.ViewingRateMinutes < 0)
            {
                await DialogHelper.ShowMessage(Resources.ViewingRateMinutesZeroOrMore);

                return(false);
            }

            if (this.ViewingRateAmount == 0 ^ this.ViewingRateMinutes == 0)
            {
                await DialogHelper.ShowMessage(Resources.ViewingRateMinutesInvalid);

                return(false);
            }

            if (this.FollowBonus < 0)
            {
                await DialogHelper.ShowMessage(Resources.FollowBonusZeroOrMore);

                return(false);
            }

            if (this.HostBonus < 0)
            {
                await DialogHelper.ShowMessage(Resources.HostBonusZeroOrMore);

                return(false);
            }

            if (this.SubscribeBonus < 0)
            {
                await DialogHelper.ShowMessage(Resources.SubscriberBonusZeroOrMore);

                return(false);
            }

            if (this.DonationBonus < 0)
            {
                await DialogHelper.ShowMessage(Resources.DonationBonusZeroOrMore);

                return(false);
            }

            if (this.BitsBonus < 0)
            {
                await DialogHelper.ShowMessage(Resources.BitsBonusZeroOrMore);

                return(false);
            }

            if (this.CustomLevelUpCommands.GroupBy(c => c.Level).Any(c => c.Count() > 1))
            {
                await DialogHelper.ShowMessage(Resources.OneCustomLevelCommand);

                return(false);
            }

            if (this.CustomLevelUpCommands.Any(c => c.Level > this.MaxLevel))
            {
                await DialogHelper.ShowMessage(Resources.MaxCustomLevelCommand);

                return(false);
            }

            return(true);
        }
Пример #4
0
 public ConsumableViewModel(StreamPassModel streamPass)
 {
     this.StreamPass = streamPass;
 }
Пример #5
0
 public ConsumableSearchFilterViewModel(StreamPassModel streamPass)
 {
     this.StreamPass = streamPass;
 }
Пример #6
0
 public ConsumablesActionModel(StreamPassModel streamPass, ConsumablesActionTypeEnum actionType, bool usersMustBePresent, string amount, string username = null, UserRoleEnum usersToApplyTo = UserRoleEnum.User, bool deductFromUser = false)
     : this(actionType, usersMustBePresent, amount, username, usersToApplyTo, deductFromUser)
 {
     this.StreamPassID = streamPass.ID;
 }
Пример #7
0
        protected override async Task PerformInternal(CommandParametersModel parameters)
        {
            CurrencyModel currency = null;

            InventoryModel     inventory = null;
            InventoryItemModel item      = null;

            StreamPassModel streamPass = null;

            string systemName = null;

            if (this.CurrencyID != Guid.Empty)
            {
                if (!ChannelSession.Settings.Currency.ContainsKey(this.CurrencyID))
                {
                    return;
                }
                currency   = ChannelSession.Settings.Currency[this.CurrencyID];
                systemName = currency.Name;
            }

            if (this.InventoryID != Guid.Empty)
            {
                if (!ChannelSession.Settings.Inventory.ContainsKey(this.InventoryID))
                {
                    return;
                }
                inventory  = ChannelSession.Settings.Inventory[this.InventoryID];
                systemName = inventory.Name;

                if (!string.IsNullOrEmpty(this.ItemName))
                {
                    string itemName = await ReplaceStringWithSpecialModifiers(this.ItemName, parameters);

                    item = inventory.GetItem(itemName);
                    if (item == null)
                    {
                        return;
                    }
                }
            }

            if (this.StreamPassID != Guid.Empty)
            {
                if (!ChannelSession.Settings.StreamPass.ContainsKey(this.StreamPassID))
                {
                    return;
                }
                streamPass = ChannelSession.Settings.StreamPass[this.StreamPassID];
                systemName = streamPass.Name;
            }

            if (this.ActionType == ConsumablesActionTypeEnum.ResetForAllUsers)
            {
                if (currency != null)
                {
                    await currency.Reset();
                }
                else if (inventory != null)
                {
                    await inventory.Reset();
                }
                else if (streamPass != null)
                {
                    await streamPass.Reset();
                }
            }
            else if (this.ActionType == ConsumablesActionTypeEnum.ResetForUser)
            {
                if (currency != null)
                {
                    currency.ResetAmount(parameters.User.Data);
                }
                else if (inventory != null)
                {
                    inventory.ResetAmount(parameters.User.Data);
                }
                else if (streamPass != null)
                {
                    streamPass.ResetAmount(parameters.User.Data);
                }
            }
            else
            {
                string amountTextValue = await ReplaceStringWithSpecialModifiers(this.Amount, parameters);

                amountTextValue = MathHelper.ProcessMathEquation(amountTextValue).ToString();

                if (!double.TryParse(amountTextValue, out double doubleAmount))
                {
                    await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.CounterActionNotAValidAmount, amountTextValue, systemName));

                    return;
                }

                int amountValue = (int)Math.Ceiling(doubleAmount);
                if (amountValue < 0)
                {
                    await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.GameCurrencyRequirementAmountGreaterThan, amountTextValue, systemName));

                    return;
                }

                HashSet <UserDataModel> receiverUserData = new HashSet <UserDataModel>();
                if (this.ActionType == ConsumablesActionTypeEnum.AddToUser)
                {
                    receiverUserData.Add(parameters.User.Data);
                }
                else if (this.ActionType == ConsumablesActionTypeEnum.AddToSpecificUser || this.ActionType == ConsumablesActionTypeEnum.SubtractFromSpecificUser)
                {
                    if (!string.IsNullOrEmpty(this.Username))
                    {
                        string usernameString = await ReplaceStringWithSpecialModifiers(this.Username, parameters);

                        UserViewModel receivingUser = null;
                        if (this.UsersMustBePresent)
                        {
                            receivingUser = ChannelSession.Services.User.GetActiveUserByUsername(usernameString, parameters.Platform);
                        }
                        else
                        {
                            receivingUser = await ChannelSession.Services.User.GetUserFullSearch(parameters.Platform, userID : null, usernameString);
                        }

                        if (receivingUser != null)
                        {
                            receiverUserData.Add(receivingUser.Data);
                        }
                        else
                        {
                            await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.UserNotFound);

                            return;
                        }
                    }
                }
                else if (this.ActionType == ConsumablesActionTypeEnum.AddToAllChatUsers || this.ActionType == ConsumablesActionTypeEnum.SubtractFromAllChatUsers)
                {
                    foreach (UserViewModel chatUser in ChannelSession.Services.User.GetAllWorkableUsers())
                    {
                        if (chatUser.HasPermissionsTo(this.UsersToApplyTo))
                        {
                            receiverUserData.Add(chatUser.Data);
                        }
                    }
                    receiverUserData.Add(ChannelSession.GetCurrentUser().Data);
                }

                if ((this.DeductFromUser && receiverUserData.Count > 0) || this.ActionType == ConsumablesActionTypeEnum.SubtractFromUser)
                {
                    if (currency != null)
                    {
                        if (!currency.HasAmount(parameters.User.Data, amountValue))
                        {
                            await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.CurrencyRequirementDoNotHaveAmount, amountValue, systemName));

                            return;
                        }
                        currency.SubtractAmount(parameters.User.Data, amountValue);
                    }
                    else if (inventory != null)
                    {
                        if (!inventory.HasAmount(parameters.User.Data, item, amountValue))
                        {
                            await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.CurrencyRequirementDoNotHaveAmount, amountValue, item.Name));

                            return;
                        }
                        inventory.SubtractAmount(parameters.User.Data, item, amountValue);
                    }
                    else if (streamPass != null)
                    {
                        if (!streamPass.HasAmount(parameters.User.Data, amountValue))
                        {
                            await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.CurrencyRequirementDoNotHaveAmount, amountValue, systemName));

                            return;
                        }
                        streamPass.SubtractAmount(parameters.User.Data, amountValue);
                    }
                }

                if (receiverUserData.Count > 0)
                {
                    foreach (UserDataModel receiverUser in receiverUserData)
                    {
                        if (currency != null)
                        {
                            if (this.ActionType == ConsumablesActionTypeEnum.SubtractFromSpecificUser || this.ActionType == ConsumablesActionTypeEnum.SubtractFromAllChatUsers)
                            {
                                currency.SubtractAmount(receiverUser, amountValue);
                            }
                            else
                            {
                                currency.AddAmount(receiverUser, amountValue);
                            }
                        }
                        else if (inventory != null)
                        {
                            if (this.ActionType == ConsumablesActionTypeEnum.SubtractFromSpecificUser || this.ActionType == ConsumablesActionTypeEnum.SubtractFromAllChatUsers)
                            {
                                inventory.SubtractAmount(receiverUser, item, amountValue);
                            }
                            else
                            {
                                inventory.AddAmount(receiverUser, item, amountValue);
                            }
                        }
                        else if (streamPass != null)
                        {
                            if (this.ActionType == ConsumablesActionTypeEnum.SubtractFromSpecificUser || this.ActionType == ConsumablesActionTypeEnum.SubtractFromAllChatUsers)
                            {
                                streamPass.SubtractAmount(receiverUser, amountValue);
                            }
                            else
                            {
                                streamPass.AddAmount(receiverUser, amountValue);
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
 public UserConsumableEditorViewModel(UserDataModel user, StreamPassModel streamPass)
     : this(user)
 {
     this.streamPass = streamPass;
 }
Пример #9
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            if (ChannelSession.Services.Chat != null)
            {
                CurrencyModel currency = null;

                InventoryModel     inventory = null;
                InventoryItemModel item      = null;

                StreamPassModel streamPass = null;

                string systemName = null;

                if (this.CurrencyID != Guid.Empty)
                {
                    if (!ChannelSession.Settings.Currency.ContainsKey(this.CurrencyID))
                    {
                        return;
                    }
                    currency   = ChannelSession.Settings.Currency[this.CurrencyID];
                    systemName = currency.Name;
                }

                if (this.InventoryID != Guid.Empty)
                {
                    if (!ChannelSession.Settings.Inventory.ContainsKey(this.InventoryID))
                    {
                        return;
                    }
                    inventory  = ChannelSession.Settings.Inventory[this.InventoryID];
                    systemName = inventory.Name;

                    if (!string.IsNullOrEmpty(this.ItemName))
                    {
                        string itemName = await this.ReplaceStringWithSpecialModifiers(this.ItemName, user, arguments);

                        item = inventory.GetItem(itemName);
                        if (item == null)
                        {
                            return;
                        }
                    }
                }

                if (this.StreamPassID != Guid.Empty)
                {
                    if (!ChannelSession.Settings.StreamPass.ContainsKey(this.StreamPassID))
                    {
                        return;
                    }
                    streamPass = ChannelSession.Settings.StreamPass[this.StreamPassID];
                    systemName = streamPass.Name;
                }

                if (this.CurrencyActionType == CurrencyActionTypeEnum.ResetForAllUsers)
                {
                    if (currency != null)
                    {
                        await currency.Reset();
                    }
                    else if (inventory != null)
                    {
                        await inventory.Reset();
                    }
                    else if (streamPass != null)
                    {
                        await streamPass.Reset();
                    }
                }
                else if (this.CurrencyActionType == CurrencyActionTypeEnum.ResetForUser)
                {
                    if (currency != null)
                    {
                        currency.ResetAmount(user.Data);
                    }
                    else if (inventory != null)
                    {
                        inventory.ResetAmount(user.Data);
                    }
                    else if (streamPass != null)
                    {
                        streamPass.ResetAmount(user.Data);
                    }
                }
                else
                {
                    string amountTextValue = await this.ReplaceStringWithSpecialModifiers(this.Amount, user, arguments);

                    if (!double.TryParse(amountTextValue, out double doubleAmount))
                    {
                        await ChannelSession.Services.Chat.SendMessage(string.Format("{0} is not a valid amount of {1}", amountTextValue, systemName));

                        return;
                    }

                    int amountValue = (int)Math.Ceiling(doubleAmount);
                    if (amountValue <= 0)
                    {
                        await ChannelSession.Services.Chat.SendMessage("The amount specified must be greater than 0");

                        return;
                    }

                    HashSet <UserDataModel> receiverUserData = new HashSet <UserDataModel>();
                    if (this.CurrencyActionType == CurrencyActionTypeEnum.AddToUser)
                    {
                        receiverUserData.Add(user.Data);
                    }
                    else if (this.CurrencyActionType == CurrencyActionTypeEnum.AddToSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser)
                    {
                        if (!string.IsNullOrEmpty(this.Username))
                        {
                            string usernameString = await this.ReplaceStringWithSpecialModifiers(this.Username, user, arguments);

                            UserViewModel receivingUser = ChannelSession.Services.User.GetUserByUsername(usernameString, this.platform);
                            if (receivingUser != null)
                            {
                                receiverUserData.Add(receivingUser.Data);
                            }
                            else
                            {
                                await ChannelSession.Services.Chat.SendMessage("The user could not be found");

                                return;
                            }
                        }
                    }
                    else if (this.CurrencyActionType == CurrencyActionTypeEnum.AddToAllChatUsers || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                    {
                        foreach (UserViewModel chatUser in ChannelSession.Services.User.GetAllWorkableUsers())
                        {
                            if (chatUser.HasPermissionsTo(this.RoleRequirement))
                            {
                                receiverUserData.Add(chatUser.Data);
                            }
                        }
                        receiverUserData.Add(ChannelSession.GetCurrentUser().Data);
                    }

                    if ((this.DeductFromUser && receiverUserData.Count > 0) || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromUser)
                    {
                        if (currency != null)
                        {
                            if (!currency.HasAmount(user.Data, amountValue))
                            {
                                await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to do this", amountValue, systemName));

                                return;
                            }
                            currency.SubtractAmount(user.Data, amountValue);
                        }
                        else if (inventory != null)
                        {
                            if (!inventory.HasAmount(user.Data, item, amountValue))
                            {
                                await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to do this", amountValue, item));

                                return;
                            }
                            inventory.SubtractAmount(user.Data, item, amountValue);
                        }
                        else if (streamPass != null)
                        {
                            if (!streamPass.HasAmount(user.Data, amountValue))
                            {
                                await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to do this", amountValue, systemName));

                                return;
                            }
                            streamPass.SubtractAmount(user.Data, amountValue);
                        }
                    }

                    if (receiverUserData.Count > 0)
                    {
                        foreach (UserDataModel receiverUser in receiverUserData)
                        {
                            if (currency != null)
                            {
                                if (this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                                {
                                    currency.SubtractAmount(receiverUser, amountValue);
                                }
                                else
                                {
                                    currency.AddAmount(receiverUser, amountValue);
                                }
                            }
                            else if (inventory != null)
                            {
                                if (this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                                {
                                    inventory.SubtractAmount(receiverUser, item, amountValue);
                                }
                                else
                                {
                                    inventory.AddAmount(receiverUser, item, amountValue);
                                }
                            }
                            else if (streamPass != null)
                            {
                                if (this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                                {
                                    streamPass.SubtractAmount(receiverUser, amountValue);
                                }
                                else
                                {
                                    streamPass.AddAmount(receiverUser, amountValue);
                                }
                            }
                        }
                    }
                }
            }
        }