public InventoryWindow(UserInventoryViewModel inventory) { this.inventory = inventory; InitializeComponent(); this.Initialize(this.StatusBar); }
private void InventoryTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { UserInventoryViewModel inventory = this.GetInventoryType(); this.InventoryItemComboBox.IsEnabled = true; this.InventoryItemComboBox.ItemsSource = inventory.Items.Values; this.InventoryItemAmountTextBox.IsEnabled = true; }
public UserInventoryEditorControl(UserInventoryViewModel inventory, UserInventoryDataViewModel inventoryData) { this.inventory = inventory; this.inventoryData = inventoryData; InitializeComponent(); this.Loaded += UserInventoryEditorControl_Loaded; this.DataContext = this.inventory; }
public CurrencyAction(UserInventoryViewModel inventory, CurrencyActionTypeEnum currencyActionType, string itemName = null, string amount = null, string username = null, MixerRoleEnum roleRequirement = MixerRoleEnum.User, bool deductFromUser = false) : this() { this.InventoryID = inventory.ID; this.CurrencyActionType = currencyActionType; this.ItemName = itemName; this.Amount = amount; this.Username = username; this.RoleRequirement = roleRequirement; this.DeductFromUser = deductFromUser; }
public static Inventory InventoryFromUserInventoryViewModel(UserInventoryViewModel inventory) { return(new Inventory { ID = inventory.ID, Name = inventory.Name, Items = inventory.Items.Keys.Select(i => new InventoryItem() { Name = i }).ToList(), }); }
public static InventoryAmount InventoryAmountFromUserInventoryViewModel(UserInventoryViewModel inventory, UserInventoryDataViewModel inventoryData) { return(new InventoryAmount { ID = inventory.ID, Name = inventory.Name, Items = inventoryData.Amounts.Select(kvp => new InventoryItemAmount() { Name = kvp.Key, Amount = kvp.Value }).ToList(), }); }
public override ActionBase GetAction() { if (this.CurrencyTypeComboBox.SelectedIndex >= 0 && this.CurrencyActionTypeComboBox.SelectedIndex >= 0) { UserCurrencyViewModel currency = this.GetSelectedCurrency(); UserInventoryViewModel inventory = this.GetSelectedInventory(); CurrencyActionTypeEnum actionType = EnumHelper.GetEnumValueFromString <CurrencyActionTypeEnum>((string)this.CurrencyActionTypeComboBox.SelectedItem); if (actionType == CurrencyActionTypeEnum.ResetForAllUsers || actionType == CurrencyActionTypeEnum.ResetForUser || !string.IsNullOrEmpty(this.CurrencyAmountTextBox.Text)) { if (actionType == CurrencyActionTypeEnum.AddToSpecificUser) { if (string.IsNullOrEmpty(this.CurrencyUsernameTextBox.Text)) { return(null); } } MixerRoleEnum roleRequirement = MixerRoleEnum.User; if (actionType == CurrencyActionTypeEnum.AddToAllChatUsers || actionType == CurrencyActionTypeEnum.SubtractFromAllChatUsers) { if (this.CurrencyPermissionsAllowedComboBox.SelectedIndex < 0) { return(null); } roleRequirement = EnumHelper.GetEnumValueFromString <MixerRoleEnum>((string)this.CurrencyPermissionsAllowedComboBox.SelectedItem); } if (currency != null) { return(new CurrencyAction(currency, actionType, this.CurrencyAmountTextBox.Text, username: this.CurrencyUsernameTextBox.Text, roleRequirement: roleRequirement, deductFromUser: this.DeductFromUserToggleButton.IsChecked.GetValueOrDefault())); } else if (inventory != null) { if (actionType == CurrencyActionTypeEnum.ResetForAllUsers || actionType == CurrencyActionTypeEnum.ResetForUser) { return(new CurrencyAction(inventory, actionType)); } else if (!string.IsNullOrEmpty(this.InventoryItemNameComboBox.Text)) { return(new CurrencyAction(inventory, actionType, this.InventoryItemNameComboBox.Text, this.CurrencyAmountTextBox.Text, username: this.CurrencyUsernameTextBox.Text, roleRequirement: roleRequirement, deductFromUser: this.DeductFromUserToggleButton.IsChecked.GetValueOrDefault())); } } } } return(null); }
public bool TrySubtractAmount(UserDataViewModel userData) { if (this.DoesMeetRequirement(userData)) { UserInventoryViewModel inventory = this.GetInventory(); if (inventory == null) { return(false); } if (!userData.HasInventoryAmount(inventory, this.ItemName, this.Amount)) { return(false); } userData.SubtractInventoryAmount(inventory, this.ItemName, this.Amount); return(true); } return(false); }
public bool DoesMeetRequirement(UserDataViewModel userData) { if (userData.IsCurrencyRankExempt) { return(true); } UserInventoryViewModel inventory = this.GetInventory(); if (inventory == null) { return(false); } if (!inventory.Items.ContainsKey(this.ItemName)) { return(false); } return(userData.GetInventoryAmount(inventory, this.ItemName) >= this.Amount); }
private User AdjustInventory(UserDataViewModel user, Guid inventoryID, [FromBody] AdjustInventory inventoryUpdate) { if (!ChannelSession.Settings.Inventories.ContainsKey(inventoryID)) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (inventoryUpdate == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } UserInventoryViewModel inventory = ChannelSession.Settings.Inventories[inventoryID]; if (string.IsNullOrEmpty(inventoryUpdate.Name) || !inventory.Items.ContainsKey(inventoryUpdate.Name)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (inventoryUpdate.Amount < 0) { int quantityToRemove = inventoryUpdate.Amount * -1; if (!user.HasInventoryAmount(inventory, inventoryUpdate.Name, quantityToRemove)) { // If the request is to remove currency, but user doesn't have enough, fail throw new HttpResponseException(HttpStatusCode.Forbidden); } user.SubtractInventoryAmount(inventory, inventoryUpdate.Name, quantityToRemove); } else if (inventoryUpdate.Amount > 0) { user.AddInventoryAmount(inventory, inventoryUpdate.Name, inventoryUpdate.Amount); } return(UserFromUserDataViewModel(user)); }
private async void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.NameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog(string.Format("A {0} name must be specified", this.CurrencyRankIdentifierString)); return; } if (this.NameTextBox.Text.Any(c => char.IsDigit(c))) { await MessageBoxHelper.ShowMessageDialog("The name can not contain any number digits in it"); return; } UserCurrencyViewModel dupeCurrency = ChannelSession.Settings.Currencies.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeCurrency != null && (this.currency == null || !this.currency.ID.Equals(dupeCurrency.ID))) { await MessageBoxHelper.ShowMessageDialog("There already exists a currency or rank system with this name"); return; } UserInventoryViewModel dupeInventory = ChannelSession.Settings.Inventories.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeInventory != null) { await MessageBoxHelper.ShowMessageDialog("There already exists an inventory with this name"); return; } string siName = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.NameTextBox.Text); if (siName.Equals("time") || siName.Equals("hours") || siName.Equals("mins") || siName.Equals("sparks") || siName.Equals("embers")) { await MessageBoxHelper.ShowMessageDialog("This name is reserved and can not be used"); return; } int maxAmount = int.MaxValue; if (!string.IsNullOrEmpty(this.MaxAmountTextBox.Text)) { if (!int.TryParse(this.MaxAmountTextBox.Text, out maxAmount) || maxAmount <= 0) { await MessageBoxHelper.ShowMessageDialog("The max amount must be greater than 0 or can be left empty for no max amount"); return; } } if (string.IsNullOrEmpty(this.OnlineAmountRateTextBox.Text) || !int.TryParse(this.OnlineAmountRateTextBox.Text, out int onlineAmount) || onlineAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The online amount must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OnlineTimeRateTextBox.Text) || !int.TryParse(this.OnlineTimeRateTextBox.Text, out int onlineTime) || onlineTime < 0) { await MessageBoxHelper.ShowMessageDialog("The online minutes must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OfflineAmountRateTextBox.Text) || !int.TryParse(this.OfflineAmountRateTextBox.Text, out int offlineAmount) || offlineAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The offline amount must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OfflineTimeRateTextBox.Text) || !int.TryParse(this.OfflineTimeRateTextBox.Text, out int offlineTime) || offlineTime < 0) { await MessageBoxHelper.ShowMessageDialog("The offline minutes must be 0 or greater"); return; } if (onlineAmount > 0 && onlineTime == 0) { await MessageBoxHelper.ShowMessageDialog("The online time can not be 0 if the online amount is greater than 0"); return; } if (offlineAmount > 0 && offlineTime == 0) { await MessageBoxHelper.ShowMessageDialog("The offline time can not be 0 if the offline amount is greater than 0"); return; } int subscriberBonus = 0; if (string.IsNullOrEmpty(this.SubscriberBonusTextBox.Text) || !int.TryParse(this.SubscriberBonusTextBox.Text, out subscriberBonus) || subscriberBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Subscriber bonus must be 0 or greater"); return; } int modBonus = 0; if (string.IsNullOrEmpty(this.ModeratorBonusTextBox.Text) || !int.TryParse(this.ModeratorBonusTextBox.Text, out modBonus) || modBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Moderator bonus must be 0 or greater"); return; } int onFollowBonus = 0; if (string.IsNullOrEmpty(this.OnFollowBonusTextBox.Text) || !int.TryParse(this.OnFollowBonusTextBox.Text, out onFollowBonus) || onFollowBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Follow bonus must be 0 or greater"); return; } int onHostBonus = 0; if (string.IsNullOrEmpty(this.OnHostBonusTextBox.Text) || !int.TryParse(this.OnHostBonusTextBox.Text, out onHostBonus) || onHostBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Host bonus must be 0 or greater"); return; } int onSubscribeBonus = 0; if (string.IsNullOrEmpty(this.OnSubscribeBonusTextBox.Text) || !int.TryParse(this.OnSubscribeBonusTextBox.Text, out onSubscribeBonus) || onSubscribeBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Subscribe bonus must be 0 or greater"); return; } if (this.IsRankToggleButton.IsChecked.GetValueOrDefault()) { if (this.ranks.Count() < 1) { await MessageBoxHelper.ShowMessageDialog("At least one rank must be created"); return; } } int minActivityRate = 0; if (string.IsNullOrEmpty(this.MinimumActivityRateTextBox.Text) || !int.TryParse(this.MinimumActivityRateTextBox.Text, out minActivityRate) || minActivityRate < 0) { await MessageBoxHelper.ShowMessageDialog("The Minimum Activity Rate must be 0 or greater"); return; } bool isNew = false; if (this.currency == null) { isNew = true; this.currency = new UserCurrencyViewModel(); ChannelSession.Settings.Currencies[this.currency.ID] = this.currency; } CurrencyAcquireRateTypeEnum acquireRate = CurrencyAcquireRateTypeEnum.Custom; if (this.OnlineRateComboBox.SelectedIndex >= 0) { acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OnlineRateComboBox.SelectedItem); } this.currency.IsTrackingSparks = false; this.currency.IsTrackingEmbers = false; if (acquireRate == CurrencyAcquireRateTypeEnum.Sparks) { this.currency.IsTrackingSparks = true; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Embers) { this.currency.IsTrackingEmbers = true; } this.currency.Name = this.NameTextBox.Text; this.currency.MaxAmount = maxAmount; this.currency.AcquireAmount = onlineAmount; this.currency.AcquireInterval = onlineTime; this.currency.OfflineAcquireAmount = offlineAmount; this.currency.OfflineAcquireInterval = offlineTime; this.currency.SubscriberBonus = subscriberBonus; this.currency.ModeratorBonus = modBonus; this.currency.OnFollowBonus = onFollowBonus; this.currency.OnHostBonus = onHostBonus; this.currency.OnSubscribeBonus = onSubscribeBonus; this.currency.MinimumActiveRate = minActivityRate; this.currency.ResetInterval = EnumHelper.GetEnumValueFromString <CurrencyResetRateEnum>((string)this.AutomaticResetComboBox.SelectedItem); this.currency.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.currency.Name); if (this.IsRankToggleButton.IsChecked.GetValueOrDefault()) { this.currency.Ranks = ranks.ToList(); this.currency.RankChangedCommand = this.rankChangedCommand; } else { this.currency.Ranks = new List <UserRankViewModel>(); this.currency.RankChangedCommand = null; } foreach (var otherCurrencies in ChannelSession.Settings.Currencies) { if (otherCurrencies.Value.IsRank == this.currency.IsRank) { // Turn off primary for all other currencies/ranks of the same kind otherCurrencies.Value.IsPrimary = false; } } this.currency.IsPrimary = this.IsPrimaryToggleButton.IsChecked.GetValueOrDefault(); await ChannelSession.SaveSettings(); if (isNew) { List <NewCurrencyRankCommand> commandsToAdd = new List <NewCurrencyRankCommand>(); ChatCommand statusCommand = new ChatCommand("User " + this.currency.Name, this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.User, 5)); string statusChatText = string.Empty; if (this.currency.IsRank) { statusChatText = string.Format("@$username is a ${0} with ${1} {2}!", this.currency.UserRankNameSpecialIdentifier, this.currency.UserAmountSpecialIdentifier, this.currency.Name); } else { statusChatText = string.Format("@$username has ${0} {1}!", this.currency.UserAmountSpecialIdentifier, this.currency.Name); } statusCommand.Actions.Add(new ChatAction(statusChatText)); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", statusCommand.Commands.First(), "Shows User's Amount"), statusCommand)); if (!this.currency.IsTrackingSparks && !this.currency.IsTrackingEmbers) { ChatCommand addCommand = new ChatCommand("Add " + this.currency.Name, "add" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.Mod, 5)); addCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******")); addCommand.Actions.Add(new ChatAction(string.Format("@$targetusername received $arg2text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", addCommand.Commands.First(), "Adds Amount To Specified User"), addCommand)); ChatCommand addAllCommand = new ChatCommand("Add All " + this.currency.Name, "addall" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.Mod, 5)); addAllCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToAllChatUsers, "$arg1text")); addAllCommand.Actions.Add(new ChatAction(string.Format("Everyone got $arg1text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", addAllCommand.Commands.First(), "Adds Amount To All Chat Users"), addAllCommand)); if (!this.currency.IsRank) { ChatCommand giveCommand = new ChatCommand("Give " + this.currency.Name, "give" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.User, 5)); giveCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******", deductFromUser: true)); giveCommand.Actions.Add(new ChatAction(string.Format("@$username gave @$targetusername $arg2text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", giveCommand.Commands.First(), "Gives Amount To Specified User"), giveCommand)); } } NewCurrencyRankCommandsDialogControl dControl = new NewCurrencyRankCommandsDialogControl(this.currency, commandsToAdd); string result = await MessageBoxHelper.ShowCustomDialog(dControl); if (!string.IsNullOrEmpty(result) && result.Equals("True")) { foreach (NewCurrencyRankCommand command in dControl.commands) { if (command.AddCommand) { ChannelSession.Settings.ChatCommands.Add(command.Command); } } } } this.Close(); }); }
private async void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.NameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog("An inventory name must be specified"); return; } UserInventoryViewModel dupeInventory = ChannelSession.Settings.Inventories.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeInventory != null && (this.inventory == null || !this.inventory.ID.Equals(dupeInventory.ID))) { await MessageBoxHelper.ShowMessageDialog("There already exists an inventory with this name"); return; } UserCurrencyViewModel dupeCurrency = ChannelSession.Settings.Currencies.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeCurrency != null) { await MessageBoxHelper.ShowMessageDialog("There already exists a currency or rank system with this name"); return; } if (string.IsNullOrEmpty(this.DefaultMaxAmountTextBox.Text) || !int.TryParse(this.DefaultMaxAmountTextBox.Text, out int maxAmount) || maxAmount <= 0) { await MessageBoxHelper.ShowMessageDialog("The default max amount must be greater than 0"); return; } if (this.items.Count == 0) { await MessageBoxHelper.ShowMessageDialog("At least 1 item must be added"); return; } if (this.ShopEnableDisableToggleButton.IsChecked.GetValueOrDefault()) { if (string.IsNullOrEmpty(this.ShopCommandTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog("A command name must be specified for the shop"); return; } if (this.ShopCurrencyComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("A currency must be specified for the shop"); return; } } if (this.inventory == null) { this.inventory = new UserInventoryViewModel(); ChannelSession.Settings.Inventories[this.inventory.ID] = this.inventory; } this.inventory.Name = this.NameTextBox.Text; this.inventory.DefaultMaxAmount = maxAmount; this.inventory.ResetInterval = EnumHelper.GetEnumValueFromString <CurrencyResetRateEnum>((string)this.AutomaticResetComboBox.SelectedItem); this.inventory.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.inventory.Name); this.inventory.Items = new Dictionary <string, UserInventoryItemViewModel>(this.items.ToDictionary(i => i.Name, i => i)); this.inventory.ShopEnabled = this.ShopEnableDisableToggleButton.IsChecked.GetValueOrDefault(); this.inventory.ShopCommand = this.ShopCommandTextBox.Text; if (this.ShopCurrencyComboBox.SelectedIndex >= 0) { UserCurrencyViewModel currency = (UserCurrencyViewModel)this.ShopCurrencyComboBox.SelectedItem; if (currency != null) { this.inventory.ShopCurrencyID = currency.ID; } } this.inventory.ItemsBoughtCommand = (CustomCommand)this.ShopItemsBoughtCommandButtonsControl.DataContext; this.inventory.ItemsSoldCommand = (CustomCommand)this.ShopItemsSoldCommandButtonsControl.DataContext; await ChannelSession.SaveSettings(); this.Close(); }); }
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 CurrencyRankInventoryContainer(UserInventoryViewModel inventory) { this.Inventory = inventory; }
private User AdjustInventory(UserDataViewModel user, Guid inventoryID, [FromBody] AdjustInventory inventoryUpdate) { if (!ChannelSession.Settings.Inventories.ContainsKey(inventoryID)) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new ObjectContent <Error>(new Error { Message = $"Unable to find inventory: {inventoryID.ToString()}." }, new JsonMediaTypeFormatter(), "application/json"), ReasonPhrase = "Inventory ID not found" }; throw new HttpResponseException(resp); } if (inventoryUpdate == null) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <Error>(new Error { Message = "Unable to parse inventory adjustment from POST body." }, new JsonMediaTypeFormatter(), "application/json"), ReasonPhrase = "Invalid POST Body" }; throw new HttpResponseException(resp); } UserInventoryViewModel inventory = ChannelSession.Settings.Inventories[inventoryID]; if (string.IsNullOrEmpty(inventoryUpdate.Name) || !inventory.Items.ContainsKey(inventoryUpdate.Name)) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <Error>(new Error { Message = "Unable to find requested inventory item." }, new JsonMediaTypeFormatter(), "application/json"), ReasonPhrase = "Invalid Inventory Item" }; throw new HttpResponseException(resp); } if (inventoryUpdate.Amount < 0) { int quantityToRemove = inventoryUpdate.Amount * -1; if (!user.HasInventoryAmount(inventory, inventoryUpdate.Name, quantityToRemove)) { // If the request is to remove inventory, but user doesn't have enough, fail var resp = new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new ObjectContent <Error>(new Error { Message = "User does not have enough inventory to remove" }, new JsonMediaTypeFormatter(), "application/json"), ReasonPhrase = "Not Enough Inventory" }; throw new HttpResponseException(resp); } user.SubtractInventoryAmount(inventory, inventoryUpdate.Name, quantityToRemove); } else if (inventoryUpdate.Amount > 0) { user.AddInventoryAmount(inventory, inventoryUpdate.Name, inventoryUpdate.Amount); } return(UserFromUserDataViewModel(user)); }
public InventoryRequirementViewModel(UserInventoryViewModel inventory, UserInventoryItemViewModel item, int amount) { this.InventoryID = inventory.ID; this.ItemName = item.Name; this.Amount = amount; }