From 02aafc927417def6377c7591538c2421978461db Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Thu, 6 Jun 2024 18:48:52 -0500 Subject: [PATCH] resource purchasing --- src/engine/net/client/ClientMessagePump.java | 66 ++++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index e6b6edcb..d72b0c47 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -1415,18 +1415,15 @@ public class ClientMessagePump implements NetMsgHandler { int cost = me.magicValue; if(npc.getContractID() == 1201 && me.getItemBase().getName().equals("Prospector")) cost = 50; - int resourceCost = (Warehouse.getSellStackSize(me.getItemBase().getUUID()) * Warehouse.getCostForResource(me.getItemBase().getUUID())); - if (resourceCost != 0) - cost = resourceCost; - if(npc.contractUUID == 900 && me.getItemBase().getUUID() == 1705032){ - cost = 1000000; - } float bargain = sourcePlayer.getBargain(); float profit = npc.getSellPercent(sourcePlayer) - bargain; if(me.getItemBase().getType().equals(ItemType.POTION)) profit -= 1.0f; if (profit < 1) profit = 1; + if(npc.getContractID() == 900){ + cost = Warehouse.getCostForResource(ib.getUUID()) * Warehouse.getSellStackSize(ib.getUUID()); + } cost *= profit; if (gold.getNumOfItems() - cost < 0) { //dont' have enough goldItem exit! @@ -1447,33 +1444,7 @@ public class ClientMessagePump implements NetMsgHandler { return; } if(me.getItemBase().getType().equals(ItemType.RESOURCE) && npc.getContractID() == 900){ - boolean stacked = false; - int buystack = Warehouse.getSellStackSize(me.getItemBase().getUUID()); - for(Item item : itemMan.getInventory()){ - int itemID = item.getItemBaseID(); - int meID = me.getItemBase().getUUID(); - if(itemID == meID){ - if(Warehouse.maxResources.isEmpty()) - Warehouse.getMaxResources(); - int maxStack = Warehouse.maxResources.get(itemID); - if(maxStack > item.getNumOfItems() + buystack){ - item.setNumOfItems(item.getNumOfItems() + buystack); - stacked = true; - itemMan.updateInventory(); - DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems()); - break; - } - } - } - if(!stacked){ - buy = Item.createItemForPlayer(sourcePlayer, ib); - if (buy != null) { - me.transferEnchants(buy); - itemMan.addItemToInventory(buy); - buy.setNumOfItems(buystack); - DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems()); - } - } + handleResourcePurchase(me,itemMan,npc,buy,sourcePlayer,ib); }else { buy = Item.createItemForPlayer(sourcePlayer, ib); if (buy != null) { @@ -1589,6 +1560,35 @@ public class ClientMessagePump implements NetMsgHandler { } } + public static void handleResourcePurchase(MobEquipment me, CharacterItemManager itemMan, NPC npc, Item buy, PlayerCharacter sourcePlayer, ItemBase ib){ + boolean stacked = false; + int buystack = Warehouse.getSellStackSize(me.getItemBase().getUUID()); + for(Item item : itemMan.getInventory()){ + int itemID = item.getItemBaseID(); + int meID = me.getItemBase().getUUID(); + if(itemID == meID){ + if(Warehouse.maxResources.isEmpty()) + Warehouse.getMaxResources(); + int maxStack = Warehouse.maxResources.get(itemID); + if(maxStack > item.getNumOfItems() + buystack){ + item.setNumOfItems(item.getNumOfItems() + buystack); + stacked = true; + itemMan.updateInventory(); + DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems()); + break; + } + } + } + if(!stacked){ + buy = Item.createItemForPlayer(sourcePlayer, ib); + if (buy != null) { + me.transferEnchants(buy); + itemMan.addItemToInventory(buy); + buy.setNumOfItems(buystack); + DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems()); + } + } + } private static void Repair(RepairMsg msg, ClientConnection origin) { PlayerCharacter player = SessionManager.getPlayerCharacter(origin);