/// <summary> /// Executes a purchase for the specified items. Validation will check if there is enough money AND inventory space. If both are true, deducts money and adds item to inventory. /// </summary> /// <param name="item">The item(s) to purchase.</param> /// <param name="discount">The discount percentage on the price of the item(s).</param> /// <param name="performValidation">Set to false only if money AND inventory space has already been validated.</param> /// <param name="result"></param> /// <returns></returns> public bool PurchaseItem(OrderItem item, float discount, bool performValidation, out string result) { bool successful = false; result = GameMaster.MSG_ERR_DEFAULT; float totalCost = GameMaster.DiscountPrice(item.TotalValue(), discount); float totalSpaceUsed = item.TotalSpaceUsed(); bool valid = true; if (performValidation) { valid = ValidatePurchaseItem(totalCost, out result); if (valid) { valid = WarehouseInventory.ValidateAddItem(totalSpaceUsed, out result); } } if (valid) { DecreaseMoney(totalCost); WarehouseInventory.AddItem(item, false, out result); successful = true; result = string.Format("Purchase successful: {0}", result); } return(successful); }
public void MoveItemsToInventory(int iSlot) { string temp = GameMaster.MSG_GEN_NA; OrderItem item = new OrderItem(Shop.ItemsOnDisplay[iSlot].ItemID, 1); bool itemMoved = WarehouseInventory.AddItem(item, false, out temp); if (itemMoved) { Shop.RemoveItem(iSlot); } else { Debug.Log("***Moving items to Inventory fail: " + temp); } }