From 0e78902ff61fd8397a582320e2f2c6036fab5b92 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 8 Aug 2023 14:22:49 -0500 Subject: [PATCH] ranged mobs attack at range again --- src/engine/mobileAI/MobAI.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 514ad546..0cb34cca 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -956,10 +956,12 @@ public class MobAI { try { - mob.updateMovementState(); - mob.updateLocation(); - - if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { + float rangeSquared = mob.getRange() * mob.getRange(); + float distanceSquared = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); + if(mob.isMoving() == true && distanceSquared < rangeSquared - 50) { + mob.destination = mob.getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 0); + } else if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (mob.getRange() > 15) { mob.destination = mob.getCombatTarget().getLoc(); MovementUtilities.moveToLocation(mob, mob.destination, 0); @@ -978,11 +980,10 @@ public class MobAI { MovementUtilities.moveToLocation(mob, mob.getCombatTarget().getLoc(), 0); break; } - if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == true) { - mob.stopMovement(mob.getLoc()); - } } } + mob.updateMovementState(); + mob.updateLocation(); } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: chaseTarget" + " " + e.getMessage()); }