public bool TrySubtractAmount(UserDataViewModel userData, int amount) { if (this.DoesMeetCurrencyRequirement(amount)) { UserCurrencyViewModel currency = this.GetCurrency(); if (currency == null) { return(false); } UserCurrencyDataViewModel userCurrencyData = userData.GetCurrency(currency); if (userCurrencyData.Amount < amount) { return(false); } userCurrencyData.Amount -= amount; return(true); } return(false); }
public UserCurrencyDataViewModel(UserDataViewModel user, UserCurrencyViewModel currency, int amount = 0) { this.User = user; this.Currency = currency; this.Amount = amount; }
public void SubtractCurrencyAmount(UserCurrencyViewModel currency, int amount) { this.AddCurrencyAmount(currency, -1 * amount); }
public void AddCurrencyAmount(UserCurrencyViewModel currency, int amount) { this.SetCurrencyAmount(currency, this.GetCurrencyAmount(currency) + amount); }
public int GetCurrencyAmount(UserCurrencyViewModel currency) { return(this.GetCurrency(currency).Amount); }
public UserCurrencyDataViewModel GetCurrency(UserCurrencyViewModel currency) { return(this.CurrencyAmounts.GetValueIfExists(currency, new UserCurrencyDataViewModel(this, currency))); }
public void SetCurrencyAmount(UserCurrencyViewModel currency, int amount) { this.GetCurrency(currency).Amount = Math.Min(amount, this.GetCurrency(currency).Currency.MaxAmount); }
public async Task PerformShopCommand(UserViewModel user, IEnumerable <string> arguments = null) { try { if (ChannelSession.Chat != null && ChannelSession.Settings.Currencies.ContainsKey(this.ShopCurrencyID)) { UserCurrencyViewModel currency = ChannelSession.Settings.Currencies[this.ShopCurrencyID]; if (arguments != null && arguments.Count() > 0) { string arg1 = arguments.ElementAt(0); if (arguments.Count() == 1 && arg1.Equals("list", StringComparison.InvariantCultureIgnoreCase)) { List <string> items = new List <string>(); foreach (UserInventoryItemViewModel item in this.Items.Values) { if (item.HasBuyAmount || item.HasSellAmount) { items.Add(item.Name); } } await ChannelSession.Chat.Whisper(user.UserName, "Items Available to Buy/Sell: " + string.Join(", ", items)); return; } else if (arguments.Count() >= 2 && (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase) || arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase))) { int amount = 1; IEnumerable <string> itemArgs = arguments.Skip(1); UserInventoryItemViewModel item = this.GetItem(string.Join(" ", itemArgs)); if (item == null && itemArgs.Count() > 1) { itemArgs = itemArgs.Take(itemArgs.Count() - 1); item = this.GetItem(string.Join(" ", itemArgs)); if (item != null) { if (!int.TryParse(arguments.Last(), out amount) || amount <= 0) { await ChannelSession.Chat.Whisper(user.UserName, "A valid amount greater than 0 must be specified"); return; } } } if (item == null) { await ChannelSession.Chat.Whisper(user.UserName, "The item you specified does not exist"); return; } int totalcost = 0; CustomCommand command = null; if (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase)) { if (item.HasBuyAmount) { int itemMaxAmount = (item.HasMaxAmount) ? item.MaxAmount : this.DefaultMaxAmount; if ((user.Data.GetInventoryAmount(this, item.Name) + amount) <= itemMaxAmount) { totalcost = item.BuyAmount * amount; if (user.Data.HasCurrencyAmount(currency, totalcost)) { user.Data.SubtractCurrencyAmount(currency, totalcost); user.Data.AddInventoryAmount(this, item.Name, amount); command = this.ItemsBoughtCommand; } else { await ChannelSession.Chat.Whisper(user.UserName, string.Format("You do not have the required {0} {1} to purchase this item", totalcost, currency.Name)); } } else { await ChannelSession.Chat.Whisper(user.UserName, string.Format("You can only have {0} {1} in total", itemMaxAmount, item.Name)); } } else { await ChannelSession.Chat.Whisper(user.UserName, "This item is not available for buying"); } } else if (arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase)) { if (item.HasSellAmount) { totalcost = item.SellAmount * amount; if (user.Data.HasInventoryAmount(this, item.Name, amount)) { user.Data.SubtractInventoryAmount(this, item.Name, amount); user.Data.AddCurrencyAmount(currency, totalcost); command = this.ItemsSoldCommand; } else { await ChannelSession.Chat.Whisper(user.UserName, string.Format("You do not have the required {0} {1} to sell", amount, item.Name)); } } else { await ChannelSession.Chat.Whisper(user.UserName, "This item is not available for selling"); } } else { await ChannelSession.Chat.Whisper(user.UserName, "You must specify either \"buy\" & \"sell\""); } if (command != null) { Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>(); specialIdentifiers["itemtotal"] = amount.ToString(); specialIdentifiers["itemname"] = item.Name; specialIdentifiers["itemcost"] = totalcost.ToString(); specialIdentifiers["currencyname"] = currency.Name; await command.Perform(user, arguments : arguments, extraSpecialIdentifiers : specialIdentifiers); } return; } else { UserInventoryItemViewModel item = this.GetItem(string.Join(" ", arguments)); if (item != null) { if (item.HasBuyAmount || item.HasSellAmount) { StringBuilder itemInfo = new StringBuilder(); itemInfo.Append(item.Name + ": "); if (item.HasBuyAmount) { itemInfo.Append(string.Format("Buy = {0} {1}", item.BuyAmount, currency.Name)); } if (item.HasBuyAmount && item.HasSellAmount) { itemInfo.Append(string.Format(", ")); } if (item.HasSellAmount) { itemInfo.Append(string.Format("Sell = {0} {1}", item.SellAmount, currency.Name)); } await ChannelSession.Chat.Whisper(user.UserName, itemInfo.ToString()); } else { await ChannelSession.Chat.Whisper(user.UserName, "This item is not available to buy/sell"); } } else { await ChannelSession.Chat.Whisper(user.UserName, "The item you specified does not exist"); } return; } } StringBuilder storeHelp = new StringBuilder(); storeHelp.Append(this.ShopCommand + " list = Lists all the items available for buying/selling ** "); storeHelp.Append(this.ShopCommand + " <ITEM NAME> = Lists the buying/selling price for the item ** "); storeHelp.Append(this.ShopCommand + " buy <ITEM NAME> [AMOUNT] = Buys 1 or the amount specified of the item ** "); storeHelp.Append(this.ShopCommand + " sell <ITEM NAME> [AMOUNT] = Sells 1 or the amount specified of the item"); await ChannelSession.Chat.Whisper(user.UserName, storeHelp.ToString()); } } catch (Exception ex) { Logger.Log(ex); } }
public void ResetCurrencyAmount(UserCurrencyViewModel currency) { this.CurrencyAmounts[currency] = new UserCurrencyDataViewModel(this, currency); }
public void SetCurrencyAmount(UserCurrencyViewModel currency, int amount) { UserCurrencyDataViewModel currencyData = this.GetCurrency(currency); currencyData.Amount = Math.Min(amount, currencyData.Currency.MaxAmount); }
public bool HasCurrencyAmount(UserCurrencyViewModel currency, int amount) { return(this.IsCurrencyRankExempt || this.GetCurrencyAmount(currency) >= amount); }
public UserCurrencyRequirementViewModel(UserCurrencyViewModel currency, UserRankViewModel rank, bool mustEqual = false) { this.CurrencyID = currency.ID; this.RankName = rank.Name; this.MustEqual = mustEqual; }
public UserCurrencyRequirementViewModel(UserCurrencyViewModel currency, int amount, int maximumAmount = 0) { this.CurrencyID = currency.ID; this.RequiredAmount = amount; this.MaximumAmount = maximumAmount; }