From f6fbc6fecbfd9cc7c47a9e6646801e9190a9bb71 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 9 Mar 2024 09:30:58 -0500 Subject: [PATCH] Logic cleanup --- src/engine/objects/CharacterItemManager.java | 29 ++++++++++++-------- src/engine/objects/Item.java | 20 +++++++------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 4fa6388d..215b8eac 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -984,41 +984,46 @@ public class CharacterItemManager { return true; } - public synchronized boolean moveItemToInventory(Item i) { + public synchronized boolean moveItemToInventory(Item item) { boolean fromEquip = false; synchronized (this) { //Skip if NOT in vault. - if (i.containerType != Enum.ItemContainerType.VAULT) - if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) + if (item.containerType != Enum.ItemContainerType.VAULT) + if (this.doesCharOwnThisItem(item.getObjectUUID()) == false) return false; // Only valid from bank, equip and vault - if (!bankContains(i) && !equippedContains(i) && !vaultContains(i)) + if (!bankContains(item) && !equippedContains(item) && !vaultContains(item)) return false; - if (equippedContains(i)) { + if (equippedContains(item)) { fromEquip = true; - ItemBase ib = i.getItemBase(); + ItemBase ib = item.getItemBase(); if (ib != null && ib.getType().equals(ItemType.GOLD)) this.absCharacter.cancelOnUnEquip(); } + // Clear equipment of item. + + this.absCharacter.charItemManager.equipped.remove(item.equipSlot); + // check to see what type of AbstractCharacter subclass we have stored + if (this.absCharacter.getClass() == PlayerCharacter.class) { - if (!i.moveItemToInventory((PlayerCharacter) this.absCharacter)) + if (!item.moveItemToInventory((PlayerCharacter) this.absCharacter)) return false; - } else if (!i.moveItemToInventory((NPC) this.absCharacter)) + } else if (!item.moveItemToInventory((NPC) this.absCharacter)) return false; // remove it from other lists: - this.remItemFromLists(i); + this.remItemFromLists(item); // add to Inventory - this.inventory.add(i); - i.addToCache(); - this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal()); + this.inventory.add(item); + item.addToCache(); + this.itemIDtoType.put(item.getObjectUUID(), item.getObjectType().ordinal()); calculateWeights(); } diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index d8f9dbf2..5458f521 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -816,6 +816,14 @@ public class Item extends AbstractWorldObject { DbManager.ItemQueries.UPDATE_REMAINING_CHARGES(this); } + public void zeroItem() { + this.ownerID = 0; + + this.ownerType = null; + this.containerType = Enum.ItemContainerType.NONE; + this.equipSlot = EquipSlotType.NONE; + } + protected void validateItemContainer() { if (this.containerType == Enum.ItemContainerType.NONE) @@ -842,15 +850,8 @@ public class Item extends AbstractWorldObject { this.removeFromCache(); } - public synchronized void zeroItem() { - this.ownerID = 0; - - this.ownerType = null; - this.containerType = Enum.ItemContainerType.NONE; - this.equipSlot = EquipSlotType.NONE; - } - protected synchronized boolean moveItemToInventory(PlayerCharacter pc) { + if (!DbManager.ItemQueries.UPDATE_OWNER(this, pc.getObjectUUID(), //tableID false, //isNPC @@ -858,13 +859,12 @@ public class Item extends AbstractWorldObject { false, //isAccount ItemContainerType.INVENTORY, 0)) //Slot - return false; - this.zeroItem(); this.ownerID = pc.getObjectUUID(); this.ownerType = OwnerType.PlayerCharacter; this.containerType = ItemContainerType.INVENTORY; + this.equipSlot = EquipSlotType.NONE; return true; }