Browse Source

mob ai Chase state work

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

18
src/engine/ai/MobileFSM.java

@ -1730,12 +1730,22 @@ public class MobileFSM {
mob.nextCallForHelp = System.currentTimeMillis() + 60000; mob.nextCallForHelp = System.currentTimeMillis() + 60000;
} }
public static void handleMobChase(Mob mob){ public static void handleMobChase(Mob mob){
if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(),mob.getRange()) == true) { if (!MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget())) {
MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); 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); mob.setState(STATE.Attack);
} }
else{ else if(mob.isMoving() == true){
mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget()); mob.destination = mob.getCombatTarget().getLoc();//MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange()); MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange());
} }
} }

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

@ -16,6 +16,7 @@ import engine.ai.MobileFSM.STATE;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.CombatManager; import engine.gameManager.CombatManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.PerformActionMsg; import engine.net.client.msg.PerformActionMsg;
@ -84,18 +85,7 @@ public class CombatUtilities {
} }
public static boolean inRange2D(AbstractWorldObject entity1, AbstractWorldObject entity2, double range){ public static boolean inRange2D(AbstractWorldObject entity1, AbstractWorldObject entity2, double range){
Vector3fImmutable loc1 = entity1.getLoc(); return entity1.getLoc().distance2D(entity2.getLoc()) < range;
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;
}
} }
public static void swingIsBlock(Mob agent,AbstractWorldObject target, int animation) { public static void swingIsBlock(Mob agent,AbstractWorldObject target, int animation) {

Loading…
Cancel
Save