From 6f028ab8c83317859ec0ff980a6334889141b2c0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 9 Mar 2024 11:26:19 -0500 Subject: [PATCH] Refactored isShield and removed equipflag. --- src/engine/devcmd/cmds/PrintStatsCmd.java | 12 ++++----- src/engine/gameManager/CombatManager.java | 2 +- src/engine/gameManager/NPCManager.java | 18 ++++++------- .../mobileAI/utilities/CombatUtilities.java | 12 +++++---- src/engine/objects/CharacterItemManager.java | 3 +-- src/engine/objects/ItemBase.java | 26 +------------------ src/engine/objects/ItemTemplate.java | 18 +++++++++++++ src/engine/objects/Mob.java | 17 ++++++------ src/engine/objects/PlayerCharacter.java | 16 +++++++++--- 9 files changed, 64 insertions(+), 60 deletions(-) diff --git a/src/engine/devcmd/cmds/PrintStatsCmd.java b/src/engine/devcmd/cmds/PrintStatsCmd.java index 0b2d5173..99244857 100644 --- a/src/engine/devcmd/cmds/PrintStatsCmd.java +++ b/src/engine/devcmd/cmds/PrintStatsCmd.java @@ -105,13 +105,13 @@ public class PrintStatsCmd extends AbstractDevCmd { ItemBase off = null; if(equip != null){ - if(equip.get(2) != null && !equip.get(2).getItemBase().isShield()){ - //off hand weapon - out += "Attack Rating: " + tar.atrHandTwo + newline; - out += "Damage: " + tar.minDamageHandTwo + " - " + tar.maxDamageHandTwo + newline; - out += "Range: " + tar.rangeHandTwo + newline; + 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{ + } else { out += "Attack Rating: " + tar.atrHandOne + newline; out += "Damage: " + tar.minDamageHandOne + " - " + tar.maxDamageHandOne + newline; out += "Range: " + tar.rangeHandOne + newline; diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 609b12e3..12776431 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -891,7 +891,7 @@ public enum CombatManager { if (tarOff == null) return false; - return tarOff.getItemBase().isShield() != false; + return ItemTemplate.isShield((tarOff)); } private static boolean isRanged(Item item) { diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index b97e9b33..21c19ebe 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -301,23 +301,23 @@ public enum NPCManager { if(guard.equip.containsKey(1)){ //has main hand weapon ItemBase weapon = guard.equip.get(1).getItemBase(); - if(weapon.isStrBased()) + if (weapon.isStrBased()) primaryStat = guard.getStatStrCurrent(); else primaryStat = guard.getStatDexCurrent(); - guard.minDamageHandOne = (int)((guard.mobBase.getDamageMin() + weapon.getMinDamage()) * rankModifier) + primaryStat; - guard.maxDamageHandOne = (int)((guard.mobBase.getDamageMax() + weapon.getMaxDamage()) * rankModifier) + primaryStat; + guard.minDamageHandOne = (int) ((guard.mobBase.getDamageMin() + weapon.getMinDamage()) * rankModifier) + primaryStat; + guard.maxDamageHandOne = (int) ((guard.mobBase.getDamageMax() + weapon.getMaxDamage()) * rankModifier) + primaryStat; guard.speedHandOne = weapon.getSpeed(); guard.rangeHandOne = weapon.getRange(); - } else if(guard.equip.containsKey(2) && !guard.equip.get(2).getItemBase().isShield()){ + } else if (guard.equip.containsKey(2) && !ItemTemplate.isShield(guard.equip.get(2).template)) { //has off hand weapon ItemBase weapon = guard.equip.get(2).getItemBase(); - if(weapon.isStrBased()) + if (weapon.isStrBased()) primaryStat = guard.getStatStrCurrent(); else primaryStat = guard.getStatDexCurrent(); - guard.minDamageHandTwo = (int)((guard.mobBase.getDamageMin() + weapon.getMinDamage()) * rankModifier) + primaryStat; - guard.maxDamageHandTwo = (int)((guard.mobBase.getDamageMax() + weapon.getMaxDamage()) * rankModifier) + primaryStat; + guard.minDamageHandTwo = (int) ((guard.mobBase.getDamageMin() + weapon.getMinDamage()) * rankModifier) + primaryStat; + guard.maxDamageHandTwo = (int) ((guard.mobBase.getDamageMax() + weapon.getMaxDamage()) * rankModifier) + primaryStat; guard.speedHandTwo = weapon.getSpeed(); guard.rangeHandTwo = weapon.getRange(); } else { @@ -337,7 +337,7 @@ public enum NPCManager { int baseDef = guard.mobBase.getDefenseRating(); int armorDefense = 0; for(MobEquipment equipped : guard.equip.values()) - if(equipped.getItemBase().isArmor() || equipped.getItemBase().isShield()) + if (equipped.getItemBase().isArmor() || ItemTemplate.isShield(equipped.template)) armorDefense += equipped.getItemBase().getDefense(); guard.defenseRating = dexterity + baseDef + armorDefense; } @@ -347,7 +347,7 @@ public enum NPCManager { int baseAtr = guard.mobBase.getAttackRating(); if (guard.equip.get(1) != null) guard.atrHandOne = baseAtr + (int) ((strength * 0.5f) + (guard.equip.get(1).getItemBase().getPercentRequired() * 4) + (guard.equip.get(1).getItemBase().getPercentRequired() * 3)); - else if (guard.equip.get(2) != null && !guard.equip.get(2).getItemBase().isShield()) + else if (guard.equip.get(2) != null && !ItemTemplate.isShield(guard.equip.get(2).template)) guard.atrHandTwo = baseAtr + (int) ((strength * 0.5f) + (guard.equip.get(2).getItemBase().getPercentRequired() * 4) + (guard.equip.get(2).getItemBase().getPercentRequired() * 3)); else guard.atrHandOne = baseAtr; diff --git a/src/engine/mobileAI/utilities/CombatUtilities.java b/src/engine/mobileAI/utilities/CombatUtilities.java index 4ad8c012..0ee24bb7 100644 --- a/src/engine/mobileAI/utilities/CombatUtilities.java +++ b/src/engine/mobileAI/utilities/CombatUtilities.java @@ -334,22 +334,24 @@ public class CombatUtilities { if (agent.getEquip().get(1) != null) { return agent.getEquip().get(1).getItemBase().getDamageType(); } - if (agent.getEquip().get(2) != null && agent.getEquip().get(2).getItemBase().isShield() == false) { + if (agent.getEquip().get(2) != null && ItemTemplate.isShield(agent.getEquip().get(2).template) == false) { return agent.getEquip().get(2).getItemBase().getDamageType(); } return dt; } public static double getMinDmg(Mob agent) { - if(agent.equip.get(2) != null && !agent.equip.get(2).getItemBase().isShield()) + if (agent.equip.get(2) != null && !ItemTemplate.isShield(agent.equip.get(2).template)) return agent.minDamageHandTwo; - else return agent.minDamageHandOne; + else + return agent.minDamageHandOne; } public static double getMaxDmg(Mob agent) { - if(agent.equip.get(2) != null && !agent.equip.get(2).getItemBase().isShield()) + if (agent.equip.get(2) != null && !ItemTemplate.isShield(agent.equip.get(2).template)) return agent.maxDamageHandTwo; - else return agent.maxDamageHandOne; + else + return agent.maxDamageHandOne; } } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 421f6661..906ea23b 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -2491,8 +2491,7 @@ public class CharacterItemManager { if (this.equipped.containsKey(Enum.EquipSlotType.LHELD)) { Item item = this.equipped.get(Enum.EquipSlotType.LHELD); - ItemBase ib = item.getItemBase(); - if (ib.isShield()) + if (ItemTemplate.isShield(item)) armor.add(item); } diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 48b8561b..92167f6e 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -42,8 +42,8 @@ public class ItemBase { private final int useID; private int hashID; private final byte useAmount; + // Armor and weapon related values - private final int equipFlag; private final int restrictFlag; private final String skillRequired; private final short percentRequired; @@ -83,8 +83,6 @@ public class ItemBase { this.hashID = rs.getInt("itemHashID"); this.isConsumable = false; - - this.equipFlag = rs.getInt("equipFlag"); this.restrictFlag = rs.getInt("restrictFlag"); this.skillRequired = rs.getString("skillRequired"); this.percentRequired = rs.getShort("percentRequired"); @@ -228,16 +226,6 @@ public class ItemBase { return this.isConsumable; } - public int getEquipFlag() { - - if ((this.type == ItemType.ARMOR) - || (this.type == ItemType.WEAPON) - || (this.type == ItemType.JEWELRY)) - return this.equipFlag; - else - return 0; - } - public boolean isRune() { int ID = uuid; if (ID > 2499 && ID < 3050) //class, discipline runes @@ -442,18 +430,6 @@ public class ItemBase { return uuid; } - public boolean isRing() { - return ((this.equipFlag & (64 | 128 | 192)) != 0); - } - - public boolean isNecklace() { - return (this.equipFlag == 256); - } - - public boolean isShield() { - return this.type.equals(ItemType.ARMOR) && this.equipFlag == 2; - } - public boolean isLightArmor() { return this.skillRequired.equals("Wear Armor, Light"); } diff --git a/src/engine/objects/ItemTemplate.java b/src/engine/objects/ItemTemplate.java index 130124dc..f903f662 100644 --- a/src/engine/objects/ItemTemplate.java +++ b/src/engine/objects/ItemTemplate.java @@ -467,4 +467,22 @@ public class ItemTemplate { return false; } + + public static boolean isShield(Item item) { + + if (item.template.item_type.equals(Enum.ItemType.ARMOR) && + item.template.item_eq_slots_and.contains(Enum.EquipSlotType.LHELD)) + return true; + + return false; + } + + public static boolean isShield(ItemTemplate template) { + + if (template.item_type.equals(Enum.ItemType.ARMOR) && + template.item_eq_slots_and.contains(Enum.EquipSlotType.LHELD)) + return true; + + return false; + } } diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 02d59a3e..e60ce4e4 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1141,14 +1141,13 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { this.rangeHandTwo = 6.5f; this.speedHandTwo = 20; - if (this.equip.get(EquipSlotType.RHELD) != null) { - //has mainhand weapon to calculate - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), true); - } - if (this.equip.get(EquipSlotType.LHELD) != null && !this.equip.get(EquipSlotType.LHELD).getItemBase().isShield()) { - //has offhand weapon to calculate - calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), false); - } + if (this.equip.get(EquipSlotType.RHELD) != null) + calculateAtrDamageForWeapon(this.equip.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 + try { calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.RHELD), true); @@ -1264,7 +1263,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { ItemBase ab = shield.getItemBase(); - if (ab == null || !ab.isShield()) + if (!ItemTemplate.isShield(shield.template)) return 0; CharacterSkill blockSkill = this.skills.get("Block"); diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 318bf375..38e6ff2b 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -4088,19 +4088,29 @@ public class PlayerCharacter extends AbstractCharacter { * @ Calculates Defense for shield */ private float getShieldDefense(Item shield) { + if (shield == null) return 0; + + if (ItemTemplate.isShield(shield) == false) + return 0; + ItemBase ab = shield.getItemBase(); - if (ab == null || !ab.isShield()) + + if (ab == null) return 0; + CharacterSkill blockSkill = this.skills.get("Block"); + float skillMod; + if (blockSkill == null) { skillMod = 0; } else skillMod = blockSkill.getModifiedAmount(); float def = ab.getDefense(); + //apply item defense bonuses if (shield != null) { def += shield.getBonus(ModType.DR, SourceType.NONE); @@ -4127,7 +4137,7 @@ public class PlayerCharacter extends AbstractCharacter { //set block if block found this.bonuses.setBool(ModType.Block, SourceType.NONE, false); if (this.baseClass != null && (this.baseClass.getObjectUUID() == 2500 || this.baseClass.getObjectUUID() == 2501)) - if (off != null && off.getItemBase() != null && off.getItemBase().isShield()) + if (off != null && off.getItemBase() != null && ItemTemplate.isShield(off)) this.bonuses.setBool(ModType.Block, SourceType.NONE, true); //set dodge if rogue @@ -4194,7 +4204,7 @@ public class PlayerCharacter extends AbstractCharacter { boolean unarmed = false; if (weapon == null) { weapon = equipped.get(EquipSlotType.LHELD); - if (weapon == null || weapon.getItemBase().isShield()) + if (weapon == null || ItemTemplate.isShield(weapon)) unarmed = true; else wb = weapon.getItemBase();