Browse Source

Logic cleanup

combat-2
MagicBot 8 months ago
parent
commit
f6fbc6fecb
  1. 29
      src/engine/objects/CharacterItemManager.java
  2. 20
      src/engine/objects/Item.java

29
src/engine/objects/CharacterItemManager.java

@ -984,41 +984,46 @@ public class CharacterItemManager { @@ -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();
}

20
src/engine/objects/Item.java

@ -816,6 +816,14 @@ public class Item extends AbstractWorldObject { @@ -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 { @@ -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 { @@ -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;
}

Loading…
Cancel
Save