/// <summary> /// Returns the amount of money this settlement will pay for this item, and this count of item /// /// </summary> /// <param name="item"></param> /// <param name="count"></param> /// <returns></returns> public int CalculateImportValue(EconomicItem item, int count) { float tVal = 0; //If this item is a requirement, then we if (RequiredImports.ContainsKey(item)) { int desiredStock = 0; DesiredItemStock.TryGetValue(item, out desiredStock); //if we have less than 10% of stock, we inflate the value of this transaction to encourage traders to come here. if (desiredStock > 0 && Inventory.ItemCount(item) < 0.1f * desiredStock) { tVal += count * item.Value * 1.5f; } for (int i = 0; i < count; i++) { tVal += item.Value * Mathf.Pow(1.01f, i); } return((int)tVal); } /* * if (DesiredImports.ContainsKey(item)) * { * for (int i = 0; i < count; i++) * { * tVal += item.Value * Mathf.Pow(1.005f, i); * } * return (int)tVal; * }*/ return(0); }
public bool HasItem(EconomicItem item) { if (item == null) { return(false); } return(AllItems.ContainsKey(item)); }
public int ItemCount(EconomicItem item) { if (item == null) { return(0); } if (AllItems.TryGetValue(item, out int count)) { return(count); } return(0); }
public void AddItem(EconomicItem item, int count) { if (item == null) { return; } if (AllItems.ContainsKey(item)) { AllItems[item] += count; } else { AllItems.Add(item, count); } }
/// <summary> /// Removes the set amount of product from this inventory, returns the remaining /// If the remaining is negative, we set the count to 0, but still return the -ve number /// </summary> /// <param name="item"></param> /// <param name="count"></param> /// <returns></returns> public int RemoveItem(EconomicItem item, int count) { if (!HasItem(item)) { return(-count); } int ic = ItemCount(item); if (ic >= count) { int rem = ic - count; AllItems[item] = rem; return(rem); } AllItems[item] = 0; return(ic - count); }
/// <summary> /// Attempts to export the specified item out of this inventory. /// The economy will only export if the item is in surplus /// Will sell up to the total number surplus, or to the 'amount' specified, whichever is larger /// Will calculate the cost per item, and only sell up to the amount of maxMoney /// will return the remaining money /// </summary> /// <param name="item"></param> /// <param name="amount"></param> /// <param name="maxMoney"></param> /// <returns></returns> public bool AttemptExport(EconomicItem item, int amount, float maxMoney, out float remainingMoney, out int totalSold) { //Check if we have a surplus if (Surplus.TryGetValue(item, out int surplus)) { totalSold = 0; while (surplus > 0 && amount > 0 && maxMoney > item.Value) { surplus--; amount--; maxMoney -= item.Value; //TODO - make item price vary totalSold++; } remainingMoney = maxMoney; return(true); } remainingMoney = maxMoney; totalSold = 0; return(false); }