public int CalculateSellPrice(Item item, int amount) { int existingQuantity = MarketInventory.GetQuantity(item); double existingMod = MathHelper.Clamp(1.0 - existingQuantity / (item.Rarity * 100.0), 0.05, 1.0); int price = (int)((item.BaseValue * amount) * existingMod); return(MathHelper.Clamp(price, 1, price)); }
/// <summary> /// Market buys from someone. /// </summary> public int MarketBuy(Item item, int amount) { int total = CalculateBuyPrice(item, amount); MarketInventory.AddItem(item, amount); MarketInventory.Credits -= total; return(total); }
/// <summary> /// Market sells to someone. /// </summary> public int MarketSell(Item item, int amount) { if (amount > 0 && amount <= MarketInventory.GetQuantity(item)) { int total = CalculateSellPrice(item, amount); MarketInventory.RemoveItem(item, amount); MarketInventory.Credits += total; return(total); } return(0); }
protected override void GatherComponents() { base.GatherComponents(); fileName = "/" + SceneManager.GetActiveScene().name + "_ShopData.dat"; shops = GetComponent <MarketInventory>(); }
internal void UpdateMarketInventoryTable(string[] marketInventoryTable) { MarketInventory?.Invoke(this, marketInventoryTable); }