From d9a03ebf93f8f9feb698054b222c752ea1847a96 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 19 Feb 2024 17:16:34 -0600 Subject: [PATCH] resources auto stack when entering inventory --- src/engine/objects/CharacterItemManager.java | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 3f8b4907..74eac61f 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -1251,6 +1251,27 @@ public class CharacterItemManager { ItemBase ib = i.getItemBase(); if (ib != null) this.inventoryWeight += ib.getWeight(); + + if (i.getItemBase().getType().equals(ItemType.RESOURCE) && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) { + int count = i.getNumOfItems(); + ArrayList purge = new ArrayList<>(); + for (Item it : this.getInventory()) { + if (it.getItemBase().equals(i.getItemBase()) && it.getNumOfItems() + i.getNumOfItems() <= Warehouse.getMaxResources().get(it.getItemBaseID())) { + purge.add(it); + count += it.getNumOfItems(); + } + } + if (count <= Warehouse.getMaxResources().get(i.getItemBaseID())) { + MobLoot ml = new MobLoot(this.getOwner(), i.getItemBase(), count, false); + for (Item p : purge) { + this.removeItemFromInventory(p); + } + this.addItemToInventory(ml.promoteToItem((PlayerCharacter) this.getOwner()), 1); + this.updateInventory(); + return true; + } + } + return true; }