From b000c9b60f123e6a883453e8545b1d54080b5ee9 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Thu, 2 Mar 2023 21:46:02 -0600 Subject: [PATCH] generic range method added, mob spell casting cleanup --- src/engine/ai/MobileFSM.java | 15 +++--------- src/engine/ai/utilities/CombatUtilities.java | 24 ++++++++++---------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 6a57b0cd..b827ffd5 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -1667,7 +1667,7 @@ public class MobileFSM { } } - int random = ThreadLocalRandom.current().nextInt(eligiblePowers.size() *2); + int random = ThreadLocalRandom.current().nextInt(eligiblePowers.size()); int powerToken = 0; int powerRank = 0; Map entries = eligiblePowers; @@ -1678,7 +1678,7 @@ public class MobileFSM { powerToken = entry.getKey(); powerRank = entry.getValue(); PowersBase mobPower = PowersManager.getPowerByToken(powerToken); - if (CombatUtilities.inRangeToCast2D(mob, mob.getCombatTarget(), mobPower)) { + if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { //PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank); PerformActionMsg msg = new PerformActionMsg(); if(mobPower.isHarmful() == false || mobPower.targetSelf == true){ @@ -1712,16 +1712,7 @@ public class MobileFSM { for (Mob mob1 : mobCamp.zoneMobSet) { if (mob1.getMobBase().getFlags().contains(Enum.MobFlagType.RESPONDSTOCALLSFORHELP)) { if (mob1.getState() == STATE.Awake) { - Vector3fImmutable loc1 = mob.getLoc(); - Vector3fImmutable loc2 = mob1.getLoc(); - double sum = 0; - double x = loc1.x - loc2.x; - sum += x * x; - double z = loc1.z - loc2.z; - sum += z * z; - double dist = sqrt(sum); - double aggroRange = mob.getAggroRange(); - if (dist <= aggroRange) { + if (CombatUtilities.inRange2D(mob, mob1, mob.getAggroRange()) == true) { MovementUtilities.moveToLocation(mob1, mob.getLoc(), 0); } } diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index 56976ffd..68a48a2f 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -33,6 +33,7 @@ import java.util.concurrent.ThreadLocalRandom; import static engine.math.FastMath.sqr; import static java.lang.Math.pow; +import static java.lang.Math.sqrt; public class CombatUtilities { @@ -82,18 +83,17 @@ public class CombatUtilities { } } - public static boolean inRangeToCast2D(Mob agent,AbstractWorldObject target, PowersBase power) { - - if (Float.isNaN(agent.getLoc().x)) - return false; - try { - Vector3fImmutable sl = agent.getLoc(); - Vector3fImmutable tl = target.getLoc(); - float range = power.getRange(); - range += CombatManager.calcHitBox(target) + CombatManager.calcHitBox(agent); - return !(sl.distanceSquared2D(tl) > sqr(range)); - } catch (Exception e) { - Logger.error(e.toString()); + public static boolean inRange2D(AbstractWorldObject entity1, AbstractWorldObject entity2, double range){ + Vector3fImmutable loc1 = entity1.getLoc(); + Vector3fImmutable loc2 = entity2.getLoc(); + double sum = 0; + double x = loc1.x - loc2.x; + sum += x * x; + double z = loc1.z - loc2.z; + sum += z * z; + if(sqrt(sum) <= range){ + return true; + } else { return false; } }