cleaned up some aggro rules

This commit is contained in:
2023-04-14 20:50:47 -05:00
parent f9205eb4e2
commit aaff8e7d6b
2 changed files with 32 additions and 29 deletions
+31 -28
View File
@@ -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) { public static boolean canCast(Mob mob) {
// Performs validation to determine if a // Performs validation to determine if a
@@ -578,6 +563,8 @@ public class MobileFSM {
if (mob == null) { if (mob == null) {
return; return;
} }
//add default behaviour type
mob.BehaviourType = MobBehaviourType.Aggro;
if (mob.isAlive() == false) { if (mob.isAlive() == false) {
//no need to continue if mob is dead, check for respawn and move on //no need to continue if mob is dead, check for respawn and move on
CheckForRespawn(mob); CheckForRespawn(mob);
@@ -599,7 +586,7 @@ public class MobileFSM {
CheckMobMovement(mob); CheckMobMovement(mob);
} }
//check if mob can attack if it isn't wimpy //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); CheckForAttack(mob);
} }
} }
@@ -631,11 +618,13 @@ public class MobileFSM {
continue; continue;
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) { if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
aiAgent.setAggroTargetID(playerID); aiAgent.setAggroTargetID(playerID);
aiAgent.setCombatTarget(loadedPlayer);
return; return;
} }
} }
} }
private static void CheckMobMovement(Mob mob) { private static void CheckMobMovement(Mob mob) {
mob.updateLocation();
if (mob.getCombatTarget() == null) { if (mob.getCombatTarget() == null) {
//patrol //patrol
int patrolRandom = ThreadLocalRandom.current().nextInt(1000); int patrolRandom = ThreadLocalRandom.current().nextInt(1000);
@@ -654,19 +643,18 @@ public class MobileFSM {
patrolRadius = 60; patrolRadius = 60;
MovementUtilities.aiMove(mob, Vector3fImmutable.getRandomPointInCircle(mob.getBindLoc(), patrolRadius), true); 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 { } else {
//chase target mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
mob.updateMovementState(); MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange());
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());
}
}
} }
} }
} }
@@ -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);
}
}
} }
+1 -1
View File
@@ -1347,7 +1347,7 @@ public class Mob extends AbstractIntelligenceAgent {
} }
public boolean canRespawn() { public boolean canRespawn() {
return System.currentTimeMillis() > this.despawnTime + 4000; return System.currentTimeMillis() > this.deathTime;
} }
@Override @Override