Browse Source

Relevant methods made static and moved into NPCManager

master
MagicBot 2 years ago
parent
commit
3881c2b1d0
  1. 8
      src/engine/InterestManagement/InterestManager.java
  2. 235
      src/engine/ai/MobileFSM.java
  3. 4
      src/engine/ai/utilities/MovementUtilities.java
  4. 7
      src/engine/db/handlers/dbMobHandler.java
  5. 2
      src/engine/devcmd/cmds/InfoCmd.java
  6. 4
      src/engine/gameManager/BuildingManager.java
  7. 16
      src/engine/gameManager/CombatManager.java
  8. 314
      src/engine/gameManager/NPCManager.java
  9. 8
      src/engine/net/client/ClientMessagePump.java
  10. 19
      src/engine/net/client/handlers/MinionTrainingMsgHandler.java
  11. 7
      src/engine/net/client/handlers/OrderNPCMsgHandler.java
  12. 2
      src/engine/objects/AbstractCharacter.java
  13. 4
      src/engine/objects/AbstractIntelligenceAgent.java
  14. 305
      src/engine/objects/Mob.java
  15. 8
      src/engine/objects/NPC.java
  16. 72
      src/engine/objects/PlayerCharacter.java
  17. 4
      src/engine/powers/poweractions/ClearAggroPowerAction.java
  18. 4
      src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java
  19. 19
      src/engine/powers/poweractions/CreateMobPowerAction.java
  20. 4
      src/engine/server/world/WorldServer.java

8
src/engine/InterestManagement/InterestManager.java

@ -285,7 +285,7 @@ public enum InterestManager implements Runnable {
uom.addObject(obj); uom.addObject(obj);
if (obj.getObjectType() == GameObjectType.Mob) if (obj.getObjectType() == GameObjectType.Mob)
((Mob) obj).getPlayerAgroMap().remove(player.getObjectUUID()); ((Mob) obj).playerAgroMap.remove(player.getObjectUUID());
} catch (Exception e) { } catch (Exception e) {
Logger.error("UnloadCharacter", obj.getObjectUUID() + " " + e.getMessage()); Logger.error("UnloadCharacter", obj.getObjectUUID() + " " + e.getMessage());
} }
@ -338,10 +338,10 @@ public enum InterestManager implements Runnable {
if (!awonpc.isAlive() && (awonpc.isPet() || awonpc.isSiege() || awonpc.isNecroPet() || awonpc.isPlayerGuard())) if (!awonpc.isAlive() && (awonpc.isPet() || awonpc.isSiege() || awonpc.isNecroPet() || awonpc.isPlayerGuard()))
continue; continue;
if (awonpc.getState().equals(STATE.Respawn) || awonpc.getState().equals(STATE.Disabled)) if (awonpc.state.equals(STATE.Respawn) || awonpc.state.equals(STATE.Disabled))
continue; continue;
awonpc.getPlayerAgroMap().put(player.getObjectUUID(), false); awonpc.playerAgroMap.put(player.getObjectUUID(), false);
MobileFSM.setAwake(awonpc, false); MobileFSM.setAwake(awonpc, false);
// IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000)); // IVarController.setVariable(awonpc, "IntelligenceDisableDelay", (double) (System.currentTimeMillis() + 5000));
// awonpc.enableIntelligence(); // awonpc.enableIntelligence();
@ -355,7 +355,7 @@ public enum InterestManager implements Runnable {
if (!awonpc.isAlive()) if (!awonpc.isAlive())
continue; continue;
awonpc.getPlayerAgroMap().put(player.getObjectUUID(), false); awonpc.playerAgroMap.put(player.getObjectUUID(), false);
if (awonpc.isMob()) if (awonpc.isMob())
MobileFSM.setAwake(awonpc, false); MobileFSM.setAwake(awonpc, false);

235
src/engine/ai/MobileFSM.java

@ -34,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr; import static engine.math.FastMath.sqr;
import static java.lang.Math.sqrt;
public class MobileFSM { public class MobileFSM {
@ -58,7 +57,7 @@ public class MobileFSM {
if (mob == null) { if (mob == null) {
return; return;
} }
STATE state = mob.getState(); STATE state = mob.state;
switch (state) { switch (state) {
case Idle: case Idle:
if (mob.isAlive()) if (mob.isAlive())
@ -149,21 +148,21 @@ public class MobileFSM {
public static boolean setAwake(Mob aiAgent, boolean force) { public static boolean setAwake(Mob aiAgent, boolean force) {
if (force) { if (force) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return true; return true;
} }
if (aiAgent.getState() == STATE.Idle) { if (aiAgent.state == STATE.Idle) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return true; return true;
} }
return false; return false;
} }
public static boolean setAggro(Mob aiAgent, int targetID) { public static boolean setAggro(Mob aiAgent, int targetID) {
if (aiAgent.getState() != STATE.Dead) { if (aiAgent.state != STATE.Dead) {
aiAgent.setNoAggro(false); aiAgent.setNoAggro(false);
aiAgent.setAggroTargetID(targetID); aiAgent.setAggroTargetID(targetID);
aiAgent.setState(STATE.Aggro); aiAgent.state = STATE.Aggro;
return true; return true;
} }
return false; return false;
@ -173,18 +172,18 @@ public class MobileFSM {
if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) { if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) {
mob.setWalkingHome(false); mob.setWalkingHome(false);
mob.setState(STATE.Home); mob.state = STATE.Home;
} }
} }
private static void awake(Mob aiAgent) { private static void awake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
//Don't attempt to aggro if No aggro is on and aiAgent is not home yet. //Don't attempt to aggro if No aggro is on and aiAgent is not home yet.
@ -197,8 +196,8 @@ public class MobileFSM {
aiAgent.setNoAggro(false); aiAgent.setNoAggro(false);
} }
//no players currently have this mob loaded. return to IDLE. //no players currently have this mob loaded. return to IDLE.
if (aiAgent.getPlayerAgroMap().isEmpty()) { if (aiAgent.playerAgroMap.isEmpty()) {
aiAgent.setState(STATE.Idle); aiAgent.state = STATE.Idle;
return; return;
} }
@ -210,7 +209,7 @@ public class MobileFSM {
//Get the Map for Players that loaded this mob. //Get the Map for Players that loaded this mob.
ConcurrentHashMap<Integer, Boolean> loadedPlayers = aiAgent.getPlayerAgroMap(); ConcurrentHashMap<Integer, Boolean> loadedPlayers = aiAgent.playerAgroMap;
if (!Enum.MobFlagType.AGGRESSIVE.elementOf(aiAgent.getMobBase().getFlags()) && aiAgent.getCombatTarget() == null) { if (!Enum.MobFlagType.AGGRESSIVE.elementOf(aiAgent.getMobBase().getFlags()) && aiAgent.getCombatTarget() == null) {
@ -218,7 +217,7 @@ public class MobileFSM {
int patrolRandom = ThreadLocalRandom.current().nextInt(1000); int patrolRandom = ThreadLocalRandom.current().nextInt(1000);
if (patrolRandom <= MBServerStatics.AI_PATROL_DIVISOR) { if (patrolRandom <= MBServerStatics.AI_PATROL_DIVISOR) {
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
} }
return; return;
} }
@ -251,7 +250,7 @@ public class MobileFSM {
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) { if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
aiAgent.setAggroTargetID(playerID); aiAgent.setAggroTargetID(playerID);
aiAgent.setState(STATE.Aggro); aiAgent.state = STATE.Aggro;
return; return;
} }
@ -260,37 +259,37 @@ public class MobileFSM {
int patrolRandom = ThreadLocalRandom.current().nextInt(1000); int patrolRandom = ThreadLocalRandom.current().nextInt(1000);
if (patrolRandom <= MBServerStatics.AI_PATROL_DIVISOR) { if (patrolRandom <= MBServerStatics.AI_PATROL_DIVISOR) {
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
} }
} }
private static void guardAttackMob(Mob aiAgent) { private static void guardAttackMob(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
AbstractGameObject target = aiAgent.getCombatTarget(); AbstractGameObject target = aiAgent.getCombatTarget();
if (target == null) { if (target == null) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (target.getObjectType().equals(GameObjectType.Mob) == false) { if (target.getObjectType().equals(GameObjectType.Mob) == false) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (target.equals(aiAgent)) { if (target.equals(aiAgent)) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
Mob mob = (Mob) target; Mob mob = (Mob) target;
if (!mob.isAlive() || mob.getState() == STATE.Dead) { if (!mob.isAlive() || mob.state == STATE.Dead) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -350,7 +349,7 @@ public class MobileFSM {
} }
private static void awakeNPCguard(Mob aiAgent) { private static void awakeNPCguard(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
@ -359,7 +358,7 @@ public class MobileFSM {
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -383,13 +382,13 @@ public class MobileFSM {
if (aiAgent.getLoc().distanceSquared2D(mob.getLoc()) > sqr(50)) if (aiAgent.getLoc().distanceSquared2D(mob.getLoc()) > sqr(50))
continue; continue;
aiAgent.setCombatTarget(mob); aiAgent.setCombatTarget(mob);
aiAgent.setState(STATE.Attack); aiAgent.state = STATE.Attack;
} }
} }
private static void petAwake(Mob aiAgent) { private static void petAwake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
@ -425,13 +424,13 @@ public class MobileFSM {
private static void aggro(Mob aiAgent, int targetID) { private static void aggro(Mob aiAgent, int targetID) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -447,22 +446,22 @@ public class MobileFSM {
if (aggroTarget == null) { if (aggroTarget == null) {
// Logger.error("MobileFSM.aggro", "aggro target with UUID " + targetID + " returned null"); // Logger.error("MobileFSM.aggro", "aggro target with UUID " + targetID + " returned null");
aiAgent.getPlayerAgroMap().remove(targetID); aiAgent.playerAgroMap.remove(targetID);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (!aiAgent.canSee(aggroTarget)) { if (!aiAgent.canSee(aggroTarget)) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
targetID = 0; targetID = 0;
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (!aggroTarget.isActive()) { if (!aggroTarget.isActive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
targetID = 0; targetID = 0;
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
aiAgent.setCombatTarget(aggroTarget); aiAgent.setCombatTarget(aggroTarget);
@ -471,7 +470,7 @@ public class MobileFSM {
attack(aiAgent, targetID); attack(aiAgent, targetID);
} }
} else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, aiAgent.getRange())) { } else if (CombatUtilities.inRange2D(aiAgent, aggroTarget, aiAgent.getRange())) {
aiAgent.setState(STATE.Attack); aiAgent.state = STATE.Attack;
attack(aiAgent, targetID); attack(aiAgent, targetID);
return; return;
} }
@ -480,14 +479,14 @@ public class MobileFSM {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0); MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (!MovementUtilities.inRangeOfBindLocation(aiAgent)) { if (!MovementUtilities.inRangeOfBindLocation(aiAgent)) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -511,14 +510,14 @@ public class MobileFSM {
private static void petAttack(Mob aiAgent) { private static void petAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
AbstractGameObject target = aiAgent.getCombatTarget(); AbstractGameObject target = aiAgent.getCombatTarget();
if (target == null) { if (target == null) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -530,13 +529,13 @@ public class MobileFSM {
if (!player.isActive()) { if (!player.isActive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (player.inSafeZone()) { if (player.inSafeZone()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -556,21 +555,21 @@ public class MobileFSM {
private static void mobAttack(Mob aiAgent) { private static void mobAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
AbstractGameObject target = aiAgent.getCombatTarget(); AbstractGameObject target = aiAgent.getCombatTarget();
if (target == null) { if (target == null) {
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
@ -582,13 +581,13 @@ public class MobileFSM {
if (!player.isActive()) { if (!player.isActive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (aiAgent.isNecroPet() && player.inSafeZone()) { if (aiAgent.isNecroPet() && player.inSafeZone()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Idle); aiAgent.state = STATE.Idle;
return; return;
} }
if (canCast(aiAgent) == true) { if (canCast(aiAgent) == true) {
@ -614,19 +613,19 @@ public class MobileFSM {
if (building.getRank() == -1) { if (building.getRank() == -1) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (!building.isVulnerable()) { if (!building.isVulnerable()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (BuildingManager.getBuildingFromCache(building.getObjectUUID()) == null) { if (BuildingManager.getBuildingFromCache(building.getObjectUUID()) == null) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -645,7 +644,7 @@ public class MobileFSM {
continue; continue;
mob.setCombatTarget(aiAgent); mob.setCombatTarget(aiAgent);
mob.setState(STATE.Attack); mob.state = STATE.Attack;
} }
} }
@ -722,13 +721,13 @@ public class MobileFSM {
if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (!player.isAlive()) { if (!player.isAlive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -798,13 +797,13 @@ public class MobileFSM {
if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (!player.isAlive()) { if (!player.isAlive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -815,14 +814,14 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
if (!MovementUtilities.inRangeDropAggro(aiAgent, player)) { if (!MovementUtilities.inRangeDropAggro(aiAgent, player)) {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0); MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (CombatUtilities.inRange2D(aiAgent, player, aiAgent.getRange())) { if (CombatUtilities.inRange2D(aiAgent, player, aiAgent.getRange())) {
@ -891,13 +890,13 @@ public class MobileFSM {
if (CombatUtilities.inRangeToAttack2D(aiAgent, player)) if (CombatUtilities.inRangeToAttack2D(aiAgent, player))
return; return;
//set mob to pursue target //set mob to pursue target
aiAgent.setState(MobileFSM.STATE.Chase); aiAgent.state = STATE.Chase;
} }
private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { private static void handleMobAttackForPet(Mob aiAgent, Mob mob) {
if (!mob.isAlive()) { if (!mob.isAlive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -969,7 +968,7 @@ public class MobileFSM {
if (!mob.isAlive()) { if (!mob.isAlive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1040,7 +1039,7 @@ public class MobileFSM {
//in range to attack, start attacking now! //in range to attack, start attacking now!
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
@ -1048,23 +1047,23 @@ public class MobileFSM {
if (aggroTarget == null) { if (aggroTarget == null) {
// Logger.error("MobileFSM.aggro", "aggro target with UUID " + targetID + " returned null"); // Logger.error("MobileFSM.aggro", "aggro target with UUID " + targetID + " returned null");
aiAgent.getPlayerAgroMap().remove(targetID); aiAgent.playerAgroMap.remove(targetID);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (aiAgent.getMobBase().getSeeInvis() < aggroTarget.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < aggroTarget.getHidden()) {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (!aggroTarget.isAlive()) { if (!aggroTarget.isAlive()) {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
@ -1072,7 +1071,7 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -1080,7 +1079,7 @@ public class MobileFSM {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0); MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1144,17 +1143,17 @@ public class MobileFSM {
MovementManager.translocate(aiAgent, aiAgent.getBindLoc(), null); MovementManager.translocate(aiAgent, aiAgent.getBindLoc(), null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
} }
private static void recalling(Mob aiAgent) { private static void recalling(Mob aiAgent) {
//recall home. //recall home.
if (aiAgent.getLoc() == aiAgent.getBindLoc()) if (aiAgent.getLoc() == aiAgent.getBindLoc())
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
} }
} }
private static void patrol(Mob aiAgent) { private static void patrol(Mob aiAgent) {
@ -1162,7 +1161,7 @@ public class MobileFSM {
MobBase mobbase = aiAgent.getMobBase(); MobBase mobbase = aiAgent.getMobBase();
if (mobbase != null && (Enum.MobFlagType.SENTINEL.elementOf(mobbase.getFlags()) || !Enum.MobFlagType.CANROAM.elementOf(mobbase.getFlags()))) { if (mobbase != null && (Enum.MobFlagType.SENTINEL.elementOf(mobbase.getFlags()) || !Enum.MobFlagType.CANROAM.elementOf(mobbase.getFlags()))) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1178,35 +1177,35 @@ public class MobileFSM {
MovementUtilities.aiMove(aiAgent, Vector3fImmutable.getRandomPointInCircle(aiAgent.getBindLoc(), patrolRadius), true); MovementUtilities.aiMove(aiAgent, Vector3fImmutable.getRandomPointInCircle(aiAgent.getBindLoc(), patrolRadius), true);
} }
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
} }
private static void dead(Mob aiAgent) { private 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) {
if (System.currentTimeMillis() > aiAgent.getDeathTime() + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_WITH_LOOT) {
aiAgent.despawn(); aiAgent.despawn();
//update time of death after mob despawns so respawn time happens after mob despawns. //update time of death after mob despawns so respawn time happens after mob despawns.
aiAgent.setDeathTime(System.currentTimeMillis()); aiAgent.setDeathTime(System.currentTimeMillis());
aiAgent.setState(STATE.Respawn); aiAgent.state = STATE.Respawn;
} }
//No items in inventory. //No items in inventory.
} else { } else {
//Mob's Loot has been looted. //Mob's Loot has been looted.
if (aiAgent.isHasLoot()) { if (aiAgent.isHasLoot()) {
if (System.currentTimeMillis() > aiAgent.getDeathTime() + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER_ONCE_LOOTED) {
aiAgent.despawn(); aiAgent.despawn();
//update time of death after mob despawns so respawn time happens after mob despawns. //update time of death after mob despawns so respawn time happens after mob despawns.
aiAgent.setDeathTime(System.currentTimeMillis()); aiAgent.setDeathTime(System.currentTimeMillis());
aiAgent.setState(STATE.Respawn); aiAgent.state = STATE.Respawn;
} }
//Mob never had Loot. //Mob never had Loot.
} else { } else {
if (System.currentTimeMillis() > aiAgent.getDeathTime() + MBServerStatics.DESPAWN_TIMER) { if (System.currentTimeMillis() > aiAgent.deathTime + MBServerStatics.DESPAWN_TIMER) {
aiAgent.despawn(); aiAgent.despawn();
//update time of death after mob despawns so respawn time happens after mob despawns. //update time of death after mob despawns so respawn time happens after mob despawns.
aiAgent.setDeathTime(System.currentTimeMillis()); aiAgent.setDeathTime(System.currentTimeMillis());
aiAgent.setState(STATE.Respawn); aiAgent.state = STATE.Respawn;
} }
} }
} }
@ -1214,14 +1213,14 @@ public class MobileFSM {
private static void guardAwake(Mob aiAgent) { private static void guardAwake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) { if (aiAgent.getLoc().distanceSquared2D(aiAgent.getBindLoc()) > sqr(2000)) {
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -1232,12 +1231,12 @@ public class MobileFSM {
aiAgent.setNoAggro(false); aiAgent.setNoAggro(false);
// do nothing if no players are around. // do nothing if no players are around.
if (aiAgent.getPlayerAgroMap().isEmpty()) if (aiAgent.playerAgroMap.isEmpty())
return; return;
//Get the Map for Players that loaded this mob. //Get the Map for Players that loaded this mob.
ConcurrentHashMap<Integer, Boolean> loadedPlayers = aiAgent.getPlayerAgroMap(); ConcurrentHashMap<Integer, Boolean> loadedPlayers = aiAgent.playerAgroMap;
//no players currently have this mob loaded. return to IDLE. //no players currently have this mob loaded. return to IDLE.
//aiAgent finished moving home, set aggro on. //aiAgent finished moving home, set aggro on.
@ -1342,13 +1341,13 @@ public class MobileFSM {
if (aggro) { if (aggro) {
if (CombatUtilities.inRangeToAttack(aiAgent, loadedPlayer)) { if (CombatUtilities.inRangeToAttack(aiAgent, loadedPlayer)) {
aiAgent.setAggroTargetID(playerID); aiAgent.setAggroTargetID(playerID);
aiAgent.setState(STATE.Aggro); aiAgent.state = STATE.Aggro;
return; return;
} }
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) { if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
aiAgent.setAggroTargetID(playerID); aiAgent.setAggroTargetID(playerID);
aiAgent.setState(STATE.Aggro); aiAgent.state = STATE.Aggro;
return; return;
} }
} }
@ -1356,12 +1355,12 @@ public class MobileFSM {
//attempt to patrol even if aiAgent isn't aggresive; //attempt to patrol even if aiAgent isn't aggresive;
if (aiAgent.isMoving() == false) if (aiAgent.isMoving() == false)
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
} }
private static void guardAggro(Mob aiAgent, int targetID) { private static void guardAggro(Mob aiAgent, int targetID) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
@ -1376,26 +1375,26 @@ public class MobileFSM {
PlayerCharacter aggroTarget = PlayerCharacter.getFromCache(targetID); PlayerCharacter aggroTarget = PlayerCharacter.getFromCache(targetID);
if (aggroTarget == null) { if (aggroTarget == null) {
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (!aiAgent.canSee(aggroTarget)) { if (!aiAgent.canSee(aggroTarget)) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
targetID = 0; targetID = 0;
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (!aggroTarget.isActive()) { if (!aggroTarget.isActive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
targetID = 0; targetID = 0;
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) { if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) {
aiAgent.setCombatTarget(aggroTarget); aiAgent.setCombatTarget(aggroTarget);
aiAgent.setState(STATE.Attack); aiAgent.state = STATE.Attack;
guardAttack(aiAgent); guardAttack(aiAgent);
return; return;
} }
@ -1412,7 +1411,7 @@ public class MobileFSM {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0); MovementUtilities.moveToLocation(aiAgent, aiAgent.getTrueBindLoc(), 0);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1420,7 +1419,7 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setWalkingHome(false); aiAgent.setWalkingHome(false);
aiAgent.setState(STATE.Home); aiAgent.state = STATE.Home;
return; return;
} }
@ -1437,8 +1436,8 @@ public class MobileFSM {
} }
private static void guardPatrol(Mob aiAgent) { private static void guardPatrol(Mob aiAgent) {
if (aiAgent.getPlayerAgroMap().isEmpty()) { if (aiAgent.playerAgroMap.isEmpty()) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1449,7 +1448,7 @@ public class MobileFSM {
DispatchMessage.sendToAllInRange(aiAgent, rwss); DispatchMessage.sendToAllInRange(aiAgent, rwss);
} }
if (aiAgent.getNpcOwner() == null) { if (aiAgent.npcOwner == null) {
if (!aiAgent.isWalk() || (aiAgent.isCombat() && aiAgent.getCombatTarget() == null)) { if (!aiAgent.isWalk() || (aiAgent.isCombat() && aiAgent.getCombatTarget() == null)) {
aiAgent.setWalkMode(true); aiAgent.setWalkMode(true);
@ -1460,14 +1459,14 @@ public class MobileFSM {
} }
if (aiAgent.isMoving()) { if (aiAgent.isMoving()) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
Building barrack = aiAgent.getBuilding(); Building barrack = aiAgent.building;
if (barrack == null) { if (barrack == null) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1480,7 +1479,7 @@ public class MobileFSM {
} }
} }
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1494,25 +1493,25 @@ public class MobileFSM {
} }
Building barrack = ((Mob) aiAgent.getNpcOwner()).getBuilding(); Building barrack = ((Mob) aiAgent.npcOwner).building;
if (barrack == null) { if (barrack == null) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (barrack.getPatrolPoints() == null) { if (barrack.getPatrolPoints() == null) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (barrack.getPatrolPoints().isEmpty()) { if (barrack.getPatrolPoints().isEmpty()) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
if (aiAgent.isMoving()) { if (aiAgent.isMoving()) {
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
return; return;
} }
@ -1528,24 +1527,24 @@ public class MobileFSM {
if (patrolLoc != null) { if (patrolLoc != null) {
if (MovementUtilities.canMove(aiAgent)) { if (MovementUtilities.canMove(aiAgent)) {
MovementUtilities.aiMove(aiAgent, patrolLoc, true); MovementUtilities.aiMove(aiAgent, patrolLoc, true);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
} }
} }
} }
} }
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
} }
private static void guardAttack(Mob aiAgent) { private static void guardAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.state = STATE.Dead;
return; return;
} }
AbstractGameObject target = aiAgent.getCombatTarget(); AbstractGameObject target = aiAgent.getCombatTarget();
if (target == null) { if (target == null) {
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
@ -1556,13 +1555,13 @@ public class MobileFSM {
if (!player.isActive()) { if (!player.isActive()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Patrol); aiAgent.state = STATE.Patrol;
return; return;
} }
if (aiAgent.isNecroPet() && player.inSafeZone()) { if (aiAgent.isNecroPet() && player.inSafeZone()) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Idle); aiAgent.state = STATE.Idle;
return; return;
} }
if (canCast(aiAgent) == true) { if (canCast(aiAgent) == true) {
@ -1575,7 +1574,7 @@ public class MobileFSM {
break; break;
case Building: case Building:
Logger.info("PLAYER GUARD ATTEMPTING TO ATTACK BUILDING IN " + aiAgent.getParentZone().getName()); Logger.info("PLAYER GUARD ATTEMPTING TO ATTACK BUILDING IN " + aiAgent.getParentZone().getName());
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
break; break;
case Mob: case Mob:
Mob mob = (Mob) target; Mob mob = (Mob) target;
@ -1590,7 +1589,7 @@ public class MobileFSM {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
} }
private static void respawn(Mob aiAgent) { private static void respawn(Mob aiAgent) {
@ -1599,26 +1598,26 @@ public class MobileFSM {
long spawnTime = aiAgent.getSpawnTime(); long spawnTime = aiAgent.getSpawnTime();
if (aiAgent.isPlayerGuard() && aiAgent.getNpcOwner() != null && !aiAgent.getNpcOwner().isAlive()) if (aiAgent.isPlayerGuard() && aiAgent.npcOwner != null && !aiAgent.npcOwner.isAlive())
return; return;
if (System.currentTimeMillis() > aiAgent.getDeathTime() + spawnTime) { if (System.currentTimeMillis() > aiAgent.deathTime + spawnTime) {
aiAgent.respawn(); aiAgent.respawn();
aiAgent.setState(STATE.Idle); aiAgent.state = STATE.Idle;
} }
} }
private static void retaliate(Mob aiAgent) { private static void retaliate(Mob aiAgent) {
if (aiAgent.getCombatTarget() == null) if (aiAgent.getCombatTarget() == null)
aiAgent.setState(STATE.Awake); aiAgent.state = STATE.Awake;
//out of range to attack move //out of range to attack move
if (!MovementUtilities.canMove(aiAgent)) { if (!MovementUtilities.canMove(aiAgent)) {
aiAgent.setState(STATE.Attack); aiAgent.state = STATE.Attack;
return; return;
} }
aiAgent.setState(STATE.Attack); aiAgent.state = STATE.Attack;
//lets make mobs ai less twitchy, Don't call another movement until mob reaches it's destination. //lets make mobs ai less twitchy, Don't call another movement until mob reaches it's destination.
if (aiAgent.isMoving()) if (aiAgent.isMoving())
@ -1730,7 +1729,7 @@ public class MobileFSM {
Zone mobCamp = mob.getParentZone(); Zone mobCamp = mob.getParentZone();
for (Mob mob1 : mobCamp.zoneMobSet) { for (Mob mob1 : mobCamp.zoneMobSet) {
if (mob1.getMobBase().getFlags().contains(Enum.MobFlagType.RESPONDSTOCALLSFORHELP)) { if (mob1.getMobBase().getFlags().contains(Enum.MobFlagType.RESPONDSTOCALLSFORHELP)) {
if (mob1.getState() == STATE.Awake) { if (mob1.state == STATE.Awake) {
if (CombatUtilities.inRange2D(mob, mob1, mob.getAggroRange()) == true) { if (CombatUtilities.inRange2D(mob, mob1, mob.getAggroRange()) == true) {
MovementUtilities.moveToLocation(mob1, mob.getLoc(), 0); MovementUtilities.moveToLocation(mob1, mob.getLoc(), 0);
} }
@ -1745,14 +1744,14 @@ public class MobileFSM {
mob.setCombatTarget(null); mob.setCombatTarget(null);
mob.setAggroTargetID(0); mob.setAggroTargetID(0);
mob.setWalkingHome(false); mob.setWalkingHome(false);
mob.setState(STATE.Home); mob.state = STATE.Home;
return; return;
} }
mob.updateMovementState(); mob.updateMovementState();
mob.updateLocation(); mob.updateLocation();
if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(), mob.getRange()) == true) { if(CombatUtilities.inRange2D(mob,mob.getCombatTarget(), mob.getRange()) == true) {
MovementUtilities.moveToLocation(mob, mob.getLoc(), 0); MovementUtilities.moveToLocation(mob, mob.getLoc(), 0);
mob.setState(STATE.Attack); mob.state = STATE.Attack;
} }
else {//if (mob.isMoving() == false){ else {//if (mob.isMoving() == false){
if(mob.getRange() > 15) { if(mob.getRange() > 15) {

4
src/engine/ai/utilities/MovementUtilities.java

@ -40,10 +40,10 @@ public class MovementUtilities {
if (agent.getContract() != null) if (agent.getContract() != null)
guardCaptain = agent; guardCaptain = agent;
else else
guardCaptain = (Mob) agent.getNpcOwner(); guardCaptain = (Mob) agent.npcOwner;
if (guardCaptain != null){ if (guardCaptain != null){
Building barracks = guardCaptain.getBuilding(); Building barracks = guardCaptain.building;
if (barracks != null){ if (barracks != null){
City city = barracks.getCity(); City city = barracks.getCity();

7
src/engine/db/handlers/dbMobHandler.java

@ -10,6 +10,7 @@
package engine.db.handlers; package engine.db.handlers;
import engine.ai.MobileFSM.STATE; import engine.ai.MobileFSM.STATE;
import engine.gameManager.NPCManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.objects.Mob; import engine.objects.Mob;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
@ -118,7 +119,7 @@ public class dbMobHandler extends dbHandlerBase {
while (rs.next()) { while (rs.next()) {
int mobBaseID = rs.getInt("mobBaseID"); int mobBaseID = rs.getInt("mobBaseID");
String name = rs.getString("name"); String name = rs.getString("name");
Mob toCreate = captain.createGuardMob(mobBaseID, captain.getGuild(), captain.getParentZone(), captain.getBuilding().getLoc(), captain.getLevel(),name); Mob toCreate = NPCManager.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(),name);
if (toCreate == null) if (toCreate == null)
return; return;
@ -127,7 +128,7 @@ public class dbMobHandler extends dbHandlerBase {
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
toCreate.setState(STATE.Respawn); toCreate.state = STATE.Respawn;
} }
} }
@ -241,7 +242,7 @@ public class dbMobHandler extends dbHandlerBase {
worldDelta = worldDelta.subtract(new Vector3fImmutable(sourceZone.getAbsX(), sourceZone.getAbsY(), sourceZone.getAbsZ())); worldDelta = worldDelta.subtract(new Vector3fImmutable(sourceZone.getAbsX(), sourceZone.getAbsY(), sourceZone.getAbsZ()));
newMobile = Mob.createMob(mobile.getLoadID(), newMobile = Mob.createMob(mobile.getLoadID(),
mobile.getLoc().add(worldDelta), null, true, targetZone, mobile.getBuilding(), 0); mobile.getLoc().add(worldDelta), null, true, targetZone, mobile.building, 0);
if (newMobile != null) { if (newMobile != null) {
newMobile.updateDatabase(); newMobile.updateDatabase();

2
src/engine/devcmd/cmds/InfoCmd.java

@ -449,7 +449,7 @@ public class InfoCmd extends AbstractDevCmd {
output += StringUtils.addWS("isAlive: " output += StringUtils.addWS("isAlive: "
+ targetMob.isAlive(), 20); + targetMob.isAlive(), 20);
output += newline; output += newline;
output += "Mob State: " +targetMob.getState().name(); output += "Mob State: " + targetMob.state.name();
output += newline; output += newline;
output += "Speed : " + targetMob.getSpeed(); output += "Speed : " + targetMob.getSpeed();

4
src/engine/gameManager/BuildingManager.java

@ -260,7 +260,7 @@ public enum BuildingManager {
if (slottedNPC.getObjectType() == Enum.GameObjectType.NPC) if (slottedNPC.getObjectType() == Enum.GameObjectType.NPC)
((NPC) slottedNPC).remove(); ((NPC) slottedNPC).remove();
else if (slottedNPC.getObjectType() == Enum.GameObjectType.Mob) else if (slottedNPC.getObjectType() == Enum.GameObjectType.Mob)
((Mob) slottedNPC).remove(building); NPCManager.removeMobileFromBuilding(((Mob) slottedNPC), building);
} }
return; return;
} }
@ -285,7 +285,7 @@ public enum BuildingManager {
else else
building.getHirelings().remove(npc); building.getHirelings().remove(npc);
} else if (mob != null) { } else if (mob != null) {
if (!mob.remove(building)) if (!NPCManager.removeMobileFromBuilding(mob, building))
Logger.error("Failed to remove npc " + npc.getObjectUUID() Logger.error("Failed to remove npc " + npc.getObjectUUID()
+ "from Building " + building.getObjectUUID()); + "from Building " + building.getObjectUUID());
else else

16
src/engine/gameManager/CombatManager.java

@ -183,8 +183,8 @@ public enum CombatManager {
//set sources target //set sources target
pet.setCombatTarget(target); pet.setCombatTarget(target);
pet.setState(STATE.Attack); pet.state = STATE.Attack;
// setFirstHitCombatTarget(player,target); // setFirstHitCombatTarget(player,target);
//put in combat if not already //put in combat if not already
if (!pet.isCombat()) if (!pet.isCombat())
@ -691,8 +691,8 @@ public enum CombatManager {
count++; count++;
mob.setCombatTarget(ac); mob.setCombatTarget(ac);
mob.setState(STATE.Attack); mob.state = STATE.Attack;
} }
} }
} }
} }
@ -1339,8 +1339,8 @@ public enum CombatManager {
Mob pet = ((PlayerCharacter) tarAc).getPet(); Mob pet = ((PlayerCharacter) tarAc).getPet();
if (pet != null && pet.assist() && pet.getCombatTarget() == null) { if (pet != null && pet.assist() && pet.getCombatTarget() == null) {
pet.setCombatTarget(ac); pet.setCombatTarget(ac);
pet.setState(STATE.Retaliate); pet.state = STATE.Retaliate;
} }
} }
//Handle Mob Retaliate. //Handle Mob Retaliate.
@ -1351,9 +1351,9 @@ public enum CombatManager {
if (ac.getObjectType() == GameObjectType.Mob && retaliater.isSiege()) if (ac.getObjectType() == GameObjectType.Mob && retaliater.isSiege())
return; return;
retaliater.setCombatTarget(ac); retaliater.setCombatTarget(ac);
retaliater.setState(STATE.Retaliate); retaliater.state = STATE.Retaliate;
} }
} }
public static void handleDamageShields(AbstractCharacter ac, AbstractCharacter target, float damage) { public static void handleDamageShields(AbstractCharacter ac, AbstractCharacter target, float damage) {

314
src/engine/gameManager/NPCManager.java

@ -1,7 +1,15 @@
package engine.gameManager; package engine.gameManager;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM;
import engine.math.Vector3fImmutable;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.msg.PetMsg;
import engine.objects.*; import engine.objects.*;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,10 +20,8 @@ public enum NPCManager {
NPC_MANAGER; NPC_MANAGER;
public static HashMap<Integer, ArrayList<EquipmentSetEntry>> _equipmentSetMap = new HashMap<>(); public static HashMap<Integer, ArrayList<EquipmentSetEntry>> _equipmentSetMap = new HashMap<>();
public static HashMap<Integer, ArrayList<Integer>> _runeSetMap = new HashMap<>(); public static HashMap<Integer, ArrayList<Integer>> _runeSetMap = new HashMap<>();
public static HashMap<Integer, ArrayList<BootySetEntry>> _bootySetMap = new HashMap<>(); public static HashMap<Integer, ArrayList<BootySetEntry>> _bootySetMap = new HashMap<>();
public static void LoadAllEquipmentSets() { public static void LoadAllEquipmentSets() {
_equipmentSetMap = DbManager.ItemBaseQueries.LOAD_EQUIPMENT_FOR_NPC_AND_MOBS(); _equipmentSetMap = DbManager.ItemBaseQueries.LOAD_EQUIPMENT_FOR_NPC_AND_MOBS();
} }
@ -33,7 +39,7 @@ public enum NPCManager {
// Early exit // Early exit
if (mob.runeSetID == 0) if (mob.runeSetID == 0)
return;; return;
//Apply all rune effects. //Apply all rune effects.
@ -67,7 +73,7 @@ public enum NPCManager {
// Race runes are in the runeset but not in runebase for some reason // Race runes are in the runeset but not in runebase for some reason
if (sourceRune == null) if (sourceRune == null)
return;; return;
for (MobBaseEffects mbe : sourceRune.getEffectsList()) { for (MobBaseEffects mbe : sourceRune.getEffectsList()) {
@ -106,4 +112,304 @@ public enum NPCManager {
} }
} }
public static void dismissNecroPet(Mob necroPet, boolean updateOwner) {
necroPet.state = MobileFSM.STATE.Disabled;
necroPet.combatTarget = null;
necroPet.hasLoot = false;
if (necroPet.parentZone != null)
necroPet.parentZone.zoneMobSet.remove(necroPet);
try {
necroPet.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
necroPet.playerAgroMap.clear();
WorldGrid.RemoveWorldObject(necroPet);
DbManager.removeFromCache(necroPet);
PlayerCharacter petOwner = necroPet.getOwner();
if (petOwner != null) {
necroPet.setOwner(null);
petOwner.setPet(null);
if (updateOwner == false)
return;
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
public static void auditNecroPets(PlayerCharacter player) {
int removeIndex = 0;
while (player.necroPets.size() >= 10) {
if (removeIndex == player.necroPets.size())
break;
Mob necroPet = player.necroPets.get(removeIndex);
if (necroPet == null) {
removeIndex++;
continue;
}
dismissNecroPet(necroPet, true);
player.necroPets.remove(necroPet);
removeIndex++;
}
}
public static void resetNecroPets(PlayerCharacter player) {
for (Mob necroPet : player.necroPets)
if (necroPet.isPet())
necroPet.setMob();
}
public static void spawnNecroPet(PlayerCharacter playerCharacter, Mob mob) {
if (mob == null)
return;
if (mob.getMobBaseID() != 12021 && mob.getMobBaseID() != 12022)
return;
auditNecroPets(playerCharacter);
resetNecroPets(playerCharacter);
playerCharacter.necroPets.add(mob);
}
public static void dismissNecroPets(PlayerCharacter playerCharacter) {
if (playerCharacter.necroPets.isEmpty())
return;
for (Mob necroPet : playerCharacter.necroPets) {
try {
dismissNecroPet(necroPet, true);
} catch (Exception e) {
necroPet.state = MobileFSM.STATE.Disabled;
Logger.error(e);
}
}
playerCharacter.necroPets.clear();
}
public static synchronized Mob createGuardMob(Mob guardCaptain, Guild guild, Zone parent, Vector3fImmutable loc, short level, String pirateName) {
MobBase minionMobBase;
Mob mob;
int maxSlots = 1;
switch (guardCaptain.getRank()) {
case 1:
case 2:
maxSlots = 1;
break;
case 3:
maxSlots = 2;
break;
case 4:
case 5:
maxSlots = 3;
break;
case 6:
maxSlots = 4;
break;
case 7:
maxSlots = 5;
break;
default:
maxSlots = 1;
}
if (guardCaptain.siegeMinionMap.size() == maxSlots)
return null;
minionMobBase = guardCaptain.mobBase;
if (minionMobBase == null)
return null;
mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, true);
mob.despawned = true;
mob.setLevel(level);
//grab equipment and name from minionbase.
if (guardCaptain.contract != null) {
Enum.MinionType minionType = Enum.MinionType.ContractToMinionMap.get(guardCaptain.contract.getContractID());
if (minionType != null) {
mob.equipmentSetID = minionType.getEquipSetID();
String rank = "";
if (guardCaptain.getRank() < 3)
rank = MBServerStatics.JUNIOR;
else if (guardCaptain.getRank() < 6)
rank = "";
else if (guardCaptain.getRank() == 6)
rank = MBServerStatics.VETERAN;
else
rank = MBServerStatics.ELITE;
if (rank.isEmpty())
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + minionType.getName();
else
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + rank + " " + minionType.getName();
}
}
if (parent != null)
mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ);
mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks());
// mob.setMob();
mob.isPlayerGuard = true;
mob.setParentZone(parent);
DbManager.addToCache(mob);
mob.runAfterLoad();
RuneBase guardRune = RuneBase.getRuneBase(252621);
for (MobBaseEffects mbe : guardRune.getEffectsList()) {
EffectsBase eb = PowersManager.getEffectByToken(mbe.getToken());
if (eb == null) {
Logger.info("EffectsBase Null for Token " + mbe.getToken());
continue;
}
//check to upgrade effects if needed.
if (mob.effects.containsKey(Integer.toString(eb.getUUID()))) {
if (mbe.getReqLvl() > (int) mob.level) {
continue;
}
Effect eff = mob.effects.get(Integer.toString(eb.getUUID()));
if (eff == null)
continue;
//Current effect is a higher rank, dont apply.
if (eff.getTrains() > mbe.getRank())
continue;
//new effect is of a higher rank. remove old effect and apply new one.
eff.cancelJob();
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
} else {
if (mbe.getReqLvl() > (int) mob.level)
continue;
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
}
}
int slot = 0;
slot += guardCaptain.siegeMinionMap.size() + 1;
guardCaptain.siegeMinionMap.put(mob, slot);
mob.setInBuildingLoc(guardCaptain.building, guardCaptain);
mob.setBindLoc(loc.add(mob.inBuildingLoc));
mob.deathTime = System.currentTimeMillis();
mob.spawnTime = 900;
mob.npcOwner = guardCaptain;
mob.state = MobileFSM.STATE.Respawn;
return mob;
}
public static void removeSiegeMinions(Mob mobile) {
for (Mob toRemove : mobile.siegeMinionMap.keySet()) {
toRemove.state = MobileFSM.STATE.Disabled;
if (mobile.isMoving()) {
mobile.stopMovement(mobile.getLoc());
mobile.state = MobileFSM.STATE.Disabled;
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
}
try {
toRemove.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
WorldGrid.RemoveWorldObject(toRemove);
WorldGrid.removeObject(toRemove);
DbManager.removeFromCache(toRemove);
PlayerCharacter petOwner = toRemove.getOwner();
if (petOwner != null) {
petOwner.setPet(null);
toRemove.setOwner(null);
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
}
public static boolean removeMobileFromBuilding(Mob mobile, Building building) {
// Remove npc from it's building
mobile.state = MobileFSM.STATE.Disabled;
try {
mobile.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (mobile.parentZone != null)
mobile.parentZone.zoneMobSet.remove(mobile);
if (building != null) {
building.getHirelings().remove(mobile);
removeSiegeMinions(mobile);
}
// Delete npc from database
if (DbManager.MobQueries.DELETE_MOB(mobile) == 0)
return false;
// Remove npc from the simulation
mobile.removeFromCache();
DbManager.removeFromCache(mobile);
WorldGrid.RemoveWorldObject(mobile);
WorldGrid.removeObject(mobile);
return true;
}
} }

8
src/engine/net/client/ClientMessagePump.java

@ -28,7 +28,6 @@ import engine.net.client.msg.*;
import engine.net.client.msg.chat.AbstractChatMsg; import engine.net.client.msg.chat.AbstractChatMsg;
import engine.net.client.msg.commands.ClientAdminCommandMsg; import engine.net.client.msg.commands.ClientAdminCommandMsg;
import engine.objects.*; import engine.objects.*;
import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.session.Session; import engine.session.Session;
@ -37,7 +36,6 @@ import org.pmw.tinylog.Logger;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -2028,7 +2026,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (pet.getCombatTarget() == null) if (pet.getCombatTarget() == null)
return; return;
pet.setState(STATE.Attack); pet.state = STATE.Attack;
} }
protected static void petCmd(PetCmdMsg msg, ClientConnection conn) throws MsgSendException { protected static void petCmd(PetCmdMsg msg, ClientConnection conn) throws MsgSendException {
@ -2046,7 +2044,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (!pet.isAlive()) if (!pet.isAlive())
return; return;
if (pet.getState() == STATE.Disabled) if (pet.state == STATE.Disabled)
return; return;
int type = msg.getType(); int type = msg.getType();
@ -2054,7 +2052,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (type == 1) { //stop attack if (type == 1) { //stop attack
pet.setCombatTarget(null); pet.setCombatTarget(null);
pc.setCombat(false); pc.setCombat(false);
pet.setState(STATE.Awake); pet.state = STATE.Awake;
} }
else if (type == 2) { //dismiss else if (type == 2) { //dismiss

19
src/engine/net/client/handlers/MinionTrainingMsgHandler.java

@ -7,6 +7,7 @@ import engine.ai.MobileFSM;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.NPCManager;
import engine.gameManager.SessionManager; import engine.gameManager.SessionManager;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -66,8 +67,8 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (!npc.getSiegeMinionMap().containsKey(toRemove)) if (!npc.getSiegeMinionMap().containsKey(toRemove))
return true; return true;
toRemove.setState(MobileFSM.STATE.Disabled); toRemove.state = MobileFSM.STATE.Disabled;
npc.getSiegeMinionMap().remove(toRemove); npc.getSiegeMinionMap().remove(toRemove);
//toRemove.disableIntelligence(); //toRemove.disableIntelligence();
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
@ -159,8 +160,8 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
toCreate.setSpawnTime(60 * 15); toCreate.setSpawnTime(60 * 15);
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + (60 * 15 * 1000)); toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + (60 * 15 * 1000));
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
toCreate.setState(MobileFSM.STATE.Respawn); toCreate.state = MobileFSM.STATE.Respawn;
} }
} }
ManageNPCMsg mnm = new ManageNPCMsg(npc); ManageNPCMsg mnm = new ManageNPCMsg(npc);
@ -198,8 +199,8 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.getMobBaseID(), npc.getSiegeMinionMap().get(toRemove))) if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.getMobBaseID(), npc.getSiegeMinionMap().get(toRemove)))
return true; return true;
toRemove.setState(MobileFSM.STATE.Disabled); toRemove.state = MobileFSM.STATE.Disabled;
npc.getSiegeMinionMap().remove(toRemove); npc.getSiegeMinionMap().remove(toRemove);
//toRemove.disableIntelligence(); //toRemove.disableIntelligence();
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
@ -283,7 +284,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1)) if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1))
return true; return true;
Mob toCreate = npc.createGuardMob(mobBase, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName); Mob toCreate = NPCManager.createGuardMob(npc, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName);
if (toCreate == null) if (toCreate == null)
return true; return true;
@ -292,8 +293,8 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (toCreate != null) { if (toCreate != null) {
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
toCreate.setState(MobileFSM.STATE.Respawn); toCreate.state = MobileFSM.STATE.Respawn;
} }
} }
ManageNPCMsg mnm = new ManageNPCMsg(npc); ManageNPCMsg mnm = new ManageNPCMsg(npc);

7
src/engine/net/client/handlers/OrderNPCMsgHandler.java

@ -6,6 +6,7 @@ import engine.Enum.ProfitType;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.NPCManager;
import engine.gameManager.SessionManager; import engine.gameManager.SessionManager;
import engine.math.FastMath; import engine.math.FastMath;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
@ -209,7 +210,7 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if (building.getHirelings().containsKey(mob) == false) if (building.getHirelings().containsKey(mob) == false)
return true; return true;
if (mob.remove(building) == false) { if (NPCManager.removeMobileFromBuilding(mob, building) == false) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true; return true;
} }
@ -439,9 +440,9 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
case Mob: case Mob:
Mob mob = (Mob) abstractCharacter; Mob mob = (Mob) abstractCharacter;
building = mob.getBuilding(); building = mob.building;
if (mob.getBuilding() == null) if (mob.building == null)
return; return;
City mobCity = building.getCity(); City mobCity = building.getCity();

2
src/engine/objects/AbstractCharacter.java

@ -84,7 +84,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
protected float manaMax; // Health/Mana/Stamina protected float manaMax; // Health/Mana/Stamina
protected AtomicBoolean isAlive = new AtomicBoolean(true); protected AtomicBoolean isAlive = new AtomicBoolean(true);
protected Resists resists = new Resists("Genric"); protected Resists resists = new Resists("Genric");
protected AbstractWorldObject combatTarget; public AbstractWorldObject combatTarget;
protected ConcurrentHashMap<String, JobContainer> timers; protected ConcurrentHashMap<String, JobContainer> timers;
protected ConcurrentHashMap<String, Long> timestamps; protected ConcurrentHashMap<String, Long> timestamps;
protected int atrHandOne; protected int atrHandOne;

4
src/engine/objects/AbstractIntelligenceAgent.java

@ -204,8 +204,8 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter {
WorldGrid.RemoveWorldObject(this); WorldGrid.RemoveWorldObject(this);
if (this.getObjectType() == GameObjectType.Mob){ if (this.getObjectType() == GameObjectType.Mob){
((Mob)this).setState(STATE.Disabled); ((Mob)this).state = STATE.Disabled;
if (((Mob)this).getParentZone() != null) if (((Mob)this).getParentZone() != null)
((Mob)this).getParentZone().zoneMobSet.remove(this); ((Mob)this).getParentZone().zoneMobSet.remove(this);
} }

305
src/engine/objects/Mob.java

@ -11,7 +11,6 @@ package engine.objects;
import engine.Enum; import engine.Enum;
import engine.Enum.*; import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM; import engine.ai.MobileFSM;
import engine.ai.MobileFSM.STATE; import engine.ai.MobileFSM.STATE;
@ -32,7 +31,6 @@ import engine.net.client.msg.ManageCityAssetsMsg;
import engine.net.client.msg.PetMsg; import engine.net.client.msg.PetMsg;
import engine.net.client.msg.PlaceAssetMsg; import engine.net.client.msg.PlaceAssetMsg;
import engine.net.client.msg.chat.ChatSystemMsg; import engine.net.client.msg.chat.ChatSystemMsg;
import engine.powers.EffectsBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -57,7 +55,7 @@ public class Mob extends AbstractIntelligenceAgent {
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//mob specific //mob specific
private final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>(); public final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>();
public long nextCastTime = 0; public long nextCastTime = 0;
public long nextCallForHelp = 0; public long nextCallForHelp = 0;
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
@ -70,42 +68,42 @@ public class Mob extends AbstractIntelligenceAgent {
protected boolean isMob; protected boolean isMob;
public MobBase mobBase; public MobBase mobBase;
protected float spawnRadius; protected float spawnRadius;
protected int spawnTime; public int spawnTime;
//used by static mobs //used by static mobs
protected int parentZoneID; protected int parentZoneID;
protected Zone parentZone; public Zone parentZone;
protected float statLat; protected float statLat;
protected float statLon; protected float statLon;
protected float statAlt; protected float statAlt;
protected Building building; public Building building;
public Contract contract; public Contract contract;
private int currentID; private int currentID;
private int ownerUID = 0; //only used by pets private int ownerUID = 0; //only used by pets
private boolean hasLoot = false; public boolean hasLoot = false;
private AbstractWorldObject fearedObject = null; private AbstractWorldObject fearedObject = null;
private int buildingID; private int buildingID;
private boolean isSiege = false; private boolean isSiege = false;
public boolean isPlayerGuard = false; public boolean isPlayerGuard = false;
private long timeToSpawnSiege; private long timeToSpawnSiege;
private AbstractCharacter npcOwner; public AbstractCharacter npcOwner;
private Vector3fImmutable inBuildingLoc = null; public Vector3fImmutable inBuildingLoc = null;
private boolean noAggro = false; private boolean noAggro = false;
private STATE state = STATE.Disabled; public STATE state = STATE.Disabled;
private int aggroTargetID = 0; private int aggroTargetID = 0;
private boolean walkingHome = true; private boolean walkingHome = true;
private long lastAttackTime = 0; private long lastAttackTime = 0;
private long deathTime = 0; public long deathTime = 0;
private final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); public final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private int patrolPointIndex = 0; private int patrolPointIndex = 0;
private int lastMobPowerToken = 0; private int lastMobPowerToken = 0;
private HashMap<Integer, MobEquipment> equip = null; private HashMap<Integer, MobEquipment> equip = null;
private String nameOverride = ""; public String nameOverride = "";
private Regions lastRegion = null; private Regions lastRegion = null;
private long despawnTime = 0; private long despawnTime = 0;
private DeferredPowerJob weaponPower; private DeferredPowerJob weaponPower;
private DateTime upgradeDateTime = null; private DateTime upgradeDateTime = null;
private boolean lootSync = false; private boolean lootSync = false;
private int equipmentSetID = 0; public int equipmentSetID = 0;
public int runeSetID = 0; public int runeSetID = 0;
public int bootySetID = 0; public int bootySetID = 0;
@ -1950,10 +1948,6 @@ public class Mob extends AbstractIntelligenceAgent {
} }
public Vector3fImmutable getInBuildingLoc() {
return inBuildingLoc;
}
public ItemBase getWeaponItemBase(boolean mainHand) { public ItemBase getWeaponItemBase(boolean mainHand) {
if (this.equipmentSetID != 0) { if (this.equipmentSetID != 0) {
@ -2070,10 +2064,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.timeToSpawnSiege = timeToSpawnSiege; this.timeToSpawnSiege = timeToSpawnSiege;
} }
public AbstractCharacter getNpcOwner() {
return npcOwner;
}
public void setNpcOwner(AbstractCharacter npcOwner) { public void setNpcOwner(AbstractCharacter npcOwner) {
this.npcOwner = npcOwner; this.npcOwner = npcOwner;
} }
@ -2106,81 +2096,6 @@ public class Mob extends AbstractIntelligenceAgent {
} }
} }
public boolean remove(Building building) {
// Remove npc from it's building
this.state = STATE.Disabled;
try {
this.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (this.parentZone != null)
this.parentZone.zoneMobSet.remove(this);
if (building != null) {
building.getHirelings().remove(this);
this.removeMinions();
}
// Delete npc from database
if (DbManager.MobQueries.DELETE_MOB(this) == 0)
return false;
// Remove npc from the simulation
this.removeFromCache();
DbManager.removeFromCache(this);
WorldGrid.RemoveWorldObject(this);
WorldGrid.removeObject(this);
return true;
}
public void removeMinions() {
for (Mob toRemove : this.siegeMinionMap.keySet()) {
toRemove.state = STATE.Disabled;
if (this.isMoving()) {
this.stopMovement(this.getLoc());
this.state = STATE.Disabled;
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
}
try {
toRemove.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
WorldGrid.RemoveWorldObject(toRemove);
WorldGrid.removeObject(toRemove);
DbManager.removeFromCache(toRemove);
PlayerCharacter petOwner = toRemove.getOwner();
if (petOwner != null) {
petOwner.setPet(null);
toRemove.setOwner(null);
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
}
public void setRank(int newRank) { public void setRank(int newRank) {
DbManager.MobQueries.SET_PROPERTY(this, "mob_level", newRank); DbManager.MobQueries.SET_PROPERTY(this, "mob_level", newRank);
@ -2201,14 +2116,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.noAggro = noAggro; this.noAggro = noAggro;
} }
public STATE getState() {
return state;
}
public void setState(STATE state) {
this.state = state;
}
public int getAggroTargetID() { public int getAggroTargetID() {
return aggroTargetID; return aggroTargetID;
} }
@ -2233,14 +2140,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.lastAttackTime = lastAttackTime; this.lastAttackTime = lastAttackTime;
} }
public ConcurrentHashMap<Integer, Boolean> getPlayerAgroMap() {
return playerAgroMap;
}
public long getDeathTime() {
return deathTime;
}
public void setDeathTime(long deathTime) { public void setDeathTime(long deathTime) {
this.deathTime = deathTime; this.deathTime = deathTime;
} }
@ -2261,10 +2160,6 @@ public class Mob extends AbstractIntelligenceAgent {
return siegeMinionMap; return siegeMinionMap;
} }
public Building getBuilding() {
return this.building;
}
public DateTime getUpgradeDateTime() { public DateTime getUpgradeDateTime() {
lock.readLock().lock(); lock.readLock().lock();
@ -2276,136 +2171,6 @@ public class Mob extends AbstractIntelligenceAgent {
} }
} }
public synchronized Mob createGuardMob(int loadID, Guild guild, Zone parent, Vector3fImmutable loc, short level, String pirateName) {
MobBase minionMobBase;
Mob mob;
int maxSlots = 1;
switch (this.getRank()) {
case 1:
case 2:
maxSlots = 1;
break;
case 3:
maxSlots = 2;
break;
case 4:
case 5:
maxSlots = 3;
break;
case 6:
maxSlots = 4;
break;
case 7:
maxSlots = 5;
break;
default:
maxSlots = 1;
}
if (siegeMinionMap.size() == maxSlots)
return null;
minionMobBase = this.mobBase;
if (minionMobBase == null)
return null;
mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, true);
mob.despawned = true;
mob.setLevel(level);
//grab equipment and name from minionbase.
if (this.contract != null) {
MinionType minionType = MinionType.ContractToMinionMap.get(this.contract.getContractID());
if (minionType != null) {
mob.equipmentSetID = minionType.getEquipSetID();
String rank = "";
if (this.getRank() < 3)
rank = MBServerStatics.JUNIOR;
else if (this.getRank() < 6)
rank = "";
else if (this.getRank() == 6)
rank = MBServerStatics.VETERAN;
else
rank = MBServerStatics.ELITE;
if (rank.isEmpty())
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + minionType.getName();
else
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + rank + " " + minionType.getName();
}
}
if (parent != null)
mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ);
mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks());
// mob.setMob();
mob.isPlayerGuard = true;
mob.setParentZone(parent);
DbManager.addToCache(mob);
mob.runAfterLoad();
RuneBase guardRune = RuneBase.getRuneBase(252621);
for (MobBaseEffects mbe : guardRune.getEffectsList()) {
EffectsBase eb = PowersManager.getEffectByToken(mbe.getToken());
if (eb == null) {
Logger.info("EffectsBase Null for Token " + mbe.getToken());
continue;
}
//check to upgrade effects if needed.
if (mob.effects.containsKey(Integer.toString(eb.getUUID()))) {
if (mbe.getReqLvl() > (int) mob.level) {
continue;
}
Effect eff = mob.effects.get(Integer.toString(eb.getUUID()));
if (eff == null)
continue;
//Current effect is a higher rank, dont apply.
if (eff.getTrains() > mbe.getRank())
continue;
//new effect is of a higher rank. remove old effect and apply new one.
eff.cancelJob();
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
} else {
if (mbe.getReqLvl() > (int) mob.level)
continue;
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
}
}
int slot = 0;
slot += siegeMinionMap.size() + 1;
siegeMinionMap.put(mob, slot);
mob.setInBuildingLoc(this.building, this);
mob.setBindLoc(loc.add(mob.inBuildingLoc));
mob.deathTime = System.currentTimeMillis();
mob.spawnTime = 900;
mob.npcOwner = this;
mob.state = STATE.Respawn;
return mob;
}
public Contract getContract() { public Contract getContract() {
return contract; return contract;
} }
@ -2472,7 +2237,7 @@ public class Mob extends AbstractIntelligenceAgent {
try { try {
building = this.getBuilding(); building = this.building;
// Cannot upgrade an npc not within a building // Cannot upgrade an npc not within a building
@ -2550,7 +2315,7 @@ public class Mob extends AbstractIntelligenceAgent {
if (!building.getHirelings().containsKey(this)) if (!building.getHirelings().containsKey(this))
return; return;
if (!this.remove(building)) { if (!NPCManager.removeMobileFromBuilding(this, building)) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return; return;
} }
@ -2607,7 +2372,7 @@ public class Mob extends AbstractIntelligenceAgent {
WorldGrid.RemoveWorldObject(this); WorldGrid.RemoveWorldObject(this);
DbManager.removeFromCache(this); DbManager.removeFromCache(this);
if (this.getObjectType() == GameObjectType.Mob) { if (this.getObjectType() == GameObjectType.Mob) {
this.setState(STATE.Disabled); this.state = STATE.Disabled;
if (this.getParentZone() != null) if (this.getParentZone() != null)
this.getParentZone().zoneMobSet.remove(this); this.getParentZone().zoneMobSet.remove(this);
} }
@ -2639,44 +2404,4 @@ public class Mob extends AbstractIntelligenceAgent {
} }
} }
public void dismissNecroPet(boolean updateOwner) {
this.state = STATE.Disabled;
this.combatTarget = null;
this.hasLoot = false;
if (this.parentZone != null)
this.parentZone.zoneMobSet.remove(this);
try {
this.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
this.playerAgroMap.clear();
WorldGrid.RemoveWorldObject(this);
DbManager.removeFromCache(this);
// YEAH BONUS CODE! THANKS UNNAMED ASSHOLE!
//WorldServer.removeObject(this);
//WorldGrid.INSTANCE.removeWorldObject(this);
//owner.getPet().disableIntelligence();
PlayerCharacter petOwner = this.getOwner();
if (petOwner != null) {
this.setOwner(null);
petOwner.setPet(null);
if (updateOwner == false)
return;
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
} }

8
src/engine/objects/NPC.java

@ -797,7 +797,7 @@ public class NPC extends AbstractCharacter {
for (Mob toRemove : this.siegeMinionMap.keySet()) { for (Mob toRemove : this.siegeMinionMap.keySet()) {
toRemove.setState(STATE.Disabled); toRemove.state = STATE.Disabled;
try { try {
toRemove.clearEffects(); toRemove.clearEffects();
@ -1461,14 +1461,14 @@ public class NPC extends AbstractCharacter {
siegeMinionMap.put(mob, slot); siegeMinionMap.put(mob, slot);
mob.setInBuildingLoc(this.building, this); mob.setInBuildingLoc(this.building, this);
Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, mob.getInBuildingLoc()); Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, mob.inBuildingLoc);
mob.setBindLoc(buildingWorldLoc); mob.setBindLoc(buildingWorldLoc);
mob.setLoc(buildingWorldLoc); mob.setLoc(buildingWorldLoc);
mob.setSpawnTime(10); mob.setSpawnTime(10);
mob.setNpcOwner(this); mob.setNpcOwner(this);
mob.setState(STATE.Awake); mob.state = STATE.Awake;
return mob; return mob;
} }

72
src/engine/objects/PlayerCharacter.java

@ -626,7 +626,7 @@ public class PlayerCharacter extends AbstractCharacter {
if (this.pet != null) if (this.pet != null)
this.dismissPet(); this.dismissPet();
this.dismissNecroPets(); NPCManager.dismissNecroPets(this);
// remove flight job. // remove flight job.
this.setTakeOffTime(0); this.setTakeOffTime(0);
@ -1586,77 +1586,13 @@ public class PlayerCharacter extends AbstractCharacter {
return this.pet; return this.pet;
} }
public Mob getNecroPet(int i) {
return this.necroPets.get(i);
}
public static void auditNecroPets(PlayerCharacter player){
int removeIndex =0;
while(player.necroPets.size() >= 10){
if (removeIndex == player.necroPets.size())
break;
Mob toRemove = player.necroPets.get(removeIndex);
if (toRemove == null){
removeIndex++;
continue;
}
toRemove.dismissNecroPet(true);
player.necroPets.remove(toRemove);
removeIndex++;
}
}
public static void resetNecroPets(PlayerCharacter player){
for (Mob necroPet: player.necroPets)
if (necroPet.isPet())
necroPet.setMob();
}
public void spawnNecroPet(Mob mob) {
if (mob == null)
return;
if (mob.getMobBaseID() != 12021 && mob.getMobBaseID() != 12022)
return;
PlayerCharacter.auditNecroPets(this);
PlayerCharacter.resetNecroPets(this);
this.necroPets.add(mob);
}
public void dismissPet() { public void dismissPet() {
if (this.pet != null) { if (this.pet != null) {
this.pet.dismiss(); this.pet.dismiss();
this.pet = null; this.pet = null;
} }
} }
public void dismissNecroPets() {
if (this.necroPets.isEmpty())
return;
for (Mob necroPet: this.necroPets){
try{
necroPet.dismissNecroPet(true);
}catch(Exception e){
necroPet.setState(STATE.Disabled);
Logger.error(e);
}
}
this.necroPets.clear();
}
//called to verify player has correct item equipped for casting. //called to verify player has correct item equipped for casting.
public boolean validEquip(int slot, String type) { public boolean validEquip(int slot, String type) {
@ -4644,7 +4580,7 @@ public void dismissNecroPets() {
if (!currentPet.isSiege()) { if (!currentPet.isSiege()) {
currentPet.setCombatTarget(null); currentPet.setCombatTarget(null);
currentPet.setState(STATE.Disabled); currentPet.state = STATE.Disabled;
if (currentPet.getParentZone() != null) if (currentPet.getParentZone() != null)
@ -4655,7 +4591,7 @@ public void dismissNecroPets() {
}catch(Exception e){ }catch(Exception e){
Logger.error( e.getMessage()); Logger.error( e.getMessage());
} }
currentPet.getPlayerAgroMap().clear(); currentPet.playerAgroMap.clear();
WorldGrid.RemoveWorldObject(currentPet); WorldGrid.RemoveWorldObject(currentPet);
DbManager.removeFromCache(currentPet); DbManager.removeFromCache(currentPet);

4
src/engine/powers/poweractions/ClearAggroPowerAction.java

@ -32,8 +32,8 @@ public class ClearAggroPowerAction extends AbstractPowerAction {
protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) {
if (awo != null && awo.getObjectType() == GameObjectType.Mob){ if (awo != null && awo.getObjectType() == GameObjectType.Mob){
((Mob)awo).setNoAggro(true); ((Mob)awo).setNoAggro(true);
((Mob)awo).setState(STATE.Patrol); ((Mob)awo).state = STATE.Patrol;
} }

4
src/engine/powers/poweractions/ClearNearbyAggroPowerAction.java

@ -31,8 +31,8 @@ public class ClearNearbyAggroPowerAction extends AbstractPowerAction {
@Override @Override
protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) { protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) {
if (source.getObjectType() == GameObjectType.Mob){ if (source.getObjectType() == GameObjectType.Mob){
((Mob)source).setState(STATE.Patrol); ((Mob)source).state = STATE.Patrol;
} }
} }

19
src/engine/powers/poweractions/CreateMobPowerAction.java

@ -13,6 +13,7 @@ import engine.Enum;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM.STATE; import engine.ai.MobileFSM.STATE;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.NPCManager;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.Dispatch; import engine.net.Dispatch;
@ -81,13 +82,13 @@ public class CreateMobPowerAction extends AbstractPowerAction {
if(currentPet!= null && !currentPet.isNecroPet() && !currentPet.isSiege()) { if(currentPet!= null && !currentPet.isNecroPet() && !currentPet.isSiege()) {
DbManager.removeFromCache(currentPet); DbManager.removeFromCache(currentPet);
WorldGrid.RemoveWorldObject(currentPet); WorldGrid.RemoveWorldObject(currentPet);
currentPet.setState(STATE.Disabled); currentPet.state = STATE.Disabled;
currentPet.setCombatTarget(null); currentPet.setCombatTarget(null);
if (currentPet.getParentZone() != null) if (currentPet.getParentZone() != null)
currentPet.getParentZone().zoneMobSet.remove(currentPet); currentPet.getParentZone().zoneMobSet.remove(currentPet);
currentPet.getPlayerAgroMap().clear(); currentPet.playerAgroMap.clear();
try { try {
currentPet.clearEffects(); currentPet.clearEffects();
@ -107,7 +108,7 @@ public class CreateMobPowerAction extends AbstractPowerAction {
//remove 10th pet //remove 10th pet
owner.spawnNecroPet(pet); NPCManager.spawnNecroPet(owner, pet);
} }
else { //is not a necro pet else { //is not a necro pet
@ -115,13 +116,13 @@ public class CreateMobPowerAction extends AbstractPowerAction {
if(!currentPet.isNecroPet() && !currentPet.isSiege()) { if(!currentPet.isNecroPet() && !currentPet.isSiege()) {
DbManager.removeFromCache(currentPet); DbManager.removeFromCache(currentPet);
currentPet.setCombatTarget(null); currentPet.setCombatTarget(null);
currentPet.setState(STATE.Disabled); currentPet.state = STATE.Disabled;
currentPet.setOwner(null); currentPet.setOwner(null);
WorldGrid.RemoveWorldObject(currentPet); WorldGrid.RemoveWorldObject(currentPet);
currentPet.getParentZone().zoneMobSet.remove(currentPet); currentPet.getParentZone().zoneMobSet.remove(currentPet);
currentPet.getPlayerAgroMap().clear(); currentPet.playerAgroMap.clear();
currentPet.clearEffects(); currentPet.clearEffects();
//currentPet.disableIntelligence(); //currentPet.disableIntelligence();
} }
@ -136,8 +137,8 @@ public class CreateMobPowerAction extends AbstractPowerAction {
} }
} }
PlayerCharacter.auditNecroPets(owner); NPCManager.auditNecroPets(owner);
PlayerCharacter.resetNecroPets(owner); NPCManager.resetNecroPets(owner);
} }
} }
/* if(owner.getPet() != null) { /* if(owner.getPet() != null) {

4
src/engine/server/world/WorldServer.java

@ -560,7 +560,7 @@ public class WorldServer {
m.setParentZone(zone); m.setParentZone(zone);
//ADD GUARDS HERE. //ADD GUARDS HERE.
if (m.getBuilding() != null && m.getBuilding().getBlueprint() != null && m.getBuilding().getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK) if (m.building != null && m.building.getBlueprint() != null && m.building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK)
DbManager.MobQueries.LOAD_PATROL_POINTS(m); DbManager.MobQueries.LOAD_PATROL_POINTS(m);
} }
@ -683,7 +683,7 @@ public class WorldServer {
if (player.getPet() != null) if (player.getPet() != null)
player.getPet().dismiss(); player.getPet().dismiss();
player.dismissNecroPets(); NPCManager.dismissNecroPets(player);
// Set player inactive so they quit loading for other players // Set player inactive so they quit loading for other players

Loading…
Cancel
Save