From 77e9a4d9bf6425e51c46257b51c21562a234b66c Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Thu, 14 Mar 2024 22:00:09 -0500 Subject: [PATCH] resource dupe --- src/engine/objects/CharacterItemManager.java | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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))