Browse Source

Handler created for equip message.

combat-2
MagicBot 8 months ago
parent
commit
20cb8ef94d
  1. 26
      src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java
  2. 11
      src/engine/objects/CharacterItemManager.java
  3. 16
      src/engine/objects/Item.java
  4. 3
      src/engine/objects/MobLoot.java

26
src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java

@ -43,28 +43,28 @@ public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHa
return true; return true;
} }
int uuid = transferMsg.getUUID(); int itemUUID = transferMsg.getUUID();
int slot = transferMsg.getSlotNumber(); int slotOrdinal = transferMsg.getSlotNumber();
//System.out.println("loading to slot: " + slot); Enum.EquipSlotType equipSlot = Enum.EquipSlotType.values()[slotOrdinal];
Item i = itemManager.getItemByUUID(uuid); Item item = itemManager.getItemByUUID(itemUUID);
if (i == null) { if (item == null) {
forceTransferFromEquipToInventory(transferMsg, origin, "Item not found in your item manager"); forceTransferFromEquipToInventory(transferMsg, origin, "Item not found in your item manager");
return true; return true;
} }
if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) { if (!itemManager.doesCharOwnThisItem(item.getObjectUUID())) {
forceTransferFromEquipToInventory(transferMsg, origin, "You do not own this item"); forceTransferFromEquipToInventory(transferMsg, origin, "You do not own this item");
return true; return true;
} }
//dupe check //dupe check
if (!i.validForInventory(origin, playerCharacter, itemManager)) if (!item.validForInventory(origin, playerCharacter, itemManager))
return true; return true;
if (i.containerType == Enum.ItemContainerType.INVENTORY) { if (item.containerType == Enum.ItemContainerType.INVENTORY) {
if (!itemManager.equipItem(i, (byte) slot)) { if (!itemManager.equipItem(item, equipSlot)) {
forceTransferFromEquipToInventory(transferMsg, origin, "Failed to transfer item."); forceTransferFromEquipToInventory(transferMsg, origin, "Failed to transfer item.");
return true; return true;
} }
@ -77,8 +77,8 @@ public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHa
playerCharacter.applyBonuses(); playerCharacter.applyBonuses();
DispatchMessage.dispatchMsgToInterestArea(playerCharacter, transferMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, transferMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
for (String name : i.getEffects().keySet()) { for (String name : item.getEffects().keySet()) {
Effect eff = i.getEffects().get(name); Effect eff = item.getEffects().get(name);
if (eff == null) if (eff == null)
return true; return true;
@ -92,8 +92,8 @@ public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHa
pum.setNumTrains(eff.getTrains()); pum.setNumTrains(eff.getTrains());
pum.setUnknown05(1); pum.setUnknown05(1);
pum.setUnknown06((byte) 1); pum.setUnknown06((byte) 1);
pum.setEffectSourceType(i.getObjectType().ordinal()); pum.setEffectSourceType(item.getObjectType().ordinal());
pum.setEffectSourceID(i.getObjectUUID()); pum.setEffectSourceID(item.getObjectUUID());
pum.setDuration(-1); pum.setDuration(-1);
DispatchMessage.dispatchMsgToInterestArea(playerCharacter, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, pum, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);

11
src/engine/objects/CharacterItemManager.java

@ -1266,7 +1266,7 @@ public class CharacterItemManager {
return false; return false;
} }
public boolean equipItem(Item i, byte slot) { public boolean equipItem(Item i, Enum.EquipSlotType slot) {
synchronized (this) { synchronized (this) {
@ -1275,7 +1275,6 @@ public class CharacterItemManager {
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)
@ -1284,11 +1283,11 @@ 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(equipSlot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob) if (!i.getItemBase().canEquip(slot, 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.
Item old = this.equipped.get((int) slot); Item old = this.equipped.get(slot);
if (old != null) { if (old != null) {
Logger.error("already equipped"); Logger.error("already equipped");
return false; return false;
@ -1311,11 +1310,11 @@ public class CharacterItemManager {
this.remItemFromLists(i); this.remItemFromLists(i);
// add to Equipped // add to Equipped
this.equipped.put(Enum.EquipSlotType.values()[slot], i); this.equipped.put(slot, i);
i.addToCache(); i.addToCache();
addEquipOrder(slot); addEquipOrder(slot.ordinal());
//calculateWeights(); //calculateWeights();
} }

16
src/engine/objects/Item.java

@ -956,7 +956,7 @@ public class Item extends AbstractWorldObject {
return true; return true;
} }
protected synchronized boolean equipItem(PlayerCharacter pc, byte slot) { protected synchronized boolean equipItem(PlayerCharacter pc, Enum.EquipSlotType slot) {
if (!DbManager.ItemQueries.UPDATE_OWNER(this, if (!DbManager.ItemQueries.UPDATE_OWNER(this,
pc.getObjectUUID(), //tableID pc.getObjectUUID(), //tableID
@ -964,42 +964,42 @@ public class Item extends AbstractWorldObject {
true, //isPlayer true, //isPlayer
false, //isAccount false, //isAccount
ItemContainerType.EQUIPPED, ItemContainerType.EQUIPPED,
slot)) //Slot slot.ordinal())) //Slot
return false; return false;
this.zeroItem(); this.zeroItem();
this.ownerID = pc.getObjectUUID(); this.ownerID = pc.getObjectUUID();
this.ownerType = OwnerType.PlayerCharacter; this.ownerType = OwnerType.PlayerCharacter;
this.containerType = Enum.ItemContainerType.EQUIPPED; this.containerType = Enum.ItemContainerType.EQUIPPED;
this.equipSlot = EquipSlotType.values()[slot]; this.equipSlot = slot;
return true; return true;
} }
protected synchronized boolean equipItem(NPC npc, byte slot) { protected synchronized boolean equipItem(NPC npc, Enum.EquipSlotType slot) {
if (!DbManager.ItemQueries.UPDATE_OWNER(this, if (!DbManager.ItemQueries.UPDATE_OWNER(this,
npc.getObjectUUID(), //UUID npc.getObjectUUID(), //UUID
true, //isNPC true, //isNPC
false, //isPlayer false, //isPlayer
false, //isAccount false, //isAccount
ItemContainerType.EQUIPPED, ItemContainerType.EQUIPPED,
slot)) //Slot slot.ordinal())) //Slot
return false; return false;
this.zeroItem(); this.zeroItem();
this.ownerID = npc.getObjectUUID(); this.ownerID = npc.getObjectUUID();
this.ownerType = OwnerType.Npc; this.ownerType = OwnerType.Npc;
this.containerType = Enum.ItemContainerType.EQUIPPED; this.containerType = Enum.ItemContainerType.EQUIPPED;
this.equipSlot = EquipSlotType.values()[slot]; this.equipSlot = slot;
return true; return true;
} }
protected synchronized boolean equipItem(Mob npc, byte slot) { protected synchronized boolean equipItem(Mob npc, Enum.EquipSlotType slot) {
this.zeroItem(); this.zeroItem();
this.ownerID = npc.getObjectUUID(); this.ownerID = npc.getObjectUUID();
this.ownerType = OwnerType.Mob; this.ownerType = OwnerType.Mob;
this.containerType = Enum.ItemContainerType.EQUIPPED; this.containerType = Enum.ItemContainerType.EQUIPPED;
this.equipSlot = EquipSlotType.values()[slot]; this.equipSlot = slot;
return true; return true;
} }

3
src/engine/objects/MobLoot.java

@ -239,7 +239,7 @@ public final class MobLoot extends Item {
/** /**
* Not implemented * Not implemented
*/ */
@Override
@Deprecated @Deprecated
protected boolean equipItem(NPC npc, byte slot) { protected boolean equipItem(NPC npc, byte slot) {
return false; return false;
@ -248,7 +248,6 @@ public final class MobLoot extends Item {
/** /**
* Not implemented * Not implemented
*/ */
@Override
@Deprecated @Deprecated
protected boolean equipItem(PlayerCharacter pc, byte slot) { protected boolean equipItem(PlayerCharacter pc, byte slot) {
return false; return false;

Loading…
Cancel
Save