forked from MagicBane/Server
Refactor to separate persistence and write fsm to table.
This commit is contained in:
@@ -2877,10 +2877,11 @@ public class Enum {
|
|||||||
|
|
||||||
public enum AIAgentType {
|
public enum AIAgentType {
|
||||||
MOBILE,
|
MOBILE,
|
||||||
|
GUARDCAPTAIN,
|
||||||
|
GUARDMINION,
|
||||||
|
GUARDWALLARCHER,
|
||||||
PET,
|
PET,
|
||||||
CHARMED,
|
CHARMED,
|
||||||
|
SIEGEENGINE;
|
||||||
SIEGEENGINE,
|
|
||||||
GUARD;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class dbMobHandler extends dbHandlerBase {
|
|||||||
Mob mobile = null;
|
Mob mobile = null;
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
try (Connection connection = DbManager.getConnection();
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||||
|
|
||||||
preparedStatement.setLong(1, toAdd.parentZoneUUID);
|
preparedStatement.setLong(1, toAdd.parentZoneUUID);
|
||||||
preparedStatement.setInt(2, toAdd.loadID);
|
preparedStatement.setInt(2, toAdd.loadID);
|
||||||
@@ -48,6 +48,7 @@ public class dbMobHandler extends dbHandlerBase {
|
|||||||
preparedStatement.setInt(11, toAdd.buildingUUID);
|
preparedStatement.setInt(11, toAdd.buildingUUID);
|
||||||
preparedStatement.setInt(12, toAdd.level);
|
preparedStatement.setInt(12, toAdd.level);
|
||||||
preparedStatement.setString(13, toAdd.firstName);
|
preparedStatement.setString(13, toAdd.firstName);
|
||||||
|
preparedStatement.setString(14, toAdd.behaviourType.toString());
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
|||||||
@@ -530,41 +530,59 @@ public enum BuildingManager {
|
|||||||
else
|
else
|
||||||
rank = 10;
|
rank = 10;
|
||||||
|
|
||||||
Mob mob;
|
Mob mobile;
|
||||||
NPC npc;
|
NPC npc;
|
||||||
|
|
||||||
if (NPC.ISWallArcher(contract)) {
|
if (NPC.ISWallArcher(contract)) {
|
||||||
|
|
||||||
mob = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
mobile = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
||||||
|
|
||||||
if (mob == null)
|
if (mobile == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mob.setLoc(mob.getLoc());
|
// Configure AI.
|
||||||
|
|
||||||
|
mobile.behaviourType = Enum.MobBehaviourType.GuardWallArcher;
|
||||||
|
|
||||||
|
DbManager.MobQueries.PERSIST(mobile);
|
||||||
|
|
||||||
|
mobile.setLoc(mobile.getLoc());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NPC.ISGuardCaptain(contract.getContractID())) {
|
if (NPC.ISGuardCaptain(contract.getContractID())) {
|
||||||
|
|
||||||
mob = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
mobile = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
||||||
|
|
||||||
if (mob == null)
|
if (mobile == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mob.setLoc(mob.getLoc());
|
// Configure AI.
|
||||||
|
|
||||||
|
mobile.behaviourType = Enum.MobBehaviourType.GuardCaptain;
|
||||||
|
|
||||||
|
DbManager.MobQueries.PERSIST(mobile);
|
||||||
|
|
||||||
|
mobile.setLoc(mobile.getLoc());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contract.getContractID() == 910) {
|
if (contract.getContractID() == 910) {
|
||||||
|
|
||||||
//guard dog
|
//guard dog
|
||||||
mob = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
mobile = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank);
|
||||||
|
|
||||||
if (mob == null)
|
if (mobile == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mob.setLoc(mob.getLoc());
|
// Configure AI.
|
||||||
|
|
||||||
|
mobile.behaviourType = Enum.MobBehaviourType.GuardCaptain;
|
||||||
|
|
||||||
|
DbManager.MobQueries.PERSIST(mobile);
|
||||||
|
mobile.setLoc(mobile.getLoc());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1011,14 +1011,14 @@ public class MobAI {
|
|||||||
|
|
||||||
//dont scan self.
|
//dont scan self.
|
||||||
|
|
||||||
if (mob.equals(awoMob) || (mob.agentType.equals(Enum.AIAgentType.GUARD)) == true)
|
if (mob.equals(awoMob) || (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) == true)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Mob aggroMob = (Mob) awoMob;
|
Mob aggroMob = (Mob) awoMob;
|
||||||
|
|
||||||
//don't attack other guards
|
//don't attack other guards
|
||||||
|
|
||||||
if ((aggroMob.agentType.equals(Enum.AIAgentType.GUARD)))
|
if ((aggroMob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (aggroMob.behaviourType.equals(Enum.MobBehaviourType.Pet1))
|
if (aggroMob.behaviourType.equals(Enum.MobBehaviourType.Pet1))
|
||||||
|
|||||||
+18
-31
@@ -405,6 +405,8 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
|
|
||||||
Mob mobile = new Mob();
|
Mob mobile = new Mob();
|
||||||
mobile.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET;
|
mobile.dbID = MBServerStatics.NO_DB_ROW_ASSIGNED_YET;
|
||||||
|
mobile.agentType = AIAgentType.MOBILE;
|
||||||
|
mobile.behaviourType = MobBehaviourType.None;
|
||||||
mobile.loadID = loadID;
|
mobile.loadID = loadID;
|
||||||
mobile.level = (short) level;
|
mobile.level = (short) level;
|
||||||
|
|
||||||
@@ -428,18 +430,7 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
else
|
else
|
||||||
mobile.contractUUID = contract.getContractID();
|
mobile.contractUUID = contract.getContractID();
|
||||||
|
|
||||||
Mob mob;
|
return mobile;
|
||||||
|
|
||||||
mobile.agentType = AIAgentType.GUARD;
|
|
||||||
try {
|
|
||||||
mob = DbManager.MobQueries.PERSIST(mobile);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.error("SQLException:" + e.getMessage());
|
|
||||||
mob = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized Mob createGuardMinion(Mob guardCaptain, short level, String minionName) {
|
public static synchronized Mob createGuardMinion(Mob guardCaptain, short level, String minionName) {
|
||||||
@@ -463,7 +454,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
minionMobile.guardCaptain = guardCaptain;
|
minionMobile.guardCaptain = guardCaptain;
|
||||||
minionMobile.spawnTime = (int) (-2.500 * guardCaptain.building.getRank() + 22.5) * 60;
|
minionMobile.spawnTime = (int) (-2.500 * guardCaptain.building.getRank() + 22.5) * 60;
|
||||||
minionMobile.behaviourType = Enum.MobBehaviourType.GuardMinion;
|
minionMobile.behaviourType = Enum.MobBehaviourType.GuardMinion;
|
||||||
minionMobile.agentType = AIAgentType.GUARD;
|
|
||||||
minionMobile.isPlayerGuard = true;
|
minionMobile.isPlayerGuard = true;
|
||||||
minionMobile.guardedCity = guardCaptain.guardedCity;
|
minionMobile.guardedCity = guardCaptain.guardedCity;
|
||||||
minionMobile.patrolPoints = guardCaptain.building.patrolPoints;
|
minionMobile.patrolPoints = guardCaptain.building.patrolPoints;
|
||||||
@@ -1545,33 +1535,30 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
else
|
else
|
||||||
this.contract = DbManager.ContractQueries.GET_CONTRACT(this.contractUUID);
|
this.contract = DbManager.ContractQueries.GET_CONTRACT(this.contractUUID);
|
||||||
|
|
||||||
// Setup mobile AI and equipset for contract
|
|
||||||
|
|
||||||
if (this.contract != null) {
|
if (this.contract != null) {
|
||||||
|
|
||||||
|
// Setup equipset for contract
|
||||||
this.equipmentSetID = this.contract.getEquipmentSet();
|
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
|
switch (this.behaviourType) {
|
||||||
this.behaviourType = MobBehaviourType.GuardCaptain;
|
case GuardCaptain:
|
||||||
this.spawnTime = 60 * 15;
|
this.agentType = AIAgentType.GUARDCAPTAIN;
|
||||||
this.isPlayerGuard = true;
|
this.spawnTime = 600;
|
||||||
this.guardedCity = ZoneManager.getCityAtLocation(this.building.getLoc());
|
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))
|
if (this.behaviourType == null || this.behaviourType.equals(MobBehaviourType.None))
|
||||||
this.behaviourType = this.getMobBase().fsm;
|
this.behaviourType = this.getMobBase().fsm;
|
||||||
@@ -1604,7 +1591,7 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
// Don't override level for guard minions or pets
|
// Don't override level for guard minions or pets
|
||||||
|
|
||||||
if (this.contract == null)
|
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();
|
this.level = (short) this.mobBase.getLevel();
|
||||||
|
|
||||||
//set bonuses
|
//set bonuses
|
||||||
|
|||||||
Reference in New Issue
Block a user