Browse Source

added Chase to mob ai state enum

master
FatBoy-DOTC 2 years ago
parent
commit
dcac0634a8
  1. 38
      src/engine/ai/MobileFSM.java
  2. 2
      src/engine/ai/utilities/CombatUtilities.java
  3. 6
      src/engine/objects/AbstractCharacter.java

38
src/engine/ai/MobileFSM.java

@ -53,7 +53,8 @@ public class MobileFSM {
Home, Home,
Dead, Dead,
Recalling, Recalling,
Retaliate Retaliate,
Chase
} }
public static void run(Mob mob) { public static void run(Mob mob) {
@ -116,7 +117,6 @@ public class MobileFSM {
rwss.setPlayer(mob); rwss.setPlayer(mob);
DispatchMessage.sendToAllInRange(mob, rwss); DispatchMessage.sendToAllInRange(mob, rwss);
} }
if (mob.isPlayerGuard()) if (mob.isPlayerGuard())
guardAttack(mob); guardAttack(mob);
else if (mob.isPet() || mob.isSiege()) else if (mob.isPet() || mob.isSiege())
@ -144,6 +144,9 @@ public class MobileFSM {
case Retaliate: case Retaliate:
retaliate(mob); retaliate(mob);
break; break;
case Chase:
handleMobChase(mob);
break;
} }
} }
@ -339,8 +342,8 @@ public class MobileFSM {
if (!MovementUtilities.canMove(aiAgent)) if (!MovementUtilities.canMove(aiAgent))
return; return;
double WeaponRange = aiAgent.getEquip().get(0).getItemBase().getRange();
if (CombatUtilities.inRangeToAttack2D(aiAgent, mob)) if (CombatUtilities.inRange2D(aiAgent, mob, WeaponRange))
return; return;
@ -465,11 +468,18 @@ public class MobileFSM {
aiAgent.setState(STATE.Patrol); aiAgent.setState(STATE.Patrol);
return; return;
} }
aiAgent.setCombatTarget(aggroTarget);
double AttackRange = 3;
if(aiAgent.getEquip().get(0) != null){
AttackRange = aiAgent.getEquip().get(0).getItemBase().getRange();
} else if(aiAgent.getEquip().get(1) != null){
AttackRange = aiAgent.getEquip().get(1).getItemBase().getRange();
}
if (canCast(aiAgent) == true) { if (canCast(aiAgent) == true) {
if (MobCast(aiAgent) == false) { if (MobCast(aiAgent) == false) {
attack(aiAgent, targetID); attack(aiAgent, targetID);
} }
} else if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) { } else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, AttackRange)) {
aiAgent.setState(STATE.Attack); aiAgent.setState(STATE.Attack);
attack(aiAgent, targetID); attack(aiAgent, targetID);
return; return;
@ -888,10 +898,8 @@ public class MobileFSM {
//this stops mobs from attempting to move while they are underneath a player. //this stops mobs from attempting to move while they are underneath a player.
if (CombatUtilities.inRangeToAttack2D(aiAgent, player)) if (CombatUtilities.inRangeToAttack2D(aiAgent, player))
return; return;
//move mob to within attack range again
aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, player); aiAgent.setState(MobileFSM.STATE.Chase);
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { private static void handleMobAttackForPet(Mob aiAgent, Mob mob) {
@ -1678,7 +1686,7 @@ public class MobileFSM {
powerToken = entry.getKey(); powerToken = entry.getKey();
powerRank = entry.getValue(); powerRank = entry.getValue();
PowersBase mobPower = PowersManager.getPowerByToken(powerToken); PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { if (CombatUtilities.inRange2D(mob, target, mobPower.getRange())) {
PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank); PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank);
PerformActionMsg msg = new PerformActionMsg(); PerformActionMsg msg = new PerformActionMsg();
if(mobPower.isHarmful() == false || mobPower.targetSelf == true){ if(mobPower.isHarmful() == false || mobPower.targetSelf == true){
@ -1721,4 +1729,14 @@ public class MobileFSM {
//wait 60 seconds to call for help again //wait 60 seconds to call for help again
mob.nextCallForHelp = System.currentTimeMillis() + 60000; 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);
mob.setState(STATE.Attack);
}
else{
mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange());
}
}
} }

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

@ -91,7 +91,7 @@ public class CombatUtilities {
sum += x * x; sum += x * x;
double z = loc1.z - loc2.z; double z = loc1.z - loc2.z;
sum += z * z; sum += z * z;
if(sqrt(sum) <= range){ if((sum*sum) <= (range*range)){
return true; return true;
} else { } else {
return false; return false;

6
src/engine/objects/AbstractCharacter.java

@ -786,6 +786,12 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
if (mob.isSiege()) { if (mob.isSiege()) {
return 300; return 300;
} }
float DefaultRange = 8;
if(((Mob) this).getEquip().get(0) != null){
return ((Mob) this).getEquip().get(0).getItemBase().getRange();
} else if(((Mob) this).getEquip().get(1) != null){
return ((Mob) this).getEquip().get(1).getItemBase().getRange();
}
} }
if (this.rangeHandOne > this.rangeHandTwo) { if (this.rangeHandOne > this.rangeHandTwo) {
return this.rangeHandOne; return this.rangeHandOne;

Loading…
Cancel
Save