From e38be1e18fade9f4f524d2c7e29681e71af60f35 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Fri, 21 Apr 2023 10:20:38 -0500 Subject: [PATCH] pet movement logic --- src/engine/ai/MobileFSM.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 7d56fa66..eb780b59 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -30,7 +30,11 @@ import java.util.concurrent.ThreadLocalRandom; import static engine.math.FastMath.sqr; public class MobileFSM { private static void AttackTarget(Mob mob, AbstractWorldObject target) { - if(target == null || mob == null){ + if(mob == null){ + return; + } + if(target == null){ + mob.setCombatTarget(null); return; } switch (target.getObjectType()) { @@ -426,14 +430,15 @@ public class MobileFSM { //mob no longer has its owner loaded, translocate pet to owner MovementManager.translocate(mob, mob.getOwner().getLoc(), null); } - if (mob.getCombatTarget() == null || mob.combatTarget.isAlive() == false) { + if (mob.getCombatTarget() == null) { //move back to owner - if (CombatUtilities.inRange2D(mob, mob.getOwner(), 10) == false) { - mob.destination = mob.getOwner().getLoc(); - MovementUtilities.moveToLocation(mob, mob.destination, 5); - } else { - chaseTarget(mob); + if(CombatUtilities.inRange2D(mob,mob.getOwner(),11)) { + return; } + mob.destination = mob.getOwner().getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 10); + } else{ + chaseTarget(mob); } } } @@ -464,7 +469,6 @@ public class MobileFSM { } if (System.currentTimeMillis() > aiAgent.deathTime + (aiAgent.spawnTime * 1000)) { aiAgent.respawn(); - aiAgent.setCombatTarget(null); } } public static void CheckForAttack(Mob mob) { @@ -534,8 +538,6 @@ public class MobileFSM { } private static void chaseTarget(Mob mob) { mob.updateMovementState(); - if (CombatUtilities.inRangeToAttack2D(mob, mob.getCombatTarget())) - return; if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (mob.getRange() > 15) { mob.destination = mob.getCombatTarget().getLoc(); @@ -602,6 +604,9 @@ public class MobileFSM { } } private static void PetLogic(Mob mob){ + if(mob.getCombatTarget() != null && mob.getCombatTarget().isAlive() == false){ + mob.setCombatTarget(null); + } if(MovementUtilities.canMove(mob)){ CheckMobMovement(mob); }