diff --git a/src/engine/db/handlers/dbNPCHandler.java b/src/engine/db/handlers/dbNPCHandler.java index 51b20246..0a3c390a 100644 --- a/src/engine/db/handlers/dbNPCHandler.java +++ b/src/engine/db/handlers/dbNPCHandler.java @@ -131,6 +131,30 @@ public class dbNPCHandler extends dbHandlerBase { return npc; } + public boolean BANE_COMMANDER_EXISTS(final int objectUUID) { + + boolean exists = false; + + String query = "SELECT 1 FROM `obj_npc` WHERE `npc_buildingID` = ? LIMIT 1;"; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(query)) { + + preparedStatement.setInt(1, objectUUID); + + try (ResultSet rs = preparedStatement.executeQuery()) { + // If there's a result, it means the entry exists + exists = rs.next(); + } + + } catch (SQLException e) { + Logger.error(e); + } + + return exists; + } + + public int MOVE_NPC(long npcID, long parentID, float locX, float locY, float locZ) { int rowCount; diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index 3f6776d2..c407985c 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -14,13 +14,11 @@ import engine.Enum.ProtectionState; import engine.Enum.SiegePhase; import engine.Enum.SiegeResult; import engine.InterestManagement.HeightMap; +import engine.InterestManagement.InterestManager; import engine.InterestManagement.WorldGrid; import engine.db.archive.BaneRecord; import engine.db.archive.DataWarehouse; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; +import engine.gameManager.*; import engine.job.JobScheduler; import engine.jobs.ActivateBaneJob; import engine.jobs.BaneDefaultTimeJob; @@ -275,17 +273,20 @@ public final class Bane { public static void summonBaneCommander(Bane bane){ Vector3fImmutable spawnLoc = Vector3fImmutable.getRandomPointOnCircle(bane.getStone().loc,15); NPC baneCommander; - if(bane.getStone().getHirelings().isEmpty()) { + boolean npcPresent = DbManager.NPCQueries.BANE_COMMANDER_EXISTS(bane.getStone().getObjectUUID()); + + if(!npcPresent) { //add bane commander NPC int contractID = 1502042; baneCommander = NPC.createNPC("Bane Commander", contractID, spawnLoc, bane.getCity().getGuild(), ZoneManager.findSmallestZone(bane.getStone().loc), (short) 70, bane.getStone()); baneCommander.setLoc(spawnLoc); baneCommander.setGuild(bane.getCity().getGuild()); - }else{ + }else{ baneCommander = (NPC)bane.getStone().getHirelings().keySet().iterator().next(); baneCommander.setLoc(spawnLoc); baneCommander.setGuild(bane.getCity().getGuild()); } + InterestManager.setObjectDirty(baneCommander); } public static Bane getBane(int cityUUID) {