forked from MagicBane/Server
Logic cleanup
This commit is contained in:
@@ -984,41 +984,46 @@ public class CharacterItemManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean moveItemToInventory(Item i) {
|
public synchronized boolean moveItemToInventory(Item item) {
|
||||||
|
|
||||||
boolean fromEquip = false;
|
boolean fromEquip = false;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
||||||
//Skip if NOT in vault.
|
//Skip if NOT in vault.
|
||||||
if (i.containerType != Enum.ItemContainerType.VAULT)
|
if (item.containerType != Enum.ItemContainerType.VAULT)
|
||||||
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false)
|
if (this.doesCharOwnThisItem(item.getObjectUUID()) == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Only valid from bank, equip and vault
|
// Only valid from bank, equip and vault
|
||||||
if (!bankContains(i) && !equippedContains(i) && !vaultContains(i))
|
if (!bankContains(item) && !equippedContains(item) && !vaultContains(item))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (equippedContains(i)) {
|
if (equippedContains(item)) {
|
||||||
fromEquip = true;
|
fromEquip = true;
|
||||||
ItemBase ib = i.getItemBase();
|
ItemBase ib = item.getItemBase();
|
||||||
if (ib != null && ib.getType().equals(ItemType.GOLD))
|
if (ib != null && ib.getType().equals(ItemType.GOLD))
|
||||||
this.absCharacter.cancelOnUnEquip();
|
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
|
// check to see what type of AbstractCharacter subclass we have stored
|
||||||
|
|
||||||
if (this.absCharacter.getClass() == PlayerCharacter.class) {
|
if (this.absCharacter.getClass() == PlayerCharacter.class) {
|
||||||
if (!i.moveItemToInventory((PlayerCharacter) this.absCharacter))
|
if (!item.moveItemToInventory((PlayerCharacter) this.absCharacter))
|
||||||
return false;
|
return false;
|
||||||
} else if (!i.moveItemToInventory((NPC) this.absCharacter))
|
} else if (!item.moveItemToInventory((NPC) this.absCharacter))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// remove it from other lists:
|
// remove it from other lists:
|
||||||
this.remItemFromLists(i);
|
this.remItemFromLists(item);
|
||||||
|
|
||||||
// add to Inventory
|
// add to Inventory
|
||||||
this.inventory.add(i);
|
this.inventory.add(item);
|
||||||
i.addToCache();
|
item.addToCache();
|
||||||
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
|
this.itemIDtoType.put(item.getObjectUUID(), item.getObjectType().ordinal());
|
||||||
|
|
||||||
calculateWeights();
|
calculateWeights();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -816,6 +816,14 @@ public class Item extends AbstractWorldObject {
|
|||||||
DbManager.ItemQueries.UPDATE_REMAINING_CHARGES(this);
|
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() {
|
protected void validateItemContainer() {
|
||||||
|
|
||||||
if (this.containerType == Enum.ItemContainerType.NONE)
|
if (this.containerType == Enum.ItemContainerType.NONE)
|
||||||
@@ -842,15 +850,8 @@ public class Item extends AbstractWorldObject {
|
|||||||
this.removeFromCache();
|
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) {
|
protected synchronized boolean moveItemToInventory(PlayerCharacter pc) {
|
||||||
|
|
||||||
if (!DbManager.ItemQueries.UPDATE_OWNER(this,
|
if (!DbManager.ItemQueries.UPDATE_OWNER(this,
|
||||||
pc.getObjectUUID(), //tableID
|
pc.getObjectUUID(), //tableID
|
||||||
false, //isNPC
|
false, //isNPC
|
||||||
@@ -858,13 +859,12 @@ public class Item extends AbstractWorldObject {
|
|||||||
false, //isAccount
|
false, //isAccount
|
||||||
ItemContainerType.INVENTORY,
|
ItemContainerType.INVENTORY,
|
||||||
0)) //Slot
|
0)) //Slot
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.zeroItem();
|
|
||||||
this.ownerID = pc.getObjectUUID();
|
this.ownerID = pc.getObjectUUID();
|
||||||
this.ownerType = OwnerType.PlayerCharacter;
|
this.ownerType = OwnerType.PlayerCharacter;
|
||||||
this.containerType = ItemContainerType.INVENTORY;
|
this.containerType = ItemContainerType.INVENTORY;
|
||||||
|
this.equipSlot = EquipSlotType.NONE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user