From 2ceaece7d9a6d8f4036726fbec33db1c64438005 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 15 Mar 2024 11:30:03 -0400 Subject: [PATCH] More itembase refactor work --- src/engine/net/client/ClientMessagePump.java | 44 ++++++++++---------- src/engine/objects/Item.java | 4 +- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 32b6ca8f..3023af22 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -1243,16 +1243,15 @@ public class ClientMessagePump implements NetMsgHandler { Item buy = null; if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) { + ArrayList sellInventory = npc.getContract().getSellInventory(); + if (sellInventory == null) return; - for (MobEquipment me : sellInventory) { - if (me.getObjectUUID() == msg.getItemID()) { - ItemBase ib = me.getItemBase(); + for (MobEquipment me : sellInventory) { - if (ib == null) - return; + if (me.getObjectUUID() == msg.getItemID()) { //test room available for item if (!itemMan.hasRoomInventory(me.template.item_wt)) @@ -1275,22 +1274,22 @@ public class ClientMessagePump implements NetMsgHandler { return; } - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + Building building = (!npc.isStatic()) ? npc.getBuilding() : null; - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; + if (building != null && building.getProtectionState().equals(ProtectionState.NPC)) + building = null; int buildingDeposit = cost - me.getMagicValue(); - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); return; } - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { + if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) { // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item."); return; } - buy = Item.createItemForPlayer(sourcePlayer, ib); + buy = Item.createItemForPlayer(sourcePlayer, me.templateID); if (buy != null) { me.transferEnchants(buy); @@ -1344,20 +1343,20 @@ public class ClientMessagePump implements NetMsgHandler { return; } - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + Building building = (!npc.isStatic()) ? npc.getBuilding() : null; - if (b != null) - if (b.getProtectionState().equals(ProtectionState.NPC)) - b = null; + if (building != null) + if (building.getProtectionState().equals(ProtectionState.NPC)) + building = null; int buildingDeposit = cost; - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); return; } - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { + if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110); return; } @@ -1391,24 +1390,23 @@ public class ClientMessagePump implements NetMsgHandler { int cost = buy.getMagicValue(); cost *= npc.getSellPercent(sourcePlayer); - if (gold.getNumOfItems() - cost < 0) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold return; } - Building b = (!npc.isStatic()) ? npc.getBuilding() : null; + Building building = (!npc.isStatic()) ? npc.getBuilding() : null; - if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) - b = null; + if (building != null && building.getProtectionState().equals(ProtectionState.NPC)) + building = null; int buildingDeposit = cost; - if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { + if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); return; } - if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) + if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) return; if (buy != null) diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index ad85bf01..1f43d1bb 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -523,9 +523,9 @@ public class Item extends AbstractWorldObject { writer.putIntAt(serialized, indexPosition); } - public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) { + public static Item createItemForPlayer(PlayerCharacter pc, int templateID) { - Item item = new Item(ib.getUUID()); + Item item = new Item(templateID); item.ownerID = pc.getObjectUUID(); item.ownerType = OwnerType.PlayerCharacter;