diff --git a/src/engine/Enum.java b/src/engine/Enum.java index aec9e3c6..125bc6f7 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2877,10 +2877,11 @@ public class Enum { public enum AIAgentType { MOBILE, + GUARDCAPTAIN, + GUARDMINION, + GUARDWALLARCHER, PET, CHARMED, - - SIEGEENGINE, - GUARD; + SIEGEENGINE; } } diff --git a/src/engine/db/handlers/dbMobHandler.java b/src/engine/db/handlers/dbMobHandler.java index 766335ff..08a1e6e6 100644 --- a/src/engine/db/handlers/dbMobHandler.java +++ b/src/engine/db/handlers/dbMobHandler.java @@ -33,7 +33,7 @@ public class dbMobHandler extends dbHandlerBase { Mob mobile = null; 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.setInt(2, toAdd.loadID); @@ -48,6 +48,7 @@ public class dbMobHandler extends dbHandlerBase { preparedStatement.setInt(11, toAdd.buildingUUID); preparedStatement.setInt(12, toAdd.level); preparedStatement.setString(13, toAdd.firstName); + preparedStatement.setString(14, toAdd.behaviourType.toString()); ResultSet rs = preparedStatement.executeQuery(); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 844942ad..b13065fd 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -530,41 +530,59 @@ public enum BuildingManager { else rank = 10; - Mob mob; + Mob mobile; NPC npc; 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; - mob.setLoc(mob.getLoc()); + // Configure AI. + + mobile.behaviourType = Enum.MobBehaviourType.GuardWallArcher; + + DbManager.MobQueries.PERSIST(mobile); + + mobile.setLoc(mobile.getLoc()); return true; } 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; - mob.setLoc(mob.getLoc()); + // Configure AI. + + mobile.behaviourType = Enum.MobBehaviourType.GuardCaptain; + + DbManager.MobQueries.PERSIST(mobile); + + mobile.setLoc(mobile.getLoc()); return true; } + if (contract.getContractID() == 910) { //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; - mob.setLoc(mob.getLoc()); + // Configure AI. + + mobile.behaviourType = Enum.MobBehaviourType.GuardCaptain; + + DbManager.MobQueries.PERSIST(mobile); + mobile.setLoc(mobile.getLoc()); return true; } diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 6aed514a..4ab371c7 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -1011,14 +1011,14 @@ public class MobAI { //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; Mob aggroMob = (Mob) awoMob; //don't attack other guards - if ((aggroMob.agentType.equals(Enum.AIAgentType.GUARD))) + if ((aggroMob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN))) continue; if (aggroMob.behaviourType.equals(Enum.MobBehaviourType.Pet1)) diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 00bdfb28..94342988 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -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 - - 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()); + // Configure AI related values + + 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