diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 0b664877..df143179 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -1254,13 +1254,37 @@ public class CharacterItemManager { } return false; } + } else if (i.getItemBase().getType().equals(ItemType.RESOURCE)) { + if(this.inventoryContainsResource(i)){ + Item resource = getResource(i); + if(resource != null){ + resource.setNumOfItems(resource.getNumOfItems() + i.getNumOfItems()); + return true; + } + } } - + this.inventory.add(i); this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); return true; } + private boolean inventoryContainsResource(Item resource) { + for(Item i : this.inventory){ + if(i.getItemBaseID() == resource.getItemBaseID()) + return true; + } + return false; + } + + private Item getResource(Item resource) { + for(Item i : this.inventory){ + if(i.getItemBaseID() == resource.getItemBaseID()) + return i; + } + return null; + } + //called for adding gold of a specified amount public synchronized boolean addItemToInventory(Item i, int amount) { if (i.getItemBase().getType().equals(ItemType.GOLD))