From f4c9e6d7b80b6f38fe09adde03eb3838e3898635 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 9 Sep 2023 08:28:03 -0400 Subject: [PATCH] Remove hireling method defined in manager. --- src/engine/gameManager/BuildingManager.java | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index b17ee20c..672a3d87 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -308,6 +308,52 @@ public enum BuildingManager { } + public static void removeHireling(Building building, AbstractCharacter hireling) { + + Mob guardCaptain = null; + + if (hireling.getObjectType().equals(GameObjectType.Mob)) { + + guardCaptain = (Mob) hireling; + + // Clear minions from database if a guard captain + + if (guardCaptain.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) + DbManager.MobQueries.REMOVE_ALL_MINIONS(hireling.getObjectUUID()); + } + + // Clear minions from world + + for (Integer minionUUID : hireling.minions) { + Mob minionMob = Mob.getMob(minionUUID); + DbManager.removeFromCache(minionMob); + WorldGrid.RemoveWorldObject(minionMob); + WorldGrid.unloadObject(minionMob); + + if (minionMob.getParentZone() != null) + minionMob.getParentZone().zoneMobSet.remove(minionMob); + } + + // Remove hireling from building + + building.getHirelings().remove(hireling); + + // Delete hireling from database + + if (hireling.getObjectType().equals(GameObjectType.Mob)) + DbManager.MobQueries.DELETE_MOB((Mob) hireling); + else + DbManager.NPCQueries.DELETE_NPC((NPC) hireling); + + // Unload hireling from world + + DbManager.removeFromCache(hireling); + WorldGrid.RemoveWorldObject(hireling); + WorldGrid.removeObject(hireling); + + } + + public static void cleanupHirelings(Building building) { // Early exit: Cannot have hirelings in a building