From 0590ae64e72ae36d3c21906bd858072a6f4cf9d0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 18 Mar 2024 09:38:33 -0400 Subject: [PATCH] Start mobequip refactor --- src/engine/Enum.java | 1 - src/engine/db/handlers/dbContractHandler.java | 4 +- src/engine/devcmd/cmds/PrintEffectsCmd.java | 4 +- src/engine/devcmd/cmds/PrintEquipCmd.java | 4 +- src/engine/devcmd/cmds/PrintRunesCmd.java | 4 +- src/engine/devcmd/cmds/PrintStatsCmd.java | 2 +- src/engine/devcmd/cmds/SimulateBootyCmd.java | 2 +- src/engine/gameManager/LootManager.java | 2 +- src/engine/gameManager/NPCManager.java | 8 +- src/engine/net/client/ClientMessagePump.java | 2 +- .../client/handlers/BuyFromNPCMsgHandler.java | 6 +- .../net/client/msg/BuyFromNPCWindowMsg.java | 6 +- src/engine/net/client/msg/LootMsg.java | 30 +- src/engine/objects/AbstractCharacter.java | 8 +- src/engine/objects/CharacterItemManager.java | 4 +- src/engine/objects/Contract.java | 4 +- src/engine/objects/Mob.java | 80 ++--- src/engine/objects/MobBase.java | 15 +- src/engine/objects/MobEquipment.java | 320 ------------------ src/engine/objects/NPC.java | 8 +- 20 files changed, 79 insertions(+), 435 deletions(-) delete mode 100644 src/engine/objects/MobEquipment.java diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 5acc0a7c..393343f5 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -1648,7 +1648,6 @@ public class Enum { Mine, Mob, MobBase, - MobEquipment, MobLoot, MobType, NPC, diff --git a/src/engine/db/handlers/dbContractHandler.java b/src/engine/db/handlers/dbContractHandler.java index 314fe0be..0b5e728e 100644 --- a/src/engine/db/handlers/dbContractHandler.java +++ b/src/engine/db/handlers/dbContractHandler.java @@ -13,7 +13,7 @@ import engine.Enum; import engine.gameManager.DbManager; import engine.objects.Contract; import engine.objects.ItemTemplate; -import engine.objects.MobEquipment; +import engine.objects.Item; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -65,7 +65,7 @@ public class dbContractHandler extends dbHandlerBase { int templateID = rs.getInt("itembaseID"); - MobEquipment me = new MobEquipment(ItemTemplate.templates.get(templateID), Enum.EquipSlotType.NONE, 0); + Item me = new Item(ItemTemplate.templates.get(templateID), Enum.EquipSlotType.NONE, 0); contract.getSellInventory().add(me); //handle magic effects diff --git a/src/engine/devcmd/cmds/PrintEffectsCmd.java b/src/engine/devcmd/cmds/PrintEffectsCmd.java index 6f810012..23e19055 100644 --- a/src/engine/devcmd/cmds/PrintEffectsCmd.java +++ b/src/engine/devcmd/cmds/PrintEffectsCmd.java @@ -25,9 +25,9 @@ public class PrintEffectsCmd 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); + Item item = equip.get(slot); if (item != null && item.getItemBase() != null) { return item.getItemBase(); } diff --git a/src/engine/devcmd/cmds/PrintEquipCmd.java b/src/engine/devcmd/cmds/PrintEquipCmd.java index d78d67f3..13c23b63 100644 --- a/src/engine/devcmd/cmds/PrintEquipCmd.java +++ b/src/engine/devcmd/cmds/PrintEquipCmd.java @@ -65,7 +65,7 @@ public class PrintEquipCmd extends AbstractDevCmd { Mob tarMob = (Mob) tar; throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) { - MobEquipment equip = tarMob.getEquip().get(slot); + Item equip = tarMob.getEquip().get(slot); throwbackInfo(pc, equip.templateID + " : " + equip.template.item_base_name + ", slot: " + slot); } return; @@ -75,7 +75,7 @@ public class PrintEquipCmd extends AbstractDevCmd { NPC tarMob = (NPC) tar; throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) { - MobEquipment equip = tarMob.getEquip().get(slot); + Item equip = tarMob.getEquip().get(slot); throwbackInfo(pc, equip.templateID + " : " + equip.template.item_base_name + ", slot: " + slot); } return; diff --git a/src/engine/devcmd/cmds/PrintRunesCmd.java b/src/engine/devcmd/cmds/PrintRunesCmd.java index 45b19d44..ff66417a 100644 --- a/src/engine/devcmd/cmds/PrintRunesCmd.java +++ b/src/engine/devcmd/cmds/PrintRunesCmd.java @@ -25,9 +25,9 @@ public class PrintRunesCmd 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); + Item item = equip.get(slot); if (item != null && item.getItemBase() != null) { return item.getItemBase(); } diff --git a/src/engine/devcmd/cmds/PrintStatsCmd.java b/src/engine/devcmd/cmds/PrintStatsCmd.java index ee9be1af..57daa93f 100644 --- a/src/engine/devcmd/cmds/PrintStatsCmd.java +++ b/src/engine/devcmd/cmds/PrintStatsCmd.java @@ -86,7 +86,7 @@ public class PrintStatsCmd extends AbstractDevCmd { out += "Defense: " + tar.getDefenseRating() + newline; //get weapons - HashMap equip = tar.getEquip(); + HashMap equip = tar.getEquip(); if(equip != null){ if (equip.get(2) != null && !ItemTemplate.isShield(equip.get(2).template)) { diff --git a/src/engine/devcmd/cmds/SimulateBootyCmd.java b/src/engine/devcmd/cmds/SimulateBootyCmd.java index 92da5c49..c0ea143a 100644 --- a/src/engine/devcmd/cmds/SimulateBootyCmd.java +++ b/src/engine/devcmd/cmds/SimulateBootyCmd.java @@ -88,7 +88,7 @@ public class SimulateBootyCmd extends AbstractDevCmd { failures++; } if (mob.getEquip() != null) { - for (MobEquipment me : mob.getEquip().values()) { + for (Item me : mob.getEquip().values()) { if (me.getDropChance() == 0) continue; diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 49fa0e55..2f2bba44 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -337,7 +337,7 @@ public enum LootManager { //do equipment here int dropCount = 0; if (mob.getEquip() != null) - for (MobEquipment me : mob.getEquip().values()) { + for (Item me : mob.getEquip().values()) { if (me.getDropChance() == 0) continue; diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index 0a81708f..d3c353c4 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -300,7 +300,7 @@ public enum NPCManager { }else{ if (guard.equip.containsKey(Enum.EquipSlotType.RHELD)) { //has main hand weapon - MobEquipment weapon = guard.equip.get(Enum.EquipSlotType.RHELD); + Item weapon = guard.equip.get(Enum.EquipSlotType.RHELD); if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength)) primaryStat = guard.getStatStrCurrent(); @@ -313,7 +313,7 @@ public enum NPCManager { guard.rangeHandOne = weapon.template.item_weapon_max_range; } else if (guard.equip.containsKey(Enum.EquipSlotType.LHELD) && !ItemTemplate.isShield(guard.equip.get(Enum.EquipSlotType.LHELD).template)) { //has off hand weapon - MobEquipment weapon = guard.equip.get(Enum.EquipSlotType.LHELD); + Item weapon = guard.equip.get(Enum.EquipSlotType.LHELD); if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength)) primaryStat = guard.getStatStrCurrent(); else @@ -338,7 +338,7 @@ public enum NPCManager { dexterity = 1; int baseDef = guard.mobBase.getDefenseRating(); int armorDefense = 0; - for(MobEquipment equipped : guard.equip.values()) + for(Item equipped : guard.equip.values()) if (equipped.template.item_type.equals(Enum.ItemType.ARMOR) || ItemTemplate.isShield(equipped.template)) armorDefense += equipped.template.item_defense_rating; guard.defenseRating = dexterity + baseDef + armorDefense; @@ -427,7 +427,7 @@ public enum NPCManager { if (mob.equip == null) return; - for (MobEquipment equipped : mob.equip.values()) { + for (Item equipped : mob.equip.values()) { if (equipped.template.item_type.equals(Enum.ItemType.ARMOR)) { mob.resists.setResist(Enum.SourceType.SLASHING, mob.resists.getResist(Enum.SourceType.SLASHING, 0) + equipped.template.combat_attack_resist.get("SLASHING")); mob.resists.setResist(Enum.SourceType.CRUSHING, mob.resists.getResist(Enum.SourceType.CRUSHING, 0) + equipped.template.combat_attack_resist.get("CRUSHING")); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 6b4208b1..de21f2c0 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -699,7 +699,7 @@ public class ClientMessagePump implements NetMsgHandler { if (item != null && item.getObjectType() == GameObjectType.MobLoot) { - for (MobEquipment equip : mobTarget.getEquip().values()) { + for (Item equip : mobTarget.getEquip().values()) { TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.slot); DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); diff --git a/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java index f572f587..ee1e3bb0 100644 --- a/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java +++ b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java @@ -63,14 +63,14 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler { Item buy = null; - if (buyFromNPCMsg.getItemType() == Enum.GameObjectType.MobEquipment.ordinal()) { + if (buyFromNPCMsg.getItemType() == Enum.GameObjectType.Item.ordinal()) { - ArrayList sellInventory = npc.getContract().getSellInventory(); + ArrayList sellInventory = npc.getContract().getSellInventory(); if (sellInventory == null) return true; - for (MobEquipment me : sellInventory) { + for (Item me : sellInventory) { if (me.getObjectUUID() == buyFromNPCMsg.getItemID()) { diff --git a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java index d41619f1..c74c41a9 100644 --- a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java +++ b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java @@ -94,7 +94,7 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { NPC npc = NPC.getFromCache(npcID); CharacterItemManager man = null; ArrayList inventory = null; - ArrayList sellInventory = null; + ArrayList sellInventory = null; if (npc != null) { man = npc.getCharItemManager(); @@ -147,9 +147,9 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { //add generic sell inventory from contract if (sellInventory != null) { - for (MobEquipment mobEquipment : sellInventory) { + for (Item Item : sellInventory) { try { - MobEquipment.serializeForVendor(mobEquipment, writer, sellPercent); + Item.serializeForVendor(Item, writer, sellPercent); } catch (SerializationException se) { continue; } diff --git a/src/engine/net/client/msg/LootMsg.java b/src/engine/net/client/msg/LootMsg.java index f2b8d355..537fc79b 100644 --- a/src/engine/net/client/msg/LootMsg.java +++ b/src/engine/net/client/msg/LootMsg.java @@ -16,7 +16,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; import engine.objects.Item; -import engine.objects.MobEquipment; +import engine.objects.Item; public class LootMsg extends ClientNetMsg { @@ -37,7 +37,7 @@ public class LootMsg extends ClientNetMsg { private int unknown07; private int unknown08; - private MobEquipment mobEquipment = null; + private Item Item = null; /** * This is the general purpose constructor. @@ -60,28 +60,6 @@ public class LootMsg extends ClientNetMsg { this.unknown08 = 0; } - //for MobEquipment - - public LootMsg(int sourceType, int sourceID, int targetType, int targetID, MobEquipment mobEquipment) { - super(Protocol.MOVEOBJECTTOCONTAINER); - this.sourceType1 = sourceType; - this.sourceID1 = sourceID; - this.targetType = targetType; - this.targetID = targetID; - this.sourceType2 = sourceType; - this.sourceID2 = sourceID; - this.item = null; - this.mobEquipment = mobEquipment; - - this.unknown01 = 0; - this.unknown02 = 0; - this.unknown03 = 0; - this.unknown04 = 0; - this.unknown05 = 0; - this.unknown07 = 0; - this.unknown08 = 0; - } - /** * This constructor is used by NetMsgFactory. It attempts to deserialize the * ByteBuffer into a message. If a BufferUnderflow occurs (based on reading @@ -100,9 +78,9 @@ public class LootMsg extends ClientNetMsg { if (this.item != null) Item.serializeForClientMsgWithoutSlot(this.item, writer); - else if (this.mobEquipment != null) + else if (this.Item != null) try { - MobEquipment._serializeForClientMsg(this.mobEquipment, writer, false); + Item._serializeForClientMsg(this.Item, writer, false); } catch (SerializationException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index e3394984..f19da53a 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -990,10 +990,10 @@ public abstract class AbstractCharacter extends AbstractWorldObject { return 300; } float range = 8; - if (((Mob) this).getEquip().get(1) != null) { - range = ((Mob) this).getEquip().get(1).template.item_weapon_max_range; - } else if (((Mob) this).getEquip().get(2) != null) { - range = ((Mob) this).getEquip().get(2).template.item_weapon_max_range; + if (( this).charItemManager.equipped.get(EquipSlotType.RHELD) != null) { + range = ((Mob) this).charItemManager.equipped.get(EquipSlotType.RHELD).template.item_weapon_max_range; + } else if (((Mob) this).charItemManager.equipped.get(EquipSlotType.LHELD) != null) { + range = ((Mob) this).charItemManager.equipped.get(EquipSlotType.LHELD).template.item_weapon_max_range; } // TODO Is this clamp from live? diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 6a86ea43..7ed53da8 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -43,7 +43,7 @@ public class CharacterItemManager { private final ConcurrentHashMap itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); // Mapping of all items equipped in this Manager // Key = Item Slot - public final ConcurrentHashMap equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public ConcurrentHashMap equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private final HashSet inventory = new HashSet<>(); private final HashSet bank = new HashSet<>(); private final HashSet vault = new HashSet<>(); @@ -1203,7 +1203,7 @@ public class CharacterItemManager { return true; } - //Used for buying MobEquipment from NPC + //Used for buying Item from NPC //Handles the gold transfer aspect // This removes ingame item from inventory for loot. diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index 076e8525..bddaa620 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -35,7 +35,7 @@ public class Contract extends AbstractGameObject { private ArrayList npcModTypeTable = new ArrayList<>(); private ArrayList npcModSuffixTable = new ArrayList<>(); private ArrayList itemModTable = new ArrayList<>(); - private ArrayList sellInventory = new ArrayList<>(); + private ArrayList sellInventory = new ArrayList<>(); private EnumBitSet allowedBuildings; private ArrayList buyItemType = new ArrayList<>(); private ArrayList buySkillToken = new ArrayList<>(); @@ -197,7 +197,7 @@ public class Contract extends AbstractGameObject { return itemModTable; } - public ArrayList getSellInventory() { + public ArrayList getSellInventory() { return this.sellInventory; } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 055b56f7..d6687bbe 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -74,7 +74,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { private int currentID; private long lastAttackTime = 0; private int lastMobPowerToken = 0; - public HashMap equip = null; private DeferredPowerJob weaponPower; private DateTime upgradeDateTime = null; private boolean lootSync = false; @@ -257,12 +256,12 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { // get a copy of the equipped items. - if (mob.equip != null) { + if (!mob.charItemManager.equipped.isEmpty()) { - writer.putInt(mob.equip.size()); + writer.putInt(mob.charItemManager.equipped.size()); - for (MobEquipment me : mob.equip.values()) - MobEquipment.serializeForClientMsg(me, writer); + for (Item me : mob.charItemManager.equipped.values()) + Item._serializeForClientMsg(me, writer); } else writer.putInt(0); @@ -934,7 +933,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { playerAgroMap.clear(); - if (!this.isPlayerGuard() && this.equip != null) + if (!this.isPlayerGuard() && this.charItemManager.equipped != null) LootManager.GenerateEquipmentDrop(this); } @@ -1122,7 +1121,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { public void calculateAtrDefenseDamage() { - if (this.charItemManager == null || this.equip == null) { + if (this.charItemManager == null || this.charItemManager.equipped == null) { Logger.error("Player " + currentID + " missing skills or equipment"); defaultAtrAndDamage(true); defaultAtrAndDamage(false); @@ -1141,16 +1140,16 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { this.rangeHandTwo = 6.5f; this.speedHandTwo = 20; - if (this.equip.get(EquipSlotType.RHELD) != null) - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), true); //has mainhand weapon to calculate + if (this.charItemManager.equipped.get(EquipSlotType.RHELD) != null) + calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), true); //has mainhand weapon to calculate - if (this.equip.get(EquipSlotType.LHELD) != null && !ItemTemplate.isShield(this.equip.get(EquipSlotType.LHELD).template)) - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), false); //has offhand weapon to calculate + if (this.charItemManager.equipped.get(EquipSlotType.LHELD) != null && !ItemTemplate.isShield(this.charItemManager.equipped.get(EquipSlotType.LHELD).template)) + calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false); //has offhand weapon to calculate try { - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.RHELD), true); + calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.RHELD), true); } catch (Exception e) { this.atrHandOne = (short) this.mobBase.getAttackRating(); @@ -1162,7 +1161,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { } try { - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), false); + calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false); } catch (Exception e) { @@ -1176,14 +1175,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { try { float defense = this.mobBase.getDefenseRating(); - defense += getShieldDefense(equip.get(EquipSlotType.LHELD)); - defense += getArmorDefense(equip.get(EquipSlotType.HELM)); - defense += getArmorDefense(equip.get(EquipSlotType.CHEST)); - defense += getArmorDefense(equip.get(EquipSlotType.UPARM)); - defense += getArmorDefense(equip.get(EquipSlotType.HANDS)); - defense += getArmorDefense(equip.get(EquipSlotType.LEGS)); - defense += getArmorDefense(equip.get(EquipSlotType.FEET)); - defense += getWeaponDefense(equip); + defense += getShieldDefense(charItemManager.equipped.get(EquipSlotType.LHELD)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HELM)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.CHEST)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.UPARM)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HANDS)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.LEGS)); + defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.FEET)); + defense += getWeaponDefense(charItemManager.equipped); // TODO add error log here if (this.bonuses != null) { @@ -1217,9 +1216,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { // calculate defense for equipment } - private float getWeaponDefense(HashMap equipped) { + private float getWeaponDefense(ConcurrentHashMap equipped) { - MobEquipment weapon = equipped.get(EquipSlotType.RHELD); + Item weapon = equipped.get(EquipSlotType.RHELD); ItemBase wb = null; CharacterSkill skill, mastery; float val = 0; @@ -1256,7 +1255,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { return val; } - private float getShieldDefense(MobEquipment shield) { + private float getShieldDefense(Item shield) { if (shield == null) return 0; @@ -1285,7 +1284,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { return (def * (1 + ((int) skillMod / 100f))); } - private float getArmorDefense(MobEquipment armor) { + private float getArmorDefense(Item armor) { if (armor == null) return 0; @@ -1313,7 +1312,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { return (def * (1 + ((int) armorSkill.getModifiedAmount() / 50f))); } - private void calculateAtrDamageForWeapon(MobEquipment weapon, boolean mainHand) { + private void calculateAtrDamageForWeapon(Item weapon, boolean mainHand) { int baseStrength = 0; @@ -1501,13 +1500,13 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { public ItemBase getWeaponItemBase(boolean mainHand) { if (this.equipmentSetID != 0) - if (equip != null) { - MobEquipment me; + if (charItemManager.equipped != null) { + Item me; if (mainHand) - me = equip.get(1); //mainHand + me = charItemManager.equipped.get(EquipSlotType.RHELD); //mainHand else - me = equip.get(2); //offHand + me = charItemManager.equipped.get(EquipSlotType.LHELD); //offHand if (me != null) { @@ -1521,14 +1520,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { MobBase mb = this.mobBase; if (mb != null) - if (equip != null) { + if (this.charItemManager.equipped.isEmpty() == false) { - MobEquipment me; + Item me; if (mainHand) - me = equip.get(1); //mainHand + me = this.charItemManager.equipped.get(EquipSlotType.RHELD); //mainHand else - me = equip.get(2); //offHand + me = this.charItemManager.equipped.get(EquipSlotType.LHELD); //offHand if (me != null) return me.getItemBase(); @@ -1670,14 +1669,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { this.loadInventory(); if (this.equipmentSetID != 0) - this.equip = MobBase.loadEquipmentSet(this.equipmentSetID); + this.charItemManager.equipped = MobBase.loadEquipmentSet(this.equipmentSetID); else - this.equip = new HashMap<>(); - - if (this.equip == null) { - Logger.error("Null equipset returned for uuid " + currentID); - this.equip = new HashMap<>(0); - } + this.charItemManager.equipped = new ConcurrentHashMap<>(); // Combine mobbase and mob aggro arrays into one bitvector //skip for pets @@ -1835,10 +1829,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { this.lootSync = lootSync; } - public HashMap getEquip() { - return equip; - } - public String getNameOverride() { return firstName + " " + lastName; } diff --git a/src/engine/objects/MobBase.java b/src/engine/objects/MobBase.java index 93d255e3..ea71ade8 100644 --- a/src/engine/objects/MobBase.java +++ b/src/engine/objects/MobBase.java @@ -20,6 +20,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; public class MobBase extends AbstractGameObject { @@ -110,10 +111,10 @@ public class MobBase extends AbstractGameObject { } - public static HashMap loadEquipmentSet(int equipmentSetID) { + public static ConcurrentHashMap loadEquipmentSet(int equipmentSetID) { ArrayList equipList; - HashMap equip = new HashMap<>(); + ConcurrentHashMap equip = new ConcurrentHashMap<>(); if (equipmentSetID == 0) return equip; @@ -125,14 +126,10 @@ public class MobBase extends AbstractGameObject { for (BootySetEntry equipmentSetEntry : equipList) { - MobEquipment mobEquipment = new MobEquipment(equipmentSetEntry.templateID, equipmentSetEntry.dropChance); - ItemBase itemBase = mobEquipment.getItemBase(); + Item item = new Item(equipmentSetEntry.templateID); + item.drop_chance = equipmentSetEntry.dropChance; - // if (itemBase.getType().equals(Enum.ItemType.WEAPON)) - // if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2) - // mobEquipment.setSlot(2); - - equip.put(mobEquipment.slot, mobEquipment); + equip.put(item.slot, Item); } diff --git a/src/engine/objects/MobEquipment.java b/src/engine/objects/MobEquipment.java deleted file mode 100644 index 07b7282d..00000000 --- a/src/engine/objects/MobEquipment.java +++ /dev/null @@ -1,320 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.objects; - -import engine.Enum; -import engine.exception.SerializationException; -import engine.gameManager.PowersManager; -import engine.net.ByteBufferWriter; -import engine.powers.EffectsBase; -import engine.powers.poweractions.AbstractPowerAction; - -import java.util.concurrent.atomic.AtomicInteger; - -public class MobEquipment extends AbstractGameObject { - - private static AtomicInteger equipCounter = new AtomicInteger(0); - private final ItemBase itemBase; - public Enum.EquipSlotType slot; - private int parentID; - - //effects - private boolean enchanted; - private boolean isID = false; - private AbstractPowerAction prefix; - private AbstractPowerAction suffix; - private int pValue; - private int sValue; - private int magicValue; - - private float dropChance = 0; - public int templateID; - public ItemTemplate template; - - /** - * No Id Constructor - */ - public MobEquipment(ItemTemplate template, Enum.EquipSlotType slot, int parentID) { - super(MobEquipment.getNewID()); - this.templateID = template.template_id; - this.template = ItemTemplate.templates.get(templateID); - this.itemBase = ItemBase.getItemBase(templateID); - this.slot = slot; - this.parentID = parentID; - this.enchanted = false; - this.prefix = null; - this.suffix = null; - this.pValue = 0; - this.sValue = 0; - setMagicValue(); - } - - public MobEquipment(int templateID, float dropChance) { - super(MobEquipment.getNewID()); - this.itemBase = ItemBase.getItemBase(templateID); - this.templateID = templateID; - this.template = ItemTemplate.templates.get(this.templateID); - - Enum.EquipSlotType equipSlot = template.item_eq_slots_or.iterator().next(); - - this.slot = equipSlot; - this.dropChance = dropChance; - - this.parentID = 0; - setMagicValue(); - } - - public static int getNewID() { - return MobEquipment.equipCounter.incrementAndGet(); - } - - public static void serializeForVendor(MobEquipment mobEquipment, ByteBufferWriter writer, float percent) throws SerializationException { - _serializeForClientMsg(mobEquipment, writer, false); - writer.putInt(mobEquipment.magicValue); - writer.putInt(mobEquipment.magicValue); - } - - public static void serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer) throws SerializationException { - _serializeForClientMsg(mobEquipment, writer, true); - } - - public static void _serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer, boolean useSlot) throws SerializationException { - - if (useSlot) - writer.putInt(mobEquipment.slot.ordinal()); - writer.putInt(0); // Pad - writer.putInt(mobEquipment.templateID); - writer.putInt(mobEquipment.getObjectType().ordinal()); - writer.putInt(mobEquipment.getObjectUUID()); - - // Unknown statics - for (int i = 0; i < 3; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 4; i++) { - writer.putInt(0x3F800000); // Static - } - for (int i = 0; i < 5; i++) { - writer.putInt(0); // Pad - } - for (int i = 0; i < 2; i++) { - writer.putInt(0xFFFFFFFF); // Static - } - - writer.putInt(0); - - writer.put((byte) 1); // End Datablock byte - writer.putInt(0); // Unknown. pad? - writer.put((byte) 1); // End Datablock byte - - writer.putFloat(mobEquipment.template.item_health_full); - writer.putFloat(mobEquipment.template.item_health_full); - - writer.put((byte) 1); // End Datablock byte - - writer.putInt(0); // Pad - writer.putInt(0); // Pad - - writer.putInt(mobEquipment.template.item_value); - writer.putInt(mobEquipment.magicValue); - - serializeEffects(mobEquipment, writer); - - writer.putInt(0x00000000); - - //name color, think mobEquipment is where mobEquipment goes - if (mobEquipment.enchanted) - if (mobEquipment.isID) - writer.putInt(36); - else - writer.putInt(40); - else - writer.putInt(4); - - writer.putInt(0); - writer.putInt(0); // Pad - writer.putInt(1); - writer.putShort((short) 0); - writer.put((byte) 0); - } - - public static void serializeEffects(MobEquipment mobEquipment, ByteBufferWriter writer) { - - //skip sending effects if not IDed - if (!mobEquipment.isID) { - writer.putInt(0); - return; - } - - //handle effect count - int cnt = 0; - EffectsBase pre = null; - EffectsBase suf = null; - - if (mobEquipment.prefix != null) { - pre = PowersManager.getEffectByIDString(mobEquipment.prefix.getIDString()); - if (pre != null) - cnt++; - } - - if (mobEquipment.suffix != null) { - suf = PowersManager.getEffectByIDString(mobEquipment.suffix.getIDString()); - if (suf != null) - cnt++; - } - - writer.putInt(cnt); - - //serialize prefix - if (pre != null) - serializeEffect(mobEquipment, writer, pre, mobEquipment.pValue); - - //serialize suffix - if (suf != null) - serializeEffect(mobEquipment, writer, suf, mobEquipment.sValue); - } - - public static void serializeEffect(MobEquipment mobEquipment, ByteBufferWriter writer, EffectsBase eb, int rank) { - String name; - if (eb.isPrefix()) { - if (mobEquipment.itemBase == null) - name = eb.getName(); - else - name = eb.getName() + ' ' + ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name; - } else if (eb.isSuffix()) { - if (mobEquipment.itemBase == null) - name = eb.getName(); - else - name = ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name + ' ' + eb.getName(); - } else { - if (mobEquipment.itemBase == null) - name = ""; - else - name = ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name; - } - - writer.putInt(eb.getToken()); - writer.putInt(rank); - writer.putInt(1); - writer.put((byte) 1); - writer.putInt(mobEquipment.getObjectType().ordinal()); - writer.putInt(mobEquipment.getObjectUUID()); - writer.putString(name); - writer.putFloat(-1000f); - } - - public ItemBase getItemBase() { - return itemBase; - } - public final void setMagicValue() { - float value = 1; - if (itemBase != null) - value = template.item_value; - if (this.prefix != null) { - if (this.prefix.getEffectsBase() != null) - value += this.prefix.getEffectsBase().getValue(); - if (this.prefix.getEffectsBase2() != null) - value += this.prefix.getEffectsBase2().getValue(); - } - if (this.suffix != null) { - if (this.suffix.getEffectsBase() != null) - value += this.suffix.getEffectsBase().getValue(); - if (this.suffix.getEffectsBase2() != null) - value += this.suffix.getEffectsBase2().getValue(); - } - - if (itemBase != null) - - for (String effectID : this.template.item_user_power_action.keySet()) { - - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effectID); - - if (apa.getEffectsBase() != null) - if (apa.getEffectsBase().getValue() > 0) - value += apa.getEffectsBase().getValue(); - - if (apa.getEffectsBase2() != null) - value += apa.getEffectsBase2().getValue(); - } - - this.magicValue = (int) value; - } - - public int getMagicValue() { - - if (!this.isID) { - return template.item_value; - } - return this.magicValue; - } - - public void setPrefix(String pIDString, int pValue) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(pIDString); - if (apa != null) { - this.prefix = apa; - this.pValue = pValue; - } else - this.prefix = null; - - this.enchanted = this.prefix != null || this.suffix != null; - - setMagicValue(); - } - - public void setSuffix(String sIDString, int sValue) { - AbstractPowerAction apa = PowersManager.getPowerActionByIDString(sIDString); - if (apa != null) { - this.suffix = apa; - this.sValue = sValue; - } else - this.suffix = null; - - this.enchanted = this.prefix != null || this.suffix != null; - - setMagicValue(); - } - - public void setIsID(boolean value) { - this.isID = value; - } - - public boolean isID() { - return this.isID; - } - - public void transferEnchants(Item item) { - if (this.prefix != null) { - String IDString = this.prefix.getIDString(); - item.addPermanentEnchantment(IDString, this.pValue); - } - if (this.suffix != null) { - String IDString = this.suffix.getIDString(); - item.addPermanentEnchantment(IDString, this.sValue); - } - if (this.isID) - item.setIsID(true); - } - - /* - * Database - */ - @Override - public void updateDatabase() { - } - - - public float getDropChance() { - return dropChance; - } - - public void setDropChance(float dropChance) { - this.dropChance = dropChance; - } -} diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index e04515b0..7b0ba35d 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; @@ -344,8 +344,8 @@ public class NPC extends AbstractCharacter { if (npc.equip != null) { writer.putInt(npc.equip.size()); - for (MobEquipment me : npc.equip.values()) - MobEquipment.serializeForClientMsg(me, writer); + for (Item me : npc.equip.values()) + Item.serializeForClientMsg(me, writer); } else writer.putInt(0); @@ -1265,7 +1265,7 @@ public class NPC extends AbstractCharacter { return true; } - public HashMap getEquip() { + public HashMap getEquip() { return equip; }