Beispiel #1
0
 public async void DeleteCurrency(UserCurrencyViewModel currency)
 {
     await this.Window.RunAsyncOperation(async() =>
     {
         if (await MessageBoxHelper.ShowConfirmationDialog("Are you sure you wish to delete this?"))
         {
             ChannelSession.Settings.Currencies.Remove(currency.ID);
             currency.Reset();
             this.RefreshList();
         }
     });
 }
Beispiel #2
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            if (ChannelSession.Chat != null)
            {
                UserCurrencyViewModel  currency  = null;
                UserInventoryViewModel inventory = null;
                string systemName = null;
                string itemName   = null;

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

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

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

                        if (!inventory.Items.ContainsKey(itemName))
                        {
                            return;
                        }
                    }
                }

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

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

                        return;
                    }

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

                        return;
                    }

                    HashSet <UserDataViewModel> receiverUserData = new HashSet <UserDataViewModel>();
                    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);

                            UserModel receivingUser = await ChannelSession.Connection.GetUser(usernameString);

                            if (receivingUser != null)
                            {
                                receiverUserData.Add(ChannelSession.Settings.UserData.GetValueIfExists(receivingUser.id, new UserDataViewModel(new UserViewModel(receivingUser))));
                            }
                            else
                            {
                                await ChannelSession.Chat.Whisper(user.UserName, "The user could not be found");

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

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

                                return;
                            }
                            user.Data.SubtractCurrencyAmount(currency, amountValue);
                        }
                        else if (inventory != null)
                        {
                            if (!user.Data.HasInventoryAmount(inventory, itemName, amountValue))
                            {
                                await ChannelSession.Chat.Whisper(user.UserName, string.Format("You do not have the required {0} {1} to do this", amountValue, itemName));

                                return;
                            }
                            user.Data.SubtractInventoryAmount(inventory, itemName, amountValue);
                        }
                    }

                    if (receiverUserData.Count > 0)
                    {
                        foreach (UserDataViewModel receiverUser in receiverUserData)
                        {
                            if (currency != null)
                            {
                                if (this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                                {
                                    receiverUser.SubtractCurrencyAmount(currency, amountValue);
                                }
                                else
                                {
                                    receiverUser.AddCurrencyAmount(currency, amountValue);
                                }
                            }
                            else if (inventory != null)
                            {
                                if (this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromSpecificUser || this.CurrencyActionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers)
                                {
                                    receiverUser.SubtractInventoryAmount(inventory, itemName, amountValue);
                                }
                                else
                                {
                                    receiverUser.AddInventoryAmount(inventory, itemName, amountValue);
                                }
                            }
                        }
                    }
                }
            }
        }
 public void DeleteCurrency(UserCurrencyViewModel currency)
 {
     ChannelSession.Settings.Currencies.Remove(currency.ID);
     currency.Reset();
     this.RefreshList();
 }