From b98e7cda15bb54c27752e030e103890baa2d3ec9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 2 Mar 2024 11:07:07 -0500 Subject: [PATCH] More item refactor work. --- src/engine/Enum.java | 23 ------ src/engine/gameManager/BuildingManager.java | 80 ------------------- .../client/handlers/OrderNPCMsgHandler.java | 6 +- src/engine/objects/Item.java | 35 +------- src/engine/objects/ItemFactory.java | 9 ++- src/engine/objects/Kit.java | 14 ++-- src/engine/objects/Warehouse.java | 17 ++-- 7 files changed, 28 insertions(+), 156 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index a6ab2532..f67c3828 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2244,29 +2244,6 @@ public class Enum { ITEM } - public enum objectMaskType { - PLAYER, - MOB, - PET, - CORPSE, - BUILDING, - UNDEAD, - BEAST, - HUMANOID, - NPC, - IAGENT, - DRAGON, - RAT, - SIEGE, - CITY, - ZONE; - - public static EnumSet AGGRO = EnumSet.of(PLAYER, PET); - public static EnumSet MOBILE = EnumSet.of(PLAYER, MOB, PET); - public static EnumSet STATIC = EnumSet.of(CORPSE, BUILDING, NPC); - - } - public enum ItemContainerType { NONE, INVENTORY, diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 01fceac3..746e8e61 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -19,10 +19,7 @@ import engine.job.JobScheduler; import engine.jobs.UpgradeBuildingJob; import engine.math.Bounds; import engine.math.Vector3fImmutable; -import engine.net.client.ClientConnection; import engine.net.client.msg.ErrorPopupMsg; -import engine.net.client.msg.ManageCityAssetsMsg; -import engine.net.client.msg.PlaceAssetMsg; import engine.objects.*; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -780,83 +777,6 @@ public enum BuildingManager { } - public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) { - - // Member variable declaration - PlayerCharacter player; - Contract contract; - CharacterItemManager itemMan; - ItemBase itemBase; - Item item; - - npc.lock.writeLock().lock(); - - try { - - - if (building == null) - return; - player = SessionManager.getPlayerCharacter(origin); - itemMan = player.getCharItemManager(); - - contract = npc.getContract(); - - if (!player.getCharItemManager().hasRoomInventory((short) 1)) { - ErrorPopupMsg.sendErrorPopup(player, 21); - return; - } - - - if (!building.getHirelings().containsKey(npc)) - return; - - if (!npc.remove()) { - PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); - return; - } - - building.getHirelings().remove(npc); - - itemBase = ItemBase.getItemBase(contract.getContractID()); - - if (itemBase == null) { - Logger.error("Could not find Contract for npc: " + npc.getObjectUUID()); - return; - } - - boolean itemWorked = false; - - item = new Item(itemBase, player.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1), - (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(1); - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.PERSIST(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } - - ManageCityAssetsMsg mca = new ManageCityAssetsMsg(); - mca.actionType = NPC.SVR_CLOSE_WINDOW; - mca.setTargetType(building.getObjectType().ordinal()); - mca.setTargetID(building.getObjectUUID()); - origin.sendMsg(mca); - - } catch (Exception e) { - Logger.error(e); - } finally { - npc.lock.writeLock().unlock(); - } - - } - public static void rebuildMine(Building mineBuilding) { setRank(mineBuilding, 1); mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank); diff --git a/src/engine/net/client/handlers/OrderNPCMsgHandler.java b/src/engine/net/client/handlers/OrderNPCMsgHandler.java index 08592353..ccdb621b 100644 --- a/src/engine/net/client/handlers/OrderNPCMsgHandler.java +++ b/src/engine/net/client/handlers/OrderNPCMsgHandler.java @@ -68,8 +68,10 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler { boolean itemWorked = false; - item = new Item(itemBase, player.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) ((byte) hireling.getRank() - 1), (byte) ((byte) hireling.getRank() - 1), (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, new ArrayList<>(), ""); - item.setNumOfItems(1); + item = new Item(itemBase.getUUID()); + item.ownerID = player.getObjectUUID(); + item.ownerType = Enum.OwnerType.PlayerCharacter; + item.chargesRemaining = (byte) hireling.getRank() - 1; item.containerType = Enum.ItemContainerType.INVENTORY; try { diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 12a9d8c8..57d19582 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -47,7 +47,7 @@ public class Item extends AbstractWorldObject { public ReentrantLock lootLock = new ReentrantLock(); public int ownerID; //may be character, account, npc, mob private int flags; //1 = isIDed - private int numberOfItems; + public int numberOfItems; public float durabilityCurrent; public int chargesRemaining; public byte equipSlot; @@ -73,37 +73,8 @@ public class Item extends AbstractWorldObject { this.chargesRemaining = this.template.item_initial_charges; this.durabilityCurrent = this.template.combat_health_full; this.equipSlot = 0; - loadEnchantments(); - bakeInStats(); - } - - public Item(ItemBase itemBase, int ownerID, - OwnerType ownerType, byte chargesMax, byte chargesRemaining, - short durabilityCurrent, short durabilityMax, boolean canDestroy, - boolean rentable, Enum.ItemContainerType containerType, byte equipSlot, - String name) { - super(); - this.templsteID = itemBase.getUUID(); - this.ownerID = ownerID; - this.ownerType = ownerType; - - if (itemBase.getType().getValue() == 20) { - this.chargesMax = chargesMax; - this.chargesRemaining = chargesRemaining; - } else { - this.chargesMax = (byte) itemBase.getNumCharges(); - this.chargesRemaining = (byte) itemBase.getNumCharges(); - } - - this.durabilityMax = (short) itemBase.getDurability(); - this.durabilityCurrent = (short) itemBase.getDurability(); - this.containerType = containerType; - this.canDestroy = canDestroy; - this.equipSlot = equipSlot; - this.flags = 1; - this.value = this.magicValue; - this.customName = name; - + this.containerType = ItemContainerType.NONE; + this.numberOfItems = 1; loadEnchantments(); bakeInStats(); } diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 5360c5b9..be2cd3bf 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -25,7 +25,6 @@ import engine.server.MBServerStatics; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; -import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -57,9 +56,11 @@ public class ItemFactory { break; } - Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); + Item item = new Item(ib.getUUID()); + item.ownerID = pc.getObjectUUID(); + item.ownerType = OwnerType.PlayerCharacter; + item.containerType = ItemContainerType.INVENTORY; + try { item = DbManager.ItemQueries.PERSIST(item); worked = true; diff --git a/src/engine/objects/Kit.java b/src/engine/objects/Kit.java index 3ec8354e..aebca369 100644 --- a/src/engine/objects/Kit.java +++ b/src/engine/objects/Kit.java @@ -112,20 +112,20 @@ public class Kit extends AbstractGameObject { */ private static boolean kitItemCreator(PlayerCharacter pc, int itemBase, int slot) { - ItemBase i = ItemBase.getItemBase(itemBase); - Item temp = new Item(i, pc.getObjectUUID(), - OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) 0, (short) 0, - false, false, ItemContainerType.EQUIPPED, (byte) slot, - new ArrayList<>(), ""); + Item item = new Item(itemBase); + item.ownerID = pc.getObjectUUID(); + item.ownerType = OwnerType.PlayerCharacter; + item.containerType = ItemContainerType.EQUIPPED; + item.equipSlot = (byte) slot; try { - temp = DbManager.ItemQueries.PERSIST(temp); + item = DbManager.ItemQueries.PERSIST(item); } catch (Exception e) { Logger.error(e); } - if (temp == null) { + if (item == null) { Logger.info("Ungoof this goof, something is wrong with our kit."); } return true; diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 5b0c8e0f..8839ea1e 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -753,11 +753,12 @@ public class Warehouse extends AbstractWorldObject { itemMan.updateInventory(); } else { boolean itemWorked = false; - Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(amount); + + Item item = new Item(ib.getUUID()); + item.ownerID = pc.getObjectUUID(); + item.ownerType = Enum.OwnerType.PlayerCharacter; item.containerType = Enum.ItemContainerType.INVENTORY; + item.numberOfItems = amount; try { item = DbManager.ItemQueries.PERSIST(item); @@ -829,11 +830,11 @@ public class Warehouse extends AbstractWorldObject { itemMan.updateInventory(); } else { boolean itemWorked = false; - Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(amount); + Item item = new Item(ib.getUUID()); + item.ownerID = pc.getObjectUUID(); + item.ownerType = Enum.OwnerType.PlayerCharacter; item.containerType = Enum.ItemContainerType.INVENTORY; + item.numberOfItems = amount; try { item = DbManager.ItemQueries.PERSIST(item);