From 531cd52664053b680785322da56dd3062420c1b3 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 14 Mar 2023 18:39:59 -0500 Subject: [PATCH] mob ai Chase state work --- src/engine/ai/MobileFSM.java | 20 +++++++++++++++----- src/engine/ai/utilities/CombatUtilities.java | 14 ++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index e5c7f95a..1ca8e072 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -1730,13 +1730,23 @@ public class MobileFSM { mob.nextCallForHelp = System.currentTimeMillis() + 60000; } public static void handleMobChase(Mob mob){ - if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(),mob.getRange()) == true) { - MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); + if (!MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget())) { + mob.setAggroTargetID(0); + mob.setCombatTarget(null); + MovementUtilities.moveToLocation(mob, mob.getTrueBindLoc(), 0); + mob.setState(STATE.Awake); + return; + } + float range = mob.getRange(); + float distance = mob.getLoc().distanceSquared2D(mob.getCombatTarget().getLoc()); + boolean inRange = mob.getLoc().inRange2D(mob.getCombatTarget().getLoc(),range); + if(range > distance) { + mob.stopMovement(mob.getLoc()); mob.setState(STATE.Attack); } - else{ - mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); - MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); + else if(mob.isMoving() == true){ + mob.destination = mob.getCombatTarget().getLoc();//MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); + MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); } } } diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index 519dcdeb..28c8d5b9 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -16,6 +16,7 @@ import engine.ai.MobileFSM.STATE; import engine.gameManager.ChatManager; import engine.gameManager.CombatManager; import engine.gameManager.PowersManager; +import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.msg.PerformActionMsg; @@ -84,18 +85,7 @@ public class CombatUtilities { } 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((sum*sum) <= (range*range)){ - return true; - } else { - return false; - } + return entity1.getLoc().distance2D(entity2.getLoc()) < range; } public static void swingIsBlock(Mob agent,AbstractWorldObject target, int animation) {