From 2ca51d6a836d6d6c507922969159b3c03ca686d1 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 20 May 2024 14:07:30 -0500 Subject: [PATCH] merchant resource stacking --- src/engine/net/client/ClientMessagePump.java | 36 +++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 54cbc291..3398eeb0 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -1464,11 +1464,37 @@ public class ClientMessagePump implements NetMsgHandler { ChatManager.chatSystemError(sourcePlayer, "Failed To Buy Item"); return; } - buy = Item.createItemForPlayer(sourcePlayer, ib); - if (buy != null) { - me.transferEnchants(buy); - itemMan.addItemToInventory(buy); - //itemMan.updateInventory(); + if(me.getItemBase().getType().equals(ItemType.RESOURCE)){ + boolean stacked = false; + for(Item item : itemMan.getInventory()){ + int itemID = item.getItemBaseID(); + int meID = me.getItemBase().getUUID(); + if(itemID == meID){ + int maxStack = Warehouse.maxResources.get(meID); + if(maxStack > item.getNumOfItems() + 1){ + item.setNumOfItems(item.getNumOfItems() + 1); + stacked = true; + itemMan.updateInventory(); + item.updateDatabase(); + break; + } + } + } + if(!stacked){ + buy = Item.createItemForPlayer(sourcePlayer, ib); + if (buy != null) { + me.transferEnchants(buy); + itemMan.addItemToInventory(buy); + //itemMan.updateInventory(); + } + } + }else { + buy = Item.createItemForPlayer(sourcePlayer, ib); + if (buy != null) { + me.transferEnchants(buy); + itemMan.addItemToInventory(buy); + //itemMan.updateInventory(); + } } } }