From aaff8e7d6b19562a8ce5160c6150c396ba40bd3b Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Fri, 14 Apr 2023 20:50:47 -0500 Subject: [PATCH] cleaned up some aggro rules --- src/engine/ai/MobileFSM.java | 59 +++++++++++++++++++----------------- src/engine/objects/Mob.java | 2 +- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 01a1fb89..04124152 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -451,21 +451,6 @@ public class MobileFSM { } } } - private static void respawn(Mob aiAgent) { - - if (!aiAgent.canRespawn()) - return; - - long spawnTime = aiAgent.getSpawnTime(); - - if (aiAgent.isPlayerGuard() && aiAgent.npcOwner != null && !aiAgent.npcOwner.isAlive()) - return; - - if (System.currentTimeMillis() > aiAgent.deathTime + spawnTime) { - aiAgent.respawn(); - aiAgent.setCombatTarget(null); - } - } public static boolean canCast(Mob mob) { // Performs validation to determine if a @@ -578,6 +563,8 @@ public class MobileFSM { if (mob == null) { return; } + //add default behaviour type + mob.BehaviourType = MobBehaviourType.Aggro; if (mob.isAlive() == false) { //no need to continue if mob is dead, check for respawn and move on CheckForRespawn(mob); @@ -599,7 +586,7 @@ public class MobileFSM { CheckMobMovement(mob); } //check if mob can attack if it isn't wimpy - if (!mob.BehaviourType.isWimpy && !mob.isMoving()) { + if (!mob.BehaviourType.isWimpy && !mob.isMoving() && mob.combatTarget != null) { CheckForAttack(mob); } } @@ -631,11 +618,13 @@ public class MobileFSM { continue; if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) { aiAgent.setAggroTargetID(playerID); + aiAgent.setCombatTarget(loadedPlayer); return; } } } private static void CheckMobMovement(Mob mob) { + mob.updateLocation(); if (mob.getCombatTarget() == null) { //patrol int patrolRandom = ThreadLocalRandom.current().nextInt(1000); @@ -654,19 +643,18 @@ public class MobileFSM { patrolRadius = 60; MovementUtilities.aiMove(mob, Vector3fImmutable.getRandomPointInCircle(mob.getBindLoc(), patrolRadius), true); + } + } + }else { + //chase target + mob.updateMovementState(); + if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { + if (mob.getRange() > 15) { + mob.destination = mob.getCombatTarget().getLoc(); + MovementUtilities.moveToLocation(mob, mob.destination, 0); } else { - //chase target - mob.updateMovementState(); - mob.updateLocation(); - if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { - if (mob.getRange() > 15) { - mob.destination = mob.getCombatTarget().getLoc(); - MovementUtilities.moveToLocation(mob, mob.destination, 0); - } else { - mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); - MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); - } - } + mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); + MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); } } } @@ -761,4 +749,19 @@ public class MobileFSM { } } } + private static void respawn(Mob aiAgent) { + + if (!aiAgent.canRespawn()) + return; + + long spawnTime = aiAgent.getSpawnTime(); + + if (aiAgent.isPlayerGuard() && aiAgent.npcOwner != null && !aiAgent.npcOwner.isAlive()) + return; + + if (System.currentTimeMillis() > aiAgent.deathTime + spawnTime) { + aiAgent.respawn(); + aiAgent.setCombatTarget(null); + } + } } \ No newline at end of file diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 83d7bf47..99aecfc2 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1347,7 +1347,7 @@ public class Mob extends AbstractIntelligenceAgent { } public boolean canRespawn() { - return System.currentTimeMillis() > this.despawnTime + 4000; + return System.currentTimeMillis() > this.deathTime; } @Override