Refactor to separate persistence and write fsm to table.

This commit is contained in:
2023-08-31 08:03:30 -04:00
parent 6641651f3c
commit c8ed04aaaf
5 changed files with 54 additions and 47 deletions
+18 -31
View File
@@ -405,6 +405,8 @@ public class Mob extends AbstractIntelligenceAgent {
Mob mobile = new Mob();
mobile.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET;
mobile.agentType = AIAgentType.MOBILE;
mobile.behaviourType = MobBehaviourType.None;
mobile.loadID = loadID;
mobile.level = (short) level;
@@ -428,18 +430,7 @@ public class Mob extends AbstractIntelligenceAgent {
else
mobile.contractUUID = contract.getContractID();
Mob mob;
mobile.agentType = AIAgentType.GUARD;
try {
mob = DbManager.MobQueries.PERSIST(mobile);
} catch (Exception e) {
Logger.error("SQLException:" + e.getMessage());
mob = null;
}
return mob;
return mobile;
}
public static synchronized Mob createGuardMinion(Mob guardCaptain, short level, String minionName) {
@@ -463,7 +454,6 @@ public class Mob extends AbstractIntelligenceAgent {
minionMobile.guardCaptain = guardCaptain;
minionMobile.spawnTime = (int) (-2.500 * guardCaptain.building.getRank() + 22.5) * 60;
minionMobile.behaviourType = Enum.MobBehaviourType.GuardMinion;
minionMobile.agentType = AIAgentType.GUARD;
minionMobile.isPlayerGuard = true;
minionMobile.guardedCity = guardCaptain.guardedCity;
minionMobile.patrolPoints = guardCaptain.building.patrolPoints;
@@ -1545,33 +1535,30 @@ public class Mob extends AbstractIntelligenceAgent {
else
this.contract = DbManager.ContractQueries.GET_CONTRACT(this.contractUUID);
// Setup mobile AI and equipset for contract
if (this.contract != null) {
// Setup equipset for contract
this.equipmentSetID = this.contract.getEquipmentSet();
// Load AI for guard captains
// Configure AI related values
if (NPC.ISGuardCaptain(contract.getContractID()) || this.contract.getContractID() == 910) { // Guard Dog
this.behaviourType = MobBehaviourType.GuardCaptain;
this.spawnTime = 60 * 15;
this.isPlayerGuard = true;
this.guardedCity = ZoneManager.getCityAtLocation(this.building.getLoc());
switch (this.behaviourType) {
case GuardCaptain:
this.agentType = AIAgentType.GUARDCAPTAIN;
this.spawnTime = 600;
this.guardedCity = ZoneManager.getCityAtLocation(this.building.getLoc());
break;
case GuardWallArcher:
this.gridObjectType = GridObjectType.DYNAMIC;
this.agentType = AIAgentType.GUARDWALLARCHER;
this.spawnTime = 450;
this.guardedCity = ZoneManager.getCityAtLocation(this.building.getLoc());
}
// Load AI for wall archers
if (NPC.ISWallArcher(this.contract)) {
this.gridObjectType = GridObjectType.DYNAMIC;
this.behaviourType = MobBehaviourType.GuardWallArcher;
this.isPlayerGuard = true;
this.spawnTime = 450;
this.guardedCity = ZoneManager.getCityAtLocation(this.building.getLoc());
}
}
// Default to the mobbase for AI if nothing is hte mob field to override.
// Default to the mobbase for AI if nothing is in mob field to override.
if (this.behaviourType == null || this.behaviourType.equals(MobBehaviourType.None))
this.behaviourType = this.getMobBase().fsm;
@@ -1604,7 +1591,7 @@ public class Mob extends AbstractIntelligenceAgent {
// Don't override level for guard minions or pets
if (this.contract == null)
if (!this.agentType.equals(AIAgentType.GUARD) && !this.agentType.equals(AIAgentType.PET))
if (!this.agentType.equals(AIAgentType.GUARDCAPTAIN) && !this.agentType.equals(AIAgentType.PET))
this.level = (short) this.mobBase.getLevel();
//set bonuses