Browse Source

remove test code, added guard captain and minion behaviour flags

master
FatBoy-DOTC 2 years ago
parent
commit
1d965c0785
  1. 38
      src/engine/ai/MobileFSM.java
  2. 3
      src/engine/gameManager/NPCManager.java
  3. 1
      src/engine/objects/Mob.java

38
src/engine/ai/MobileFSM.java

@ -7,6 +7,7 @@
// www.magicbane.com // www.magicbane.com
package engine.ai; package engine.ai;
import engine.Enum.DispatchChannel; import engine.Enum.DispatchChannel;
import engine.InterestManagement.WorldGrid;
import engine.ai.utilities.CombatUtilities; import engine.ai.utilities.CombatUtilities;
import engine.ai.utilities.MovementUtilities; import engine.ai.utilities.MovementUtilities;
import engine.gameManager.*; import engine.gameManager.*;
@ -20,6 +21,7 @@ import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -75,6 +77,7 @@ public class MobileFSM {
this.respondsToCallForHelp = respondstocallforhelp; this.respondsToCallForHelp = respondstocallforhelp;
} }
} }
private static void mobAttack(Mob aiAgent) { private static void mobAttack(Mob aiAgent) {
AbstractGameObject target = aiAgent.getCombatTarget(); AbstractGameObject target = aiAgent.getCombatTarget();
@ -110,6 +113,7 @@ public class MobileFSM {
handleMobAttackForMob(aiAgent, mob); handleMobAttackForMob(aiAgent, mob);
} }
} }
private static void petHandleBuildingAttack(Mob aiAgent, Building building) { private static void petHandleBuildingAttack(Mob aiAgent, Building building) {
int buildingHitBox = (int) CombatManager.calcHitBox(building); int buildingHitBox = (int) CombatManager.calcHitBox(building);
@ -216,6 +220,7 @@ public class MobileFSM {
if (MovementUtilities.canMove(aiAgent)) if (MovementUtilities.canMove(aiAgent))
MovementUtilities.moveToLocation(aiAgent, building.getLoc(), aiAgent.getRange() + buildingHitBox); MovementUtilities.moveToLocation(aiAgent, building.getLoc(), aiAgent.getRange() + buildingHitBox);
} }
private static void handlePlayerAttackForMob(Mob aiAgent, PlayerCharacter player) { private static void handlePlayerAttackForMob(Mob aiAgent, PlayerCharacter player) {
if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) {
@ -304,6 +309,7 @@ public class MobileFSM {
return; return;
} }
private static void handleMobAttackForMob(Mob aiAgent, Mob mob) { private static void handleMobAttackForMob(Mob aiAgent, Mob mob) {
@ -368,6 +374,7 @@ public class MobileFSM {
if (!MovementUtilities.updateMovementToCharacter(aiAgent, mob)) if (!MovementUtilities.updateMovementToCharacter(aiAgent, mob))
return; return;
} }
private static void patrol(Mob mob) { private static void patrol(Mob mob) {
if (mob.isMoving() == true) { if (mob.isMoving() == true) {
//early exit for a mob who is already moving to a patrol point //early exit for a mob who is already moving to a patrol point
@ -404,6 +411,7 @@ public class MobileFSM {
mob.lastPatrolPointIndex += 1; mob.lastPatrolPointIndex += 1;
} }
} }
public static boolean canCast(Mob mob) { public static boolean canCast(Mob mob) {
// Performs validation to determine if a // Performs validation to determine if a
@ -420,6 +428,7 @@ public class MobileFSM {
return mob.nextCastTime <= System.currentTimeMillis(); return mob.nextCastTime <= System.currentTimeMillis();
} }
public static boolean MobCast(Mob mob) { public static boolean MobCast(Mob mob) {
// Method picks a random spell from a mobile's list of powers // Method picks a random spell from a mobile's list of powers
@ -496,6 +505,7 @@ public class MobileFSM {
return false; return false;
} }
public static void MobCallForHelp(Mob mob) { public static void MobCallForHelp(Mob mob) {
boolean callGotResponse = false; boolean callGotResponse = false;
if (mob.nextCallForHelp == 0) { if (mob.nextCallForHelp == 0) {
@ -518,16 +528,12 @@ public class MobileFSM {
mob.nextCallForHelp = System.currentTimeMillis() + 60000; mob.nextCallForHelp = System.currentTimeMillis() + 60000;
} }
} }
public static void run(Mob mob) { public static void run(Mob mob) {
if (mob == null) { if (mob == null) {
return; return;
} }
if (mob.isPet() == false && mob.isSummonedPet() == false && mob.isNecroPet() == false) { if (mob.isPet() == false && mob.isSummonedPet() == false && mob.isNecroPet() == false) {
//TEST CODE FOR BEHAVIOUR CHANGING START
if (mob.BehaviourType == null || mob.BehaviourType.ordinal() == MobBehaviourType.None.ordinal()) {
mob.BehaviourType = MobBehaviourType.Simple;
}
//TEST CODE FOR BEHAVIOUR CHANGING END
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);
@ -561,6 +567,7 @@ public class MobileFSM {
CheckForAttack(mob); CheckForAttack(mob);
} }
} }
private static void CheckForAggro(Mob aiAgent) { private static void CheckForAggro(Mob aiAgent) {
//looks for and sets mobs combatTarget //looks for and sets mobs combatTarget
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -594,6 +601,7 @@ public class MobileFSM {
} }
} }
} }
private static void CheckMobMovement(Mob mob) { private static void CheckMobMovement(Mob mob) {
mob.updateLocation(); mob.updateLocation();
if (mob.isPet() == false && mob.isSummonedPet() == false && mob.isNecroPet() == false) { if (mob.isPet() == false && mob.isSummonedPet() == false && mob.isNecroPet() == false) {
@ -620,6 +628,7 @@ public class MobileFSM {
} }
} }
} }
private static void CheckForRespawn(Mob aiAgent) { private static void CheckForRespawn(Mob aiAgent) {
//handles checking for respawn of dead mobs even when no players have mob loaded //handles checking for respawn of dead mobs even when no players have mob loaded
//Despawn Timer with Loot currently in inventory. //Despawn Timer with Loot currently in inventory.
@ -659,6 +668,7 @@ public class MobileFSM {
} }
} }
public static void CheckForAttack(Mob mob) { public static void CheckForAttack(Mob mob) {
//checks if mob can attack based on attack timer and range //checks if mob can attack based on attack timer and range
if (mob.isAlive()) if (mob.isAlive())
@ -671,6 +681,7 @@ public class MobileFSM {
} }
mobAttack(mob); mobAttack(mob);
} }
private static void CheckToSendMobHome(Mob mob) { private static void CheckToSendMobHome(Mob mob) {
if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) { if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) {
PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersBase recall = PowersManager.getPowerByToken(-1994153779);
@ -679,6 +690,7 @@ public class MobileFSM {
mob.setCombatTarget(null); mob.setCombatTarget(null);
} }
} }
public static void dead(Mob aiAgent) { public static void dead(Mob aiAgent) {
//Despawn Timer with Loot currently in inventory. //Despawn Timer with Loot currently in inventory.
if (aiAgent.getCharItemManager().getInventoryCount() > 0) { if (aiAgent.getCharItemManager().getInventoryCount() > 0) {
@ -710,6 +722,7 @@ public class MobileFSM {
} }
} }
} }
private static void respawn(Mob aiAgent) { private static void respawn(Mob aiAgent) {
if (!aiAgent.canRespawn()) if (!aiAgent.canRespawn())
@ -725,6 +738,7 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
} }
} }
private static void chaseTarget(Mob mob) { private static void chaseTarget(Mob mob) {
mob.updateMovementState(); mob.updateMovementState();
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
@ -737,9 +751,21 @@ public class MobileFSM {
} }
} }
} }
private static void SafeGuardAggro(Mob mob) { private static void SafeGuardAggro(Mob mob) {
for(Entry<Integer,Boolean> entry : mob.playerAgroMap.entrySet()){ HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(mob, 100, MBServerStatics.MASK_MOB);
for (AbstractWorldObject awoMob : awoList) {
//dont scan self.
if (mob.equals(awoMob))
continue;
Mob aggroMob = (Mob) awoMob;
//dont attack other guards
if (aggroMob.isGuard())
continue;
if (mob.getLoc().distanceSquared2D(aggroMob.getLoc()) > sqr(50))
continue;
mob.setCombatTarget(aggroMob);
} }
} }
} }

3
src/engine/gameManager/NPCManager.java

@ -2,6 +2,7 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -324,7 +325,7 @@ public enum NPCManager {
mob.deathTime = System.currentTimeMillis(); mob.deathTime = System.currentTimeMillis();
mob.spawnTime = 900; mob.spawnTime = 900;
mob.npcOwner = guardCaptain; mob.npcOwner = guardCaptain;
mob.BehaviourType = MobileFSM.MobBehaviourType.GuardMinion;
return mob; return mob;
} }

1
src/engine/objects/Mob.java

@ -13,7 +13,6 @@ import engine.Enum;
import engine.Enum.*; import engine.Enum.*;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM; import engine.ai.MobileFSM;
import engine.ai.utilities.MovementUtilities;
import engine.exception.SerializationException; import engine.exception.SerializationException;
import engine.gameManager.*; import engine.gameManager.*;
import engine.job.JobContainer; import engine.job.JobContainer;

Loading…
Cancel
Save