public int CheckMoney() { if (items.GetItem(moneyItem) != null) { return(items.GetItem(moneyItem).count); } return(0); }
void TryToBuy(StoredItem s) { InventoryList merchantInventory = currentMerchant.baseInventory; Item item = s.item; bool hasMoney = item.cost <= GlobalController.inventory.CheckMoney(); if (hasMoney) { // copy StoredItem toAdd = new StoredItem(merchantInventory.GetItem(item).item); TakeMoney(item.cost); if (merchantInventory.GetItem(item).item.stackable) { if (merchantInventory.GetItem(s).count > 1) { merchantInventory.GetItem(s).count -= 1; } else { merchantInventory.RemoveItem(s); } } else { merchantInventory.RemoveItem(s); } AddItem(toAdd, false); inventoryUI.merchantLine.text = currentMerchant.GetThanksDialogue(item); itemBuy.PlayOneShot(itemBuy.clip); UpdateMoneyUI(); currentMerchant.ReactToBuy(); } else { inventoryUI.merchantLine.text = currentMerchant.notEnoughMoneyDialogue; } inventoryUI.PopulateItems(currentMerchant.baseInventory); }
public void CheckForItem(InventoryList inventoryToCheck) { foreach (Item wantedItem in wanted) { StoredItem i = inventoryToCheck.GetItem(wantedItem.name); if (i == null) { //reject if even one item is missing RejectItems(); return; } } AcceptItems(); }
override public void ActivateSwitch(bool b) { if (b) { InventoryList playerInventory = GlobalController.inventory.items; if (playerInventory.HasItem(plasma)) { StoredItem playerPlasma = playerInventory.GetItem(plasma); int plasmaCount = playerPlasma.count; playerInventory.RemoveItem(playerPlasma); GlobalController.BoostStat(StatType.HEALTH, plasmaCount * healthPerPlasma); } } }
void TryToBuy(InventoryItem item) { InventoryList merchantInventory = currentMerchant.baseInventory; bool hasMoney = item.cost <= GlobalController.inventory.CheckMoney(); if (hasMoney) { InventoryItem toAdd = merchantInventory.GetItem(item).Clone(); TakeMoney(item.cost); if (merchantInventory.GetItem(item).stackable) { if (merchantInventory.GetItem(item).count > 1) { merchantInventory.GetItem(item).count -= 1; } else { merchantInventory.RemoveItem(item); } } else { merchantInventory.RemoveItem(item); } toAdd.count = 1; AddItem(toAdd); inventoryUI.merchantLine.text = currentMerchant.thanksDialogue; itemBuy.PlayOneShot(itemBuy.clip); UpdateMoneyUI(); currentMerchant.ReactToBuy(); } else { inventoryUI.merchantLine.text = currentMerchant.notEnoughMoneyDialogue; } inventoryUI.PopulateItems(currentMerchant.baseInventory); }
public void CheckForItem(InventoryList inventoryToCheck) { List <InventoryItem> actualWantedItems = wantedItems.Select(x => x.GetItem()).ToList(); foreach (InventoryItem wantedItem in actualWantedItems) { InventoryItem i = inventoryToCheck.GetItem(wantedItem); if (!(i != null && i.count >= wantedItem.count)) { //reject if even one item is missing RejectItems(); return; } } AcceptItems(); }