From e6d83ca36c8f988afcab0fb8535ea245de51e98e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 17 Apr 2024 14:07:42 -0400 Subject: [PATCH] Mobloot vestiges removed --- .../handlers/ItemProductionMsgHandler.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index a28959a6..fdf173cc 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -15,7 +15,6 @@ import engine.gameManager.DbManager; import engine.gameManager.ForgeManager; import engine.loot.WorkOrder; import engine.mbEnums; -import engine.mbEnums.GameObjectType; import engine.mbEnums.ItemType; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -24,7 +23,10 @@ import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ManageNPCMsg; -import engine.objects.*; +import engine.objects.CharacterItemManager; +import engine.objects.Item; +import engine.objects.NPC; +import engine.objects.PlayerCharacter; import org.pmw.tinylog.Logger; import java.util.HashMap; @@ -113,7 +115,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { depositItem(msg.itemUUID, vendor, origin); break; case SETPRICE: - setItemPrice(msg.itemType, msg.itemUUID, msg.itemPrice, vendor, origin); + setItemPrice(msg.itemUUID, msg.itemPrice, vendor, origin); break; case TAKE: takeItem(msg.items, vendor, origin); @@ -151,7 +153,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { } - private static void setItemPrice(int itemType, int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) { + private static void setItemPrice(int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) { Item targetItem; ItemProductionMsg outMsg; @@ -162,35 +164,16 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { if (player == null) return; - if (itemType == GameObjectType.Item.ordinal()) - targetItem = Item.getFromCache(itemUUID); - else if (itemType == GameObjectType.MobLoot.ordinal()) - targetItem = MobLoot.getFromCache(itemUUID); - else - targetItem = null; + targetItem = Item.getFromCache(itemUUID); if (targetItem == null) return; - if (targetItem.getObjectType() == GameObjectType.Item) { - if (!DbManager.ItemQueries.UPDATE_VALUE(targetItem, itemPrice)) { + if (!DbManager.ItemQueries.UPDATE_VALUE(targetItem, itemPrice)) { ChatManager.chatInfoError(origin.getPlayerCharacter(), "Failed to set price! Contact CCR For help."); return; } - targetItem.setValue(itemPrice); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.DEPOSIT, true); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.SETPRICE, true); - dispatch = Dispatch.borrow(player, outMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - } else if (targetItem.getObjectType() == GameObjectType.MobLoot) { - MobLoot mobLoot = (MobLoot) targetItem; - if (!DbManager.NPCQueries.UPDATE_ITEM_PRICE(mobLoot.getObjectUUID(), vendor.getObjectUUID(), itemPrice)) { - ChatManager.chatInfoError(origin.getPlayerCharacter(), "Failed to set price! Contact CCR For help."); - return; - } targetItem.setValue(itemPrice); outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.DEPOSIT, true); dispatch = Dispatch.borrow(player, outMsg); @@ -199,7 +182,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, mbEnums.ProductionActionType.SETPRICE, true); dispatch = Dispatch.borrow(player, outMsg); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); - } + } // Method sets the price on an item in the vendor inventory @@ -299,12 +282,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { for (int itemUUID : itemList.keySet()) { int itemValue = 0; - int type = itemList.get(itemUUID); - - if (type == GameObjectType.Item.ordinal()) - targetItem = Item.getFromCache(itemUUID); - else - targetItem = MobLoot.getFromCache(itemUUID); + targetItem = Item.getFromCache(itemUUID); if (targetItem == null) continue; @@ -314,6 +292,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { if (!vendor.charItemManager.doesCharOwnThisItem(targetItem.getObjectUUID())) continue; + if (vendor.charItemManager.inventoryContains(targetItem) == false) continue; @@ -333,6 +312,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { case POTION: continue; } + totalValue += itemValue; vendor.charItemManager.recycle(targetItem); @@ -344,8 +324,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { // Refund a portion of the gold - if (!vendor.getBuilding().transferGold(totalValue, false)) - return; + vendor.getBuilding().transferGold(totalValue, false); } catch (Exception e) { Logger.error(e); @@ -414,18 +393,14 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { for (int itemUUID : itemList.keySet()) { - int type = itemList.get(itemUUID); - if (type == GameObjectType.Item.ordinal()) { - targetItem = Item.getFromCache(itemUUID); - - } else - targetItem = MobLoot.getFromCache(itemUUID); + targetItem = Item.getFromCache(itemUUID); if (targetItem == null) return; if (targetItem.template.item_type.equals(ItemType.GOLD)) return; + if (vendor.charItemManager.inventoryContains(targetItem) == false) return;