Browse Source

mob ai Chase state work

master
FatBoy-DOTC 2 years ago
parent
commit
531cd52664
  1. 20
      src/engine/ai/MobileFSM.java
  2. 14
      src/engine/ai/utilities/CombatUtilities.java

20
src/engine/ai/MobileFSM.java

@ -1730,13 +1730,23 @@ public class MobileFSM { @@ -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());
}
}
}

14
src/engine/ai/utilities/CombatUtilities.java

@ -16,6 +16,7 @@ import engine.ai.MobileFSM.STATE; @@ -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 { @@ -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) {

Loading…
Cancel
Save