diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 5035ae41..2905431f 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -1260,12 +1260,15 @@ public class CharacterItemManager { } if (i.getItemBase().getType().equals(ItemType.RESOURCE) && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) { boolean added = false; - for(Item item : this.getInventory()){ + ArrayList purge = new ArrayList<>(); + int count = i.getNumOfItems(); + for(Item item : this.inventory){ if(item.getItemBaseID() == i.getItemBaseID()){ - if(item.getNumOfItems() + i.getNumOfItems() <= Warehouse.getMaxResources().get(item.getItemBaseID())) { - item.setNumOfItems(item.getNumOfItems() + i.getNumOfItems()); - updateInventory(); + purge.add(item); + if(count + item.getNumOfItems() <= Warehouse.maxResources.get(i.getItemBaseID())) { + count += item.getNumOfItems(); added = true; + purge.add(item); } } } @@ -1276,7 +1279,12 @@ public class CharacterItemManager { ItemBase ib = i.getItemBase(); if (ib != null) this.inventoryWeight += ib.getWeight(); + } else{ + this.inventory.removeAll(purge); + i.setNumOfItems(count); + this.inventory.add(i); } + this.updateInventory(); }else { this.inventory.add(i); this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());