From 8f7208ff34d85fbbacd3917881caed7196738db4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 18 Mar 2024 10:12:13 -0400 Subject: [PATCH] Start mobequip refactor --- src/engine/devcmd/cmds/PrintStatsCmd.java | 34 +++++++++---------- src/engine/devcmd/cmds/SimulateBootyCmd.java | 8 ++--- src/engine/gameManager/NPCManager.java | 30 ++++++++-------- .../client/handlers/BuyFromNPCMsgHandler.java | 2 +- .../net/client/msg/BuyFromNPCWindowMsg.java | 6 ++-- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/engine/devcmd/cmds/PrintStatsCmd.java b/src/engine/devcmd/cmds/PrintStatsCmd.java index 57daa93f..1cdc06ca 100644 --- a/src/engine/devcmd/cmds/PrintStatsCmd.java +++ b/src/engine/devcmd/cmds/PrintStatsCmd.java @@ -13,8 +13,6 @@ import engine.Enum; import engine.devcmd.AbstractDevCmd; import engine.objects.*; -import java.util.HashMap; - /** * */ @@ -66,11 +64,12 @@ public class PrintStatsCmd extends AbstractDevCmd { } public void printStatsMob(PlayerCharacter pc, Mob tar) { + MobBase mb = tar.getMobBase(); + if (mb == null) return; - String newline = "\r\n "; String out = "Server stats for Mob " + mb.getFirstName() + newline; out += "Stats Base (Modified)" + newline; @@ -86,22 +85,21 @@ public class PrintStatsCmd extends AbstractDevCmd { out += "Defense: " + tar.getDefenseRating() + newline; //get weapons - HashMap equip = tar.getEquip(); - - if(equip != null){ - if (equip.get(2) != null && !ItemTemplate.isShield(equip.get(2).template)) { - //off hand weapon - out += "Attack Rating: " + tar.atrHandTwo + newline; - out += "Damage: " + tar.minDamageHandTwo + " - " + tar.maxDamageHandTwo + newline; - out += "Range: " + tar.rangeHandTwo + newline; - out += "Attack Speed: " + tar.speedHandTwo + newline; - } else { - out += "Attack Rating: " + tar.atrHandOne + newline; - out += "Damage: " + tar.minDamageHandOne + " - " + tar.maxDamageHandOne + newline; - out += "Range: " + tar.rangeHandOne + newline; - out += "Attack Speed: " + tar.speedHandOne + newline; + + if (tar.charItemManager.equipped.isEmpty() == false) + if (tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemTemplate.isShield(tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD))) { + //off hand weapon + out += "Attack Rating: " + tar.atrHandTwo + newline; + out += "Damage: " + tar.minDamageHandTwo + " - " + tar.maxDamageHandTwo + newline; + out += "Range: " + tar.rangeHandTwo + newline; + out += "Attack Speed: " + tar.speedHandTwo + newline; + } else { + out += "Attack Rating: " + tar.atrHandOne + newline; + out += "Damage: " + tar.minDamageHandOne + " - " + tar.maxDamageHandOne + newline; + out += "Range: " + tar.rangeHandOne + newline; + out += "Attack Speed: " + tar.speedHandOne + newline; } - } + out += "isAlive: " + tar.isAlive() + ", Combat: " + tar.isCombat() + newline; throwbackInfo(pc, out); diff --git a/src/engine/devcmd/cmds/SimulateBootyCmd.java b/src/engine/devcmd/cmds/SimulateBootyCmd.java index dc4817a2..a91990b2 100644 --- a/src/engine/devcmd/cmds/SimulateBootyCmd.java +++ b/src/engine/devcmd/cmds/SimulateBootyCmd.java @@ -87,14 +87,14 @@ public class SimulateBootyCmd extends AbstractDevCmd { } catch (Exception ex) { failures++; } - if (mob.getEquip() != null) { - for (Item me : mob.getEquip().values()) { + if (mob.charItemManager.equipped.isEmpty() == false) { + for (Item me : mob.charItemManager.equipped.values()) { - if (me.getDropChance() == 0) + if (me.drop_chance == 0) continue; float equipmentRoll = ThreadLocalRandom.current().nextInt(99) + 1; - float dropChance = me.getDropChance() * 100; + float dropChance = me.drop_chance * 100; if (equipmentRoll > (dropChance)) continue; diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index d3c353c4..306bc7a7 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -293,14 +293,14 @@ public enum NPCManager { float rankModifier = 1 + (guard.getRank() * 0.1f); int primaryStat = 0; - if(guard.equip == null) { - guard.minDamageHandOne = (int)((guard.mobBase.getDamageMin()) * rankModifier); - guard.maxDamageHandOne = (int)((guard.mobBase.getDamageMax()) * rankModifier); + if (guard.charItemManager.equipped.isEmpty()) { + guard.minDamageHandOne = (int) ((guard.mobBase.getDamageMin()) * rankModifier); + guard.maxDamageHandOne = (int) ((guard.mobBase.getDamageMax()) * rankModifier); guard.speedHandOne = 30.0f; - }else{ - if (guard.equip.containsKey(Enum.EquipSlotType.RHELD)) { + } else { + if (guard.charItemManager.equipped.containsKey(Enum.EquipSlotType.RHELD)) { //has main hand weapon - Item weapon = guard.equip.get(Enum.EquipSlotType.RHELD); + Item weapon = guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD); if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength)) primaryStat = guard.getStatStrCurrent(); @@ -311,9 +311,9 @@ public enum NPCManager { guard.maxDamageHandOne = (int) ((guard.mobBase.getDamageMax() + weapon.template.item_weapon_damage.values().iterator().next()[1]) * rankModifier) + primaryStat; guard.speedHandOne = weapon.template.item_weapon_wepspeed; 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)) { + } else if (guard.charItemManager.equipped.containsKey(Enum.EquipSlotType.LHELD) && !ItemTemplate.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template)) { //has off hand weapon - Item weapon = guard.equip.get(Enum.EquipSlotType.LHELD); + Item weapon = guard.charItemManager.equipped.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(Item equipped : guard.equip.values()) + for (Item equipped : guard.charItemManager.equipped.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; @@ -347,10 +347,10 @@ public enum NPCManager { public static void setAttackRatingForGuard(Mob guard) { int strength = guard.getStatStrCurrent(); int baseAtr = guard.mobBase.getAttackRating(); - if (guard.equip.get(1) != null) - guard.atrHandOne = baseAtr + (int) ((strength * 0.5f) + (guard.equip.get(Enum.EquipSlotType.RHELD).getItemBase().getPercentRequired() * 4) + (guard.equip.get(Enum.EquipSlotType.RHELD).getItemBase().getPercentRequired() * 3)); - else if (guard.equip.get(2) != null && !ItemTemplate.isShield(guard.equip.get(Enum.EquipSlotType.LHELD).template)) - guard.atrHandTwo = baseAtr + (int) ((strength * 0.5f) + (guard.equip.get(Enum.EquipSlotType.LHELD).getItemBase().getPercentRequired() * 4) + (guard.equip.get(Enum.EquipSlotType.LHELD).getItemBase().getPercentRequired() * 3)); + if (guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD) != null) + guard.atrHandOne = baseAtr + (int) ((strength * 0.5f) + (guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).getItemBase().getPercentRequired() * 4) + (guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).getItemBase().getPercentRequired() * 3)); + else if (guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemTemplate.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template)) + guard.atrHandTwo = baseAtr + (int) ((strength * 0.5f) + (guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).getItemBase().getPercentRequired() * 4) + (guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).getItemBase().getPercentRequired() * 3)); else guard.atrHandOne = baseAtr; } @@ -424,10 +424,10 @@ public enum NPCManager { public static void applyEquipmentResists(Mob mob){ - if (mob.equip == null) + if (mob.charItemManager.equipped.isEmpty()) return; - for (Item equipped : mob.equip.values()) { + for (Item equipped : mob.charItemManager.equipped.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/handlers/BuyFromNPCMsgHandler.java b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java index 4f3ed69f..44f2e724 100644 --- a/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java +++ b/src/engine/net/client/handlers/BuyFromNPCMsgHandler.java @@ -115,7 +115,7 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler { buy = Item.createItemForPlayer(sourcePlayer, me.templateID); if (buy != null) { - me.transferEnchants(buy); + // me.transferEnchants(buy); itemMan.addItemToInventory(buy); //itemMan.updateInventory(); } diff --git a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java index 528ffdd2..b0dce671 100644 --- a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java +++ b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java @@ -147,10 +147,10 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { //add generic sell inventory from contract if (sellInventory != null) { - for (Item Item : sellInventory) { + for (Item item : sellInventory) { try { - Item._serializeForVendor(Item, writer, sellPercent); - } catch (SerializationException se) { + Item.serializeForClientMsgForVendor(item, writer, sellPercent); + } catch (Exception se) { continue; } ++total;