I hadn’t thought to split the predicates between HasItem and HasItems, that’s a good idea.
One other useful thing to add is in the Inventory script. There’s a bool method for HasItems(item), but the methods to determine the quantity of the item won’t give the expected result if the item isn’t stackable. If you don’t want to have to match your item checks to whether the item is stackable, this overload for HasItems is working for me:
/// <summary>
/// Is there an instance of the item in the inventory? If so, return slot.
/// </summary>
public bool HasItem(InventoryItem item, out int slot)
{
for (int i = 0; i < slots.Length; i++)
{
if (object.ReferenceEquals(slots[i].item, item))
{
slot = i;
return true;
}
}
slot = -1;
return false;
}
Then you can use this to check whether you have enough of whatever item:
int slot;
InventoryItem item = InventoryItem.GetFromID(parameterArray[0]);
if (HasItem(item, out slot))
{
if(GetNumberInSlot(slot) < int.Parse(parameters[1]))
{
return false;
}
}
else
{
return false;
}
return true;