From c913618dc3b3d4da604c20716c5fbc7bf2cd4a8f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 15 Aug 2023 08:50:02 -0400 Subject: [PATCH] Method made static and moved to manager. --- src/engine/gameManager/NPCManager.java | 25 +++++++++++++++++++ .../handlers/AssetSupportMsgHandler.java | 3 ++- src/engine/net/client/msg/ManageNPCMsg.java | 3 ++- src/engine/objects/NPC.java | 25 ------------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index 7465fddc..6997b207 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -293,4 +293,29 @@ public enum NPCManager { return nameList.get(ThreadLocalRandom.current().nextInt(nameList.size())); } + + public static ArrayList getProtectedBuildings(NPC npc) { + + ArrayList protectedBuildings = new ArrayList<>(); + + if (npc.building == null) + return protectedBuildings; + + if (npc.building.getCity() == null) + return protectedBuildings; + + for (Building b : npc.building.getCity().getParent().zoneBuildingSet) { + + if (b.getBlueprint() == null) + continue; + + if (b.getProtectionState().equals(Enum.ProtectionState.CONTRACT)) + protectedBuildings.add(b); + + if (b.getProtectionState().equals(Enum.ProtectionState.PENDING)) + protectedBuildings.add(b); + } + + return protectedBuildings; + } } diff --git a/src/engine/net/client/handlers/AssetSupportMsgHandler.java b/src/engine/net/client/handlers/AssetSupportMsgHandler.java index 444a6df8..d7bcc3d3 100644 --- a/src/engine/net/client/handlers/AssetSupportMsgHandler.java +++ b/src/engine/net/client/handlers/AssetSupportMsgHandler.java @@ -5,6 +5,7 @@ import engine.Enum.SupportMsgType; import engine.Enum.TaxType; import engine.exception.MsgSendException; import engine.gameManager.BuildingManager; +import engine.gameManager.NPCManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -71,7 +72,7 @@ public class AssetSupportMsgHandler extends AbstractClientMsgHandler { protectionSlots = (2 * serverCity.getRuneMaster().getRank()) + 6; - if (serverCity.getRuneMaster().getProtectedBuildings().size() >= + if (NPCManager.getProtectedBuildings(serverCity.getRuneMaster()).size() >= protectionSlots) { ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can only protect " + protectionSlots + " structura!"); return; diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 61fac72e..34be1f29 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -12,6 +12,7 @@ package engine.net.client.msg; import engine.Enum.GameObjectType; import engine.Enum.MinionType; import engine.Enum.ProtectionState; +import engine.gameManager.NPCManager; import engine.gameManager.PowersManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -440,7 +441,7 @@ public class ManageNPCMsg extends ClientNetMsg { //TODO add runemaster list here - ArrayList buildingList = npc.getProtectedBuildings(); + ArrayList buildingList = NPCManager.getProtectedBuildings(npc); writer.putInt(buildingList.size()); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index e93e435b..49e5c1b5 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -1271,31 +1271,6 @@ public class NPC extends AbstractCharacter { } } - public ArrayList getProtectedBuildings() { - - ArrayList protectedBuildings = new ArrayList<>(); - - if (this.building == null) - return protectedBuildings; - - if (this.building.getCity() == null) - return protectedBuildings; - - for (Building b : this.building.getCity().getParent().zoneBuildingSet) { - - if (b.getBlueprint() == null) - continue; - - if (b.getProtectionState().equals(ProtectionState.CONTRACT)) - protectedBuildings.add(b); - - if (b.getProtectionState().equals(ProtectionState.PENDING)) - protectedBuildings.add(b); - } - - return protectedBuildings; - } - @Override public Guild getGuild() { if (this.building != null)