Browse Source

pet movement logic

master
FatBoy-DOTC 2 years ago
parent
commit
e38be1e18f
  1. 21
      src/engine/ai/MobileFSM.java

21
src/engine/ai/MobileFSM.java

@ -30,7 +30,11 @@ import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr; import static engine.math.FastMath.sqr;
public class MobileFSM { public class MobileFSM {
private static void AttackTarget(Mob mob, AbstractWorldObject target) { private static void AttackTarget(Mob mob, AbstractWorldObject target) {
if(target == null || mob == null){ if(mob == null){
return;
}
if(target == null){
mob.setCombatTarget(null);
return; return;
} }
switch (target.getObjectType()) { switch (target.getObjectType()) {
@ -426,17 +430,18 @@ public class MobileFSM {
//mob no longer has its owner loaded, translocate pet to owner //mob no longer has its owner loaded, translocate pet to owner
MovementManager.translocate(mob, mob.getOwner().getLoc(), null); MovementManager.translocate(mob, mob.getOwner().getLoc(), null);
} }
if (mob.getCombatTarget() == null || mob.combatTarget.isAlive() == false) { if (mob.getCombatTarget() == null) {
//move back to owner //move back to owner
if (CombatUtilities.inRange2D(mob, mob.getOwner(), 10) == false) { if(CombatUtilities.inRange2D(mob,mob.getOwner(),11)) {
return;
}
mob.destination = mob.getOwner().getLoc(); mob.destination = mob.getOwner().getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 5); MovementUtilities.moveToLocation(mob, mob.destination, 10);
} else{ } else{
chaseTarget(mob); chaseTarget(mob);
} }
} }
} }
}
private static void CheckForRespawn(Mob aiAgent) { private static void CheckForRespawn(Mob aiAgent) {
if (aiAgent.deathTime == 0) { if (aiAgent.deathTime == 0) {
aiAgent.setDeathTime(System.currentTimeMillis()); aiAgent.setDeathTime(System.currentTimeMillis());
@ -464,7 +469,6 @@ public class MobileFSM {
} }
if (System.currentTimeMillis() > aiAgent.deathTime + (aiAgent.spawnTime * 1000)) { if (System.currentTimeMillis() > aiAgent.deathTime + (aiAgent.spawnTime * 1000)) {
aiAgent.respawn(); aiAgent.respawn();
aiAgent.setCombatTarget(null);
} }
} }
public static void CheckForAttack(Mob mob) { public static void CheckForAttack(Mob mob) {
@ -534,8 +538,6 @@ public class MobileFSM {
} }
private static void chaseTarget(Mob mob) { private static void chaseTarget(Mob mob) {
mob.updateMovementState(); mob.updateMovementState();
if (CombatUtilities.inRangeToAttack2D(mob, mob.getCombatTarget()))
return;
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
if (mob.getRange() > 15) { if (mob.getRange() > 15) {
mob.destination = mob.getCombatTarget().getLoc(); mob.destination = mob.getCombatTarget().getLoc();
@ -602,6 +604,9 @@ public class MobileFSM {
} }
} }
private static void PetLogic(Mob mob){ private static void PetLogic(Mob mob){
if(mob.getCombatTarget() != null && mob.getCombatTarget().isAlive() == false){
mob.setCombatTarget(null);
}
if(MovementUtilities.canMove(mob)){ if(MovementUtilities.canMove(mob)){
CheckMobMovement(mob); CheckMobMovement(mob);
} }

Loading…
Cancel
Save