public bool HasInventorySpace() { if (!isBuyingMode) { return(true); } Inventory shopperInventory = currentShopper.GetComponent <Inventory>(); if (shopperInventory == null) { return(false); } List <InventoryItem> flatItems = new List <InventoryItem>(); foreach (ShopItem shopItem in GetAllItems()) { InventoryItem item = shopItem.GetInventoryItem(); int quantity = shopItem.GetQuantityInTransaction(); for (int i = 0; i < quantity; i++) { flatItems.Add(item); } } return(shopperInventory.HasSpaceFor(flatItems)); }
public void ConfirmTransaction() { Inventory shopperInventory = currentShopper.GetComponent <Inventory>(); Purse shopperPurse = currentShopper.GetComponent <Purse>(); if (shopperInventory == null || shopperPurse == null) { return; } // Transfer to or from the inventory foreach (ShopItem shopItem in GetAllItems()) { InventoryItem item = shopItem.GetInventoryItem(); int quantity = shopItem.GetQuantityInTransaction(); float price = shopItem.GetPrice(); for (int i = 0; i < quantity; i++) { if (shopperPurse.GetBalance() < price) { break; } bool success = shopperInventory.AddToFirstEmptySlot(item, 1); if (success) { AddToTransaction(item, -1); stock[item]--; shopperPurse.UpdateBalance(-price); } } } // Removal from transaction // Debting or Crediting of funds if (onChange != null) { onChange(); } }
public bool HasSufficientFunds() { if (!isBuyingMode) { return(true); } Purse purse = currentShopper.GetComponent <Purse>(); if (purse == null) { return(false); } return(purse.GetBalance() >= TransactionTotal()); }