|
|
@ -46,7 +46,7 @@ public class CharacterItemManager { |
|
|
|
private final ConcurrentHashMap<Integer, Integer> itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); |
|
|
|
private final ConcurrentHashMap<Integer, Integer> itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); |
|
|
|
// Mapping of all items equipped in this Manager
|
|
|
|
// Mapping of all items equipped in this Manager
|
|
|
|
// Key = Item Slot
|
|
|
|
// Key = Item Slot
|
|
|
|
private final ConcurrentHashMap<Integer, Item> equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); |
|
|
|
private final ConcurrentHashMap<Enum.EquipSlotType, Item> equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); |
|
|
|
private final HashSet<Item> inventory = new HashSet<>(); |
|
|
|
private final HashSet<Item> inventory = new HashSet<>(); |
|
|
|
private final HashSet<Item> bank = new HashSet<>(); |
|
|
|
private final HashSet<Item> bank = new HashSet<>(); |
|
|
|
private final HashSet<Item> vault = new HashSet<>(); |
|
|
|
private final HashSet<Item> vault = new HashSet<>(); |
|
|
@ -186,8 +186,8 @@ public class CharacterItemManager { |
|
|
|
switch (i.containerType) { |
|
|
|
switch (i.containerType) { |
|
|
|
case EQUIPPED: |
|
|
|
case EQUIPPED: |
|
|
|
if (this.equipped.containsValue(i) == false) { |
|
|
|
if (this.equipped.containsValue(i) == false) { |
|
|
|
this.equipped.put((int) i.getEquipSlot(), i); |
|
|
|
this.equipped.put(i.equipSlot, i); |
|
|
|
addEquipOrder((int) i.getEquipSlot()); |
|
|
|
addEquipOrder(i.equipSlot.ordinal()); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BANK: |
|
|
|
case BANK: |
|
|
@ -235,7 +235,7 @@ public class CharacterItemManager { |
|
|
|
switch (i.containerType) { |
|
|
|
switch (i.containerType) { |
|
|
|
case EQUIPPED: |
|
|
|
case EQUIPPED: |
|
|
|
if (this.equipped.containsValue(i) == false) |
|
|
|
if (this.equipped.containsValue(i) == false) |
|
|
|
this.equipped.put((int) i.getEquipSlot(), i); |
|
|
|
this.equipped.put(i.equipSlot, i); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BANK: |
|
|
|
case BANK: |
|
|
|
if (i.getItemBase().getType().equals(ItemType.GOLD)) |
|
|
|
if (i.getItemBase().getType().equals(ItemType.GOLD)) |
|
|
@ -927,13 +927,11 @@ public class CharacterItemManager { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
byte slot = i.getEquipSlot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) |
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
this.itemIDtoType.remove(i.getObjectUUID()); |
|
|
|
this.itemIDtoType.remove(i.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
|
|
calculateWeights(); |
|
|
|
calculateWeights(); |
|
|
@ -962,13 +960,11 @@ public class CharacterItemManager { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
byte slot = i.getEquipSlot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob && (i.containerType != Enum.ItemContainerType.FORGE)) |
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob && (i.containerType != Enum.ItemContainerType.FORGE)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
this.itemIDtoType.remove(i.getObjectUUID()); |
|
|
|
this.itemIDtoType.remove(i.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
|
|
i.junk(); |
|
|
|
i.junk(); |
|
|
@ -993,7 +989,6 @@ public class CharacterItemManager { |
|
|
|
|
|
|
|
|
|
|
|
boolean fromEquip = false; |
|
|
|
boolean fromEquip = false; |
|
|
|
synchronized (this) { |
|
|
|
synchronized (this) { |
|
|
|
byte slot = i.getEquipSlot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Skip if NOT in vault.
|
|
|
|
//Skip if NOT in vault.
|
|
|
|
if (i.containerType != Enum.ItemContainerType.VAULT) |
|
|
|
if (i.containerType != Enum.ItemContainerType.VAULT) |
|
|
@ -1019,7 +1014,7 @@ public class CharacterItemManager { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
|
|
|
|
|
|
|
|
// add to Inventory
|
|
|
|
// add to Inventory
|
|
|
|
this.inventory.add(i); |
|
|
|
this.inventory.add(i); |
|
|
@ -1040,7 +1035,6 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized boolean moveItemToBank(Item i) { |
|
|
|
public synchronized boolean moveItemToBank(Item i) { |
|
|
|
byte slot = i.getEquipSlot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) |
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -1057,7 +1051,7 @@ public class CharacterItemManager { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
|
|
|
|
|
|
|
|
// add to Bank
|
|
|
|
// add to Bank
|
|
|
|
this.bank.add(i); |
|
|
|
this.bank.add(i); |
|
|
@ -1186,7 +1180,6 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized boolean moveItemToVault(Item i) { |
|
|
|
public synchronized boolean moveItemToVault(Item i) { |
|
|
|
byte slot = i.getEquipSlot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (this.doesCharOwnThisItem(i.getObjectUUID()) == false)
|
|
|
|
// if (this.doesCharOwnThisItem(i.getObjectUUID()) == false)
|
|
|
|
// return false;
|
|
|
|
// return false;
|
|
|
@ -1203,7 +1196,7 @@ public class CharacterItemManager { |
|
|
|
return false; // NPC's dont have vaults!
|
|
|
|
return false; // NPC's dont have vaults!
|
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
|
|
|
|
|
|
|
|
// add to Vault
|
|
|
|
// add to Vault
|
|
|
|
i.addToCache(); |
|
|
|
i.addToCache(); |
|
|
@ -1276,13 +1269,14 @@ public class CharacterItemManager { |
|
|
|
public boolean equipItem(Item i, byte slot) { |
|
|
|
public boolean equipItem(Item i, byte slot) { |
|
|
|
|
|
|
|
|
|
|
|
synchronized (this) { |
|
|
|
synchronized (this) { |
|
|
|
byte curSlot = i.getEquipSlot(); // Should be 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob) { |
|
|
|
if (this.doesCharOwnThisItem(i.getObjectUUID()) == false && this.absCharacter.getObjectType() != GameObjectType.Mob) { |
|
|
|
Logger.error("Doesnt own item"); |
|
|
|
Logger.error("Doesnt own item"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Enum.EquipSlotType equipSlot = Enum.EquipSlotType.values()[slot]; |
|
|
|
|
|
|
|
|
|
|
|
// Item must be in inventory to equip
|
|
|
|
// Item must be in inventory to equip
|
|
|
|
if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob) |
|
|
|
if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -1290,7 +1284,7 @@ public class CharacterItemManager { |
|
|
|
// make sure player can equip item
|
|
|
|
// make sure player can equip item
|
|
|
|
if (i.getItemBase() == null) |
|
|
|
if (i.getItemBase() == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!i.getItemBase().canEquip(slot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob) |
|
|
|
if (!i.getItemBase().canEquip(equipSlot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// check to see if item is already there.
|
|
|
|
// check to see if item is already there.
|
|
|
@ -1314,13 +1308,14 @@ public class CharacterItemManager { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(i, slot); |
|
|
|
this.remItemFromLists(i); |
|
|
|
|
|
|
|
|
|
|
|
// add to Equipped
|
|
|
|
// add to Equipped
|
|
|
|
this.equipped.put((int) slot, i); |
|
|
|
this.equipped.put(Enum.EquipSlotType.values()[slot], i); |
|
|
|
|
|
|
|
|
|
|
|
i.addToCache(); |
|
|
|
i.addToCache(); |
|
|
|
|
|
|
|
|
|
|
|
addEquipOrder(i.getEquipSlot()); |
|
|
|
addEquipOrder(slot); |
|
|
|
|
|
|
|
|
|
|
|
//calculateWeights();
|
|
|
|
//calculateWeights();
|
|
|
|
} |
|
|
|
} |
|
|
@ -1697,9 +1692,9 @@ public class CharacterItemManager { |
|
|
|
return lootItem; |
|
|
|
return lootItem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void remItemFromLists(Item i, byte slot) { |
|
|
|
private synchronized void remItemFromLists(Item i) { |
|
|
|
|
|
|
|
|
|
|
|
this.equipped.remove((int) slot); |
|
|
|
this.equipped.remove(i.equipSlot); |
|
|
|
this.vault.remove(i); |
|
|
|
this.vault.remove(i); |
|
|
|
this.bank.remove(i); |
|
|
|
this.bank.remove(i); |
|
|
|
this.inventory.remove(i); |
|
|
|
this.inventory.remove(i); |
|
|
@ -1858,9 +1853,9 @@ public class CharacterItemManager { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int slot : this.equipped.keySet()) { |
|
|
|
for (Enum.EquipSlotType slot : this.equipped.keySet()) { |
|
|
|
|
|
|
|
|
|
|
|
if (slot == MBServerStatics.SLOT_HAIRSTYLE || slot == MBServerStatics.SLOT_BEARDSTYLE) |
|
|
|
if (slot == Enum.EquipSlotType.HAIR || slot == Enum.EquipSlotType.BEARD) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
Item item = this.equipped.get(slot); |
|
|
|
Item item = this.equipped.get(slot); |
|
|
@ -1872,7 +1867,7 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!ItemTemplate.validForSkills(item, pc.getSkills())) { |
|
|
|
if (!ItemTemplate.validForSkills(item, pc.getSkills())) { |
|
|
|
this.forceToInventory(slot, item, pc, initialized); |
|
|
|
this.forceToInventory(slot.ordinal(), item, pc, initialized); |
|
|
|
pc.applyBonuses(); |
|
|
|
pc.applyBonuses(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1886,7 +1881,7 @@ public class CharacterItemManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @return the equipped |
|
|
|
* @return the equipped |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ConcurrentHashMap<Integer, Item> getEquipped() { |
|
|
|
public ConcurrentHashMap<Enum.EquipSlotType, Item> getEquipped() { |
|
|
|
synchronized (this.equipped) { |
|
|
|
synchronized (this.equipped) { |
|
|
|
return new ConcurrentHashMap<>(this.equipped); |
|
|
|
return new ConcurrentHashMap<>(this.equipped); |
|
|
|
} |
|
|
|
} |
|
|
@ -1902,9 +1897,9 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret.size() != this.equipped.size()) |
|
|
|
if (ret.size() != this.equipped.size()) |
|
|
|
//missed adding some items, figure out what.
|
|
|
|
//missed adding some items, figure out what.
|
|
|
|
for (int slot : this.equipped.keySet()) { |
|
|
|
for (Enum.EquipSlotType slot : this.equipped.keySet()) { |
|
|
|
if (!(this.equipOrder.contains(slot))) { |
|
|
|
if (!(this.equipOrder.contains(slot.ordinal()))) { |
|
|
|
this.equipOrder.add(slot); |
|
|
|
this.equipOrder.add(slot.ordinal()); |
|
|
|
ret.add(this.equipped.get(slot)); |
|
|
|
ret.add(this.equipped.get(slot)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1913,7 +1908,7 @@ public class CharacterItemManager { |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Item getEquipped(int slot) { |
|
|
|
public Item getEquipped(Enum.EquipSlotType slot) { |
|
|
|
synchronized (this.equipped) { |
|
|
|
synchronized (this.equipped) { |
|
|
|
return this.equipped.get(slot); |
|
|
|
return this.equipped.get(slot); |
|
|
|
} |
|
|
|
} |
|
|
@ -2282,7 +2277,7 @@ public class CharacterItemManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// remove it from other lists:
|
|
|
|
// remove it from other lists:
|
|
|
|
this.remItemFromLists(item, (byte) slot); |
|
|
|
this.remItemFromLists(item); |
|
|
|
|
|
|
|
|
|
|
|
// add to Inventory
|
|
|
|
// add to Inventory
|
|
|
|
this.inventory.add(item); |
|
|
|
this.inventory.add(item); |
|
|
@ -2444,10 +2439,13 @@ public class CharacterItemManager { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
//verify the item is equipped by this player
|
|
|
|
//verify the item is equipped by this player
|
|
|
|
int slot = item.getEquipSlot(); |
|
|
|
Enum.EquipSlotType slot = item.equipSlot; |
|
|
|
|
|
|
|
|
|
|
|
if (!this.equipped.containsKey(slot)) |
|
|
|
if (!this.equipped.containsKey(slot)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
Item verify = this.equipped.get(slot); |
|
|
|
Item verify = this.equipped.get(slot); |
|
|
|
|
|
|
|
|
|
|
|
if (verify == null || item.getObjectUUID() != verify.getObjectUUID()) |
|
|
|
if (verify == null || item.getObjectUUID() != verify.getObjectUUID()) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
@ -2481,7 +2479,7 @@ public class CharacterItemManager { |
|
|
|
//send damage item msg to client
|
|
|
|
//send damage item msg to client
|
|
|
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter; |
|
|
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter; |
|
|
|
|
|
|
|
|
|
|
|
ItemHealthUpdateMsg itemHealthUpdateMsg = new ItemHealthUpdateMsg(slot, (float) dur); |
|
|
|
ItemHealthUpdateMsg itemHealthUpdateMsg = new ItemHealthUpdateMsg(slot.ordinal(), (float) dur); |
|
|
|
Dispatch dispatch = Dispatch.borrow(pc, itemHealthUpdateMsg); |
|
|
|
Dispatch dispatch = Dispatch.borrow(pc, itemHealthUpdateMsg); |
|
|
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); |
|
|
|
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); |
|
|
|
|
|
|
|
|
|
|
@ -2490,26 +2488,18 @@ public class CharacterItemManager { |
|
|
|
//Damage a random piece of armor a specified amount
|
|
|
|
//Damage a random piece of armor a specified amount
|
|
|
|
public void damageRandomArmor(int amount) { |
|
|
|
public void damageRandomArmor(int amount) { |
|
|
|
ArrayList<Item> armor = new ArrayList<>(); |
|
|
|
ArrayList<Item> armor = new ArrayList<>(); |
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_OFFHAND)) { |
|
|
|
|
|
|
|
Item item = this.equipped.get(MBServerStatics.SLOT_OFFHAND); |
|
|
|
if (this.equipped.containsKey(Enum.EquipSlotType.LHELD)) { |
|
|
|
|
|
|
|
Item item = this.equipped.get(Enum.EquipSlotType.LHELD); |
|
|
|
|
|
|
|
|
|
|
|
ItemBase ib = item.getItemBase(); |
|
|
|
ItemBase ib = item.getItemBase(); |
|
|
|
if (ib.isShield()) |
|
|
|
if (ib.isShield()) |
|
|
|
armor.add(item); |
|
|
|
armor.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_HELMET)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_HELMET)); |
|
|
|
for (Item equipment : this.equipped.values()) |
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_CHEST)) |
|
|
|
if (equipment.template.item_type.equals(ItemType.ARMOR)) |
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_CHEST)); |
|
|
|
armor.add(equipment); |
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_ARMS)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_ARMS)); |
|
|
|
|
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); |
|
|
|
|
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_GLOVES)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_GLOVES)); |
|
|
|
|
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_LEGGINGS)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_LEGGINGS)); |
|
|
|
|
|
|
|
if (this.equipped.containsKey(MBServerStatics.SLOT_FEET)) |
|
|
|
|
|
|
|
armor.add(this.equipped.get(MBServerStatics.SLOT_FEET)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (armor.isEmpty()) |
|
|
|
if (armor.isEmpty()) |
|
|
|
return; //nothing to damage
|
|
|
|
return; //nothing to damage
|
|
|
|