From 56b89b7080da3b2369c99acaa935937610a9b71b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 10 Mar 2024 16:21:23 -0400 Subject: [PATCH] Refactor isTwoHanded() --- src/engine/gameManager/CombatManager.java | 13 ++++++++----- src/engine/objects/ItemBase.java | 7 ------- src/engine/objects/ItemFactory.java | 4 ++-- src/engine/objects/ItemTemplate.java | 8 ++++++++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index f6760780..b24d484a 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -595,7 +595,9 @@ public enum CombatManager { // Apply Weapon power effect if any. don't try to apply twice if // dual wielding. Perform after passive test for sync purposes. - if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) && (mainHand || wb.isTwoHanded())) { + ItemTemplate template = ItemTemplate.itemTemplates.get(wb.getUUID()); + + if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) && (mainHand || ItemTemplate.isTwoHanded(template))) { dpj = ((PlayerCharacter) attacker).getWeaponPower(); @@ -811,7 +813,8 @@ public enum CombatManager { // Apply Weapon power effect if any. // don't try to apply twice if dual wielding. - if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) && (mainHand || wb.isTwoHanded())) { + ItemTemplate template = ItemTemplate.itemTemplates.get(wb.getUUID()); + if (attacker.getObjectType().equals(GameObjectType.PlayerCharacter) && (mainHand || ItemTemplate.isTwoHanded(template))) { dpj = ((PlayerCharacter) attacker).getWeaponPower(); if (dpj != null) { @@ -1046,7 +1049,7 @@ public enum CombatManager { return 75; else if (required.equals("Sword")) { - if (wb.isTwoHanded()) + if (ItemTemplate.isTwoHanded(template)) return 105; else return 98; @@ -1056,7 +1059,7 @@ public enum CombatManager { } else if (required.equals("Spear")) { return 92; } else if (required.equals("Hammer") || required.equals("Axe")) { - if (wb.isTwoHanded()) { + if (ItemTemplate.isTwoHanded(template)) { return 105; } else if (mastery.equals("Throwing")) { return 115; @@ -1073,7 +1076,7 @@ public enum CombatManager { return 110; } else if (required.equals("Bow")) { return 109; - } else if (wb.isTwoHanded()) { + } else if (ItemTemplate.isTwoHanded(template)) { return 105; } else { return 100; diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index d5912e32..166fbaa8 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -43,7 +43,6 @@ public class ItemBase { private final short maxDamage; private final String mastery; private final engine.Enum.SourceType damageType; - private final boolean twoHanded; private boolean isConsumable; // Item stat modifiers @@ -74,8 +73,6 @@ public class ItemBase { this.mastery = rs.getString("mastery"); damageType = Enum.SourceType.valueOf(rs.getString("damageType").toUpperCase()); - this.twoHanded = (rs.getInt("twoHanded") == 1); - ItemTemplate template = ItemTemplate.itemTemplates.get(this.getUUID()); if (template == null) @@ -211,10 +208,6 @@ public class ItemBase { public final int getUUID() { return uuid; } - - public boolean isTwoHanded() { - return this.twoHanded; - } public String getMastery() { return mastery; } diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 4cdde82b..0269aa5e 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -235,7 +235,7 @@ public class ItemFactory { case "Hammer": case "Unarmed Combat": - if (ib.isTwoHanded()) + if (ItemTemplate.isTwoHanded(template)) galvorAmount = 20; else galvorAmount = 10; @@ -829,7 +829,7 @@ public class ItemFactory { case "Hammer": case "Unarmed Combat": - if (ib.isTwoHanded()) + if (ItemTemplate.isTwoHanded(template)) galvorAmount = 22; else galvorAmount = 11; diff --git a/src/engine/objects/ItemTemplate.java b/src/engine/objects/ItemTemplate.java index bb59e3f3..606ec008 100644 --- a/src/engine/objects/ItemTemplate.java +++ b/src/engine/objects/ItemTemplate.java @@ -471,6 +471,14 @@ public class ItemTemplate { return item.template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD)); } + public static boolean isTwoHanded(ItemTemplate template) { + + if (!template.item_type.equals(Enum.ItemType.WEAPON)) + return false; + + return template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD)); + } + public static boolean isShield(Item item) { if (item.template.item_skill_required.containsKey("Block"))