From 04d9b76938e3243762ed654ead1355a6fe6b4523 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 9 Mar 2024 07:41:59 -0500 Subject: [PATCH] More ordinal refactor --- src/engine/db/handlers/dbContractHandler.java | 2 +- src/engine/devcmd/cmds/PrintEquipCmd.java | 4 +- src/engine/devcmd/cmds/PrintStatsCmd.java | 5 +- src/engine/gameManager/CombatManager.java | 10 +-- src/engine/net/client/ClientMessagePump.java | 5 +- ...ansferItemFromInventoryToEquipHandler.java | 5 +- .../TransferItemFromEquipToInventoryMsg.java | 14 ++-- .../TransferItemFromInventoryToEquipMsg.java | 69 ++----------------- src/engine/objects/CharacterItemManager.java | 19 ++--- src/engine/objects/Mob.java | 6 +- src/engine/objects/MobBase.java | 15 ++-- src/engine/objects/MobEquipment.java | 18 ++--- src/engine/objects/NPC.java | 4 +- 13 files changed, 56 insertions(+), 120 deletions(-) diff --git a/src/engine/db/handlers/dbContractHandler.java b/src/engine/db/handlers/dbContractHandler.java index 323b349d..39ee22c2 100644 --- a/src/engine/db/handlers/dbContractHandler.java +++ b/src/engine/db/handlers/dbContractHandler.java @@ -70,7 +70,7 @@ public class dbContractHandler extends dbHandlerBase { if (ib != null) { - MobEquipment me = new MobEquipment(ib, 0, 0); + MobEquipment me = new MobEquipment(ib, Enum.EquipSlotType.NONE, 0); contract.getSellInventory().add(me); //handle magic effects diff --git a/src/engine/devcmd/cmds/PrintEquipCmd.java b/src/engine/devcmd/cmds/PrintEquipCmd.java index bb8de178..9037d51a 100644 --- a/src/engine/devcmd/cmds/PrintEquipCmd.java +++ b/src/engine/devcmd/cmds/PrintEquipCmd.java @@ -64,7 +64,7 @@ public class PrintEquipCmd extends AbstractDevCmd { if (tar.getObjectType() == GameObjectType.Mob) { Mob tarMob = (Mob) tar; throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (int slot : tarMob.getEquip().keySet()) { + for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) { MobEquipment equip = tarMob.getEquip().get(slot); ItemTemplate template = ItemTemplate.itemTemplates.get(equip.getItemBase().getUUID()); throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + template.item_base_name + ", slot: " + slot); @@ -75,7 +75,7 @@ public class PrintEquipCmd extends AbstractDevCmd { if (tar.getObjectType() == GameObjectType.NPC) { NPC tarMob = (NPC) tar; throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); - for (int slot : tarMob.getEquip().keySet()) { + for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) { MobEquipment equip = tarMob.getEquip().get(slot); ItemTemplate template = ItemTemplate.itemTemplates.get(equip.getItemBase().getUUID()); throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + template.item_base_name + ", slot: " + slot); diff --git a/src/engine/devcmd/cmds/PrintStatsCmd.java b/src/engine/devcmd/cmds/PrintStatsCmd.java index 816d918d..0b2d5173 100644 --- a/src/engine/devcmd/cmds/PrintStatsCmd.java +++ b/src/engine/devcmd/cmds/PrintStatsCmd.java @@ -9,6 +9,7 @@ package engine.devcmd.cmds; +import engine.Enum; import engine.devcmd.AbstractDevCmd; import engine.objects.*; @@ -25,7 +26,7 @@ public class PrintStatsCmd extends AbstractDevCmd { // super("printstats", MBServerStatics.ACCESS_LEVEL_ADMIN); } - public static ItemBase getWeaponBase(int slot, HashMap equip) { + public static ItemBase getWeaponBase(int slot, HashMap equip) { if (equip.containsKey(slot)) { MobEquipment item = equip.get(slot); if (item != null && item.getItemBase() != null) { @@ -96,7 +97,7 @@ public class PrintStatsCmd extends AbstractDevCmd { out += "Defense: " + tar.getDefenseRating() + newline; //get weapons - HashMap equip = tar.getEquip(); + HashMap equip = tar.getEquip(); ItemBase main = null; if (equip != null) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 8c408b49..609b12e3 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -865,10 +865,10 @@ public enum CombatManager { if (acItem == null || tarItem == null) return false; - Item acMain = acItem.getItemFromEquipped(1); - Item acOff = acItem.getItemFromEquipped(2); - Item tarMain = tarItem.getItemFromEquipped(1); - Item tarOff = tarItem.getItemFromEquipped(2); + Item acMain = acItem.getItemFromEquipped(EquipSlotType.RHELD); + Item acOff = acItem.getItemFromEquipped(EquipSlotType.LHELD); + Item tarMain = tarItem.getItemFromEquipped(EquipSlotType.RHELD); + Item tarOff = tarItem.getItemFromEquipped(EquipSlotType.LHELD); return !isRanged(acMain) && !isRanged(acOff) && !isRanged(tarMain) && !isRanged(tarOff); } @@ -886,7 +886,7 @@ public enum CombatManager { if (acItem == null || tarItem == null) return false; - Item tarOff = tarItem.getItemFromEquipped(2); + Item tarOff = tarItem.getItemFromEquipped(EquipSlotType.LHELD); if (tarOff == null) return false; diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index cfcbfb22..19fc3bb3 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,6 +9,7 @@ package engine.net.client; +import engine.Enum; import engine.Enum.*; import engine.InterestManagement.WorldGrid; import engine.exception.MsgSendException; @@ -164,7 +165,7 @@ public class ClientMessagePump implements NetMsgHandler { if (itemManager == null) return; - int slot = msg.getSlotNumber(); + Enum.EquipSlotType slot = msg.slot; Item i = itemManager.getItemFromEquipped(slot); if (i == null) @@ -754,7 +755,7 @@ public class ClientMessagePump implements NetMsgHandler { for (MobEquipment equip : mobTarget.getEquip().values()) { - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.getSlot()); + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.slot); DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); LootMsg lootMsg = new LootMsg(0, 0, tar.getObjectType().ordinal(), tar.getObjectUUID(), equip); diff --git a/src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java b/src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java index 97088caa..e40fd2c3 100644 --- a/src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java +++ b/src/engine/net/client/handlers/TransferItemFromInventoryToEquipHandler.java @@ -44,8 +44,7 @@ public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHa } int itemUUID = transferMsg.getUUID(); - int slotOrdinal = transferMsg.getSlotNumber(); - Enum.EquipSlotType equipSlot = Enum.EquipSlotType.values()[slotOrdinal]; + Enum.EquipSlotType equipSlot = transferMsg.slot; Item item = itemManager.getItemByUUID(itemUUID); @@ -109,7 +108,7 @@ public class TransferItemFromInventoryToEquipHandler extends AbstractClientMsgHa if (player == null) return; - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(player, msg.getSlotNumber()); + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(player, msg.slot); Dispatch dispatch = Dispatch.borrow(player, back); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java b/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java index 2dd59b54..a9e5b580 100644 --- a/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java +++ b/src/engine/net/client/msg/TransferItemFromEquipToInventoryMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; +import engine.Enum; import engine.exception.SerializationException; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -21,16 +22,16 @@ public class TransferItemFromEquipToInventoryMsg extends ClientNetMsg { private int playerType; private int playerUUID; - private int slotNumber; + public Enum.EquipSlotType slot; /** * This is the general purpose constructor. */ - public TransferItemFromEquipToInventoryMsg(AbstractGameObject ago, int slotNumber) { + public TransferItemFromEquipToInventoryMsg(AbstractGameObject ago, Enum.EquipSlotType slot) { super(Protocol.UNEQUIP); this.playerType = ago.getObjectType().ordinal(); this.playerUUID = ago.getObjectUUID(); - this.slotNumber = slotNumber; + this.slot = slot; } /** @@ -50,7 +51,7 @@ public class TransferItemFromEquipToInventoryMsg extends ClientNetMsg { protected void _deserialize(ByteBufferReader reader) { this.playerType = reader.getInt(); this.playerUUID = reader.getInt(); - this.slotNumber = reader.getInt(); + this.slot = Enum.EquipSlotType.values()[reader.getInt()]; } /** @@ -60,16 +61,13 @@ public class TransferItemFromEquipToInventoryMsg extends ClientNetMsg { protected void _serialize(ByteBufferWriter writer) throws SerializationException { writer.putInt(this.playerType); writer.putInt(this.playerUUID); - writer.putInt(this.slotNumber); + writer.putInt(this.slot.ordinal()); } /** * @return the slotNumber */ - public int getSlotNumber() { - return slotNumber; - } public int getPlayerType() { return playerType; diff --git a/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java b/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java index c74c035e..5bc3111b 100644 --- a/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java +++ b/src/engine/net/client/msg/TransferItemFromInventoryToEquipMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; +import engine.Enum; import engine.exception.SerializationException; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -25,7 +26,8 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { private int itemBase; private int type; private int objectUUID; - private int slotNumber; + + public Enum.EquipSlotType slot; private int pad2; private float unknown1, unknown2; @@ -36,11 +38,11 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { super(Protocol.EQUIP); } - public TransferItemFromInventoryToEquipMsg(AbstractCharacter source, int slot, int itemBaseID) { + public TransferItemFromInventoryToEquipMsg(AbstractCharacter source, Enum.EquipSlotType slot, int itemBaseID) { super(Protocol.EQUIP); this.sourceType = source.getObjectType().ordinal(); this.sourceID = source.getObjectUUID(); - this.slotNumber = slot; + this.slot = slot; this.itemBase = itemBaseID; } @@ -65,7 +67,7 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { itemBase = reader.getInt(); type = reader.getInt(); objectUUID = reader.getInt(); - slotNumber = reader.getInt(); + slot = Enum.EquipSlotType.values()[reader.getInt()]; pad2 = reader.getInt(); unknown1 = reader.getFloat(); unknown2 = reader.getFloat(); @@ -82,27 +84,12 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { writer.putInt(itemBase); writer.putInt(type); writer.putInt(objectUUID); - writer.putInt(slotNumber); + writer.putInt(slot.ordinal()); writer.putInt(pad2); writer.putFloat(unknown1); writer.putFloat(unknown1); } - - /** - * @return the pad1 - */ - public int getPad1() { - return pad1; - } - - /** - * @param pad1 the pad1 to set - */ - public void setPad1(int pad1) { - this.pad1 = pad1; - } - /** * @return the itemBase */ @@ -138,34 +125,6 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { return objectUUID; } - /** - * @return the slotNumber - */ - public int getSlotNumber() { - return slotNumber; - } - - /** - * @param slotNumber the slotNumber to set - */ - public void setSlotNumber(int slotNumber) { - this.slotNumber = slotNumber; - } - - /** - * @return the pad2 - */ - public int getPad2() { - return pad2; - } - - /** - * @param pad2 the pad2 to set - */ - public void setPad2(int pad2) { - this.pad2 = pad2; - } - /** * @return the unknown1 */ @@ -180,20 +139,6 @@ public class TransferItemFromInventoryToEquipMsg extends ClientNetMsg { this.unknown1 = unknown1; } - /** - * @return the unknown2 - */ - public float getUnknown2() { - return unknown2; - } - - /** - * @param unknown2 the unknown2 to set - */ - public void setUnknown2(float unknown2) { - this.unknown2 = unknown2; - } - public int getSourceType() { return sourceType; } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index c1907db8..db58211b 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -1750,7 +1750,7 @@ public class CharacterItemManager { return equipped.containsValue(i); } - public synchronized Item getItemFromEquipped(int slot) { + public synchronized Item getItemFromEquipped(Enum.EquipSlotType slot) { return equipped.get(slot); } @@ -1865,7 +1865,7 @@ public class CharacterItemManager { } if (!ItemTemplate.validForSkills(item, pc.getSkills())) { - this.forceToInventory(slot.ordinal(), item, pc, initialized); + this.forceToInventory(slot, item, pc, initialized); pc.applyBonuses(); } } @@ -2266,13 +2266,13 @@ public class CharacterItemManager { } - public void forceToInventory(int slot, Item item, PlayerCharacter pc, boolean initialized) { - if (item == null || pc == null) + public void forceToInventory(Enum.EquipSlotType slot, Item item, PlayerCharacter player, boolean initialized) { + + if (item == null || player == null) return; - if (!item.moveItemToInventory(pc)) { - //TODO well why did this fail? clean it up - } + if (!item.moveItemToInventory(player)) + Logger.error("templateL " + item.template.template_id); // remove it from other lists: this.remItemFromLists(item); @@ -2284,9 +2284,10 @@ public class CharacterItemManager { calculateWeights(); //Update players with unequipped item + if (initialized) { - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(pc, slot); - DispatchMessage.dispatchMsgToInterestArea(pc, back, engine.Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(player, slot); + DispatchMessage.dispatchMsgToInterestArea(player, back, engine.Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); } } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 19bbb5d8..02d59a3e 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -74,7 +74,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { private int currentID; private long lastAttackTime = 0; private int lastMobPowerToken = 0; - public HashMap equip = null; + public HashMap equip = null; private DeferredPowerJob weaponPower; private DateTime upgradeDateTime = null; private boolean lootSync = false; @@ -1218,7 +1218,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { // calculate defense for equipment } - private float getWeaponDefense(HashMap equipped) { + private float getWeaponDefense(HashMap equipped) { MobEquipment weapon = equipped.get(EquipSlotType.RHELD); ItemBase wb = null; @@ -1836,7 +1836,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { this.lootSync = lootSync; } - public HashMap getEquip() { + public HashMap getEquip() { return equip; } diff --git a/src/engine/objects/MobBase.java b/src/engine/objects/MobBase.java index b2b7da3b..32ec8149 100644 --- a/src/engine/objects/MobBase.java +++ b/src/engine/objects/MobBase.java @@ -110,10 +110,10 @@ public class MobBase extends AbstractGameObject { } - public static HashMap loadEquipmentSet(int equipmentSetID) { + public static HashMap loadEquipmentSet(int equipmentSetID) { ArrayList equipList; - HashMap equip = new HashMap<>(); + HashMap equip = new HashMap<>(); if (equipmentSetID == 0) return equip; @@ -128,13 +128,12 @@ public class MobBase extends AbstractGameObject { MobEquipment mobEquipment = new MobEquipment(equipmentSetEntry.itemBase, equipmentSetEntry.dropChance); ItemBase itemBase = mobEquipment.getItemBase(); - if (itemBase != null) { - if (itemBase.getType().equals(Enum.ItemType.WEAPON)) - if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2) - mobEquipment.setSlot(2); + // if (itemBase.getType().equals(Enum.ItemType.WEAPON)) + // if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2) + // mobEquipment.setSlot(2); + + equip.put(mobEquipment.slot, mobEquipment); - equip.put(mobEquipment.getSlot(), mobEquipment); - } } return equip; diff --git a/src/engine/objects/MobEquipment.java b/src/engine/objects/MobEquipment.java index 87d4089e..098e206c 100644 --- a/src/engine/objects/MobEquipment.java +++ b/src/engine/objects/MobEquipment.java @@ -22,7 +22,7 @@ public class MobEquipment extends AbstractGameObject { private static AtomicInteger equipCounter = new AtomicInteger(0); private final ItemBase itemBase; - private int slot; + public Enum.EquipSlotType slot; private int parentID; //effects @@ -41,7 +41,7 @@ public class MobEquipment extends AbstractGameObject { /** * No Id Constructor */ - public MobEquipment(ItemBase itemBase, int slot, int parentID) { + public MobEquipment(ItemBase itemBase, Enum.EquipSlotType slot, int parentID) { super(MobEquipment.getNewID()); this.itemBase = itemBase; this.templateID = this.itemBase.getUUID(); @@ -62,7 +62,8 @@ public class MobEquipment extends AbstractGameObject { this.template = ItemTemplate.itemTemplates.get(itemBaseID); Enum.EquipSlotType equipSlot = template.item_eq_slots_and.iterator().next(); - this.slot = equipSlot.ordinal(); + + this.slot = equipSlot; this.dropChance = dropChance; this.parentID = 0; @@ -86,7 +87,7 @@ public class MobEquipment extends AbstractGameObject { public static void _serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer, boolean useSlot) throws SerializationException { if (useSlot) - writer.putInt(mobEquipment.slot); + writer.putInt(mobEquipment.slot.ordinal()); writer.putInt(0); // Pad writer.putInt(mobEquipment.itemBase.getUUID()); writer.putInt(mobEquipment.getObjectType().ordinal()); @@ -209,15 +210,6 @@ public class MobEquipment extends AbstractGameObject { public ItemBase getItemBase() { return itemBase; } - - public int getSlot() { - return this.slot; - } - - public void setSlot(int value) { - this.slot = value; - } - public final void setMagicValue() { float value = 1; if (itemBase != null) diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index c54d5925..b2786275 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -52,7 +52,7 @@ public class NPC extends AbstractCharacter { private final ArrayList rolling = new ArrayList<>(); public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); public ArrayList forgedItems = new ArrayList<>(); - public HashMap equip = null; + public HashMap equip = null; public int runeSetID = 0; public int extraRune2 = 0; protected int loadID; @@ -1265,7 +1265,7 @@ public class NPC extends AbstractCharacter { return true; } - public HashMap getEquip() { + public HashMap getEquip() { return equip; }