public bool LoseItem(IInventoryElement item, int amount) { if (CheckItemAmount(item) < amount) { Debug.Log($"Player has insufficient {item.ItemName}."); return(false); } if (amount < 0) { throw new ArgumentException("Invalid value for <amount>. Value must be a positive integer."); } foreach (var obj in allInventoryItems.Where(x => x == (UnityEngine.Object)item)) { item.ItemQuantity -= amount; if (item.ItemQuantity < 0) { item.ItemQuantity = 0; Debug.LogError($"{item} amount just went below 0, after having {amount} units removed."); } } RaiseOnInventoryChanged(); Debug.Log($"Player lost x{amount} {item.ItemName}."); return(true); }
public void Setup(IInventoryElement inventoryObject) { nameTextComponent.text = inventoryObject.ItemName; countTextComponent.text = inventoryObject.ItemQuantity.ToString(); imageComponent.sprite = inventoryObject.ItemSprite; buttonComponent.onClick.AddListener(delegate { ButtonAction(inventoryObject); }); }
protected override void SetTrigger() { Debug.Log($"Constructor from Button Trigger assigned player to get."); IInventoryElement item = itemToGet as IInventoryElement; inventory.GainItem(item, itemQuantity); }
private void CheckRequiredItems(List <IInventoryElement> inventoryElements) { IInventoryElement itemDataElement = inventoryElements.Single(x => x == RequiredItem); if (itemDataElement != null && itemDataElement.ItemQuantity >= requiredQuantity) { CompleteObjective(); } }
public int CheckItemAmount(IInventoryElement item) { int amount = 0; foreach (var obj in allInventoryItems.Where(x => x == (UnityEngine.Object)item)) { amount += item.ItemQuantity; } return(amount); }
public void GainItem(IInventoryElement item, int amount) { if (amount < 0) { throw new ArgumentException("Invalid value for <amount>. Value must be a positive integer."); } foreach (var obj in allInventoryItems.Where(x => x == (UnityEngine.Object)item)) { item.ItemQuantity += amount; } RaiseOnInventoryChanged(); Debug.Log($"Player gained x{amount} {item.ItemName}."); }
public void ButtonAction(IInventoryElement inventoryObject) { var obj = Instantiate(pfDetailsPanel, GameAssets.Instance.transform); //obj.GetComponent<SetupDetailsPanel>().Setup(inventoryObject); }
public void ButtonAction(IInventoryElement inventoryObject) { //INSERT ACTION }