stack item pickup (in progress), throwable hand consumes items, spawnable objects tied to item definitions
This commit is contained in:
@@ -35,18 +35,26 @@ private void Update()
|
||||
}
|
||||
}
|
||||
|
||||
// we'll set this up to only try to add one item to the inventory at a time for now
|
||||
// there won't be stacked items in the wild for right now
|
||||
public bool AddItem(Item item, int quantity)
|
||||
{
|
||||
int curQuantity = quantity;
|
||||
|
||||
// first try to stack
|
||||
for (int i = 0; i < itemSlots.Length; i++)
|
||||
{
|
||||
if (itemSlots[i].item == item.id && itemSlots[i].quantity < item.maxStack)
|
||||
if (itemSlots[i].item == item.id && itemSlots[i].quantity + quantity < item.maxStack)
|
||||
{
|
||||
itemSlots[i].quantity += 1;
|
||||
return true;
|
||||
}
|
||||
else if (itemSlots[i].item == item.id)
|
||||
{
|
||||
curQuantity = quantity - (item.maxStack - itemSlots[i].quantity);
|
||||
itemSlots[i].quantity = item.maxStack;
|
||||
|
||||
if (curQuantity <= 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// no stack to add to, try to find an empty slot
|
||||
@@ -56,7 +64,7 @@ public bool AddItem(Item item, int quantity)
|
||||
{
|
||||
itemSlots[i] = new ItemSlot();
|
||||
|
||||
itemSlots[i].quantity = 1;
|
||||
itemSlots[i].quantity = curQuantity;
|
||||
itemSlots[i].item = item.id;
|
||||
return true;
|
||||
}
|
||||
@@ -88,6 +96,7 @@ public bool RemoveItemQuantity(ItemIdEnum itemId, int quantity)
|
||||
// we have exactly enough in the current slot, so nullify it and
|
||||
// exit
|
||||
itemSlots[i].item = ItemIdEnum.NONE;
|
||||
itemSlots[i].quantity = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user