Browse Source

Method made static and moved to manager.

master
MagicBot 1 year ago
parent
commit
c913618dc3
  1. 25
      src/engine/gameManager/NPCManager.java
  2. 3
      src/engine/net/client/handlers/AssetSupportMsgHandler.java
  3. 3
      src/engine/net/client/msg/ManageNPCMsg.java
  4. 25
      src/engine/objects/NPC.java

25
src/engine/gameManager/NPCManager.java

@ -293,4 +293,29 @@ public enum NPCManager { @@ -293,4 +293,29 @@ public enum NPCManager {
return nameList.get(ThreadLocalRandom.current().nextInt(nameList.size()));
}
public static ArrayList<Building> getProtectedBuildings(NPC npc) {
ArrayList<Building> 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;
}
}

3
src/engine/net/client/handlers/AssetSupportMsgHandler.java

@ -5,6 +5,7 @@ import engine.Enum.SupportMsgType; @@ -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 { @@ -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;

3
src/engine/net/client/msg/ManageNPCMsg.java

@ -12,6 +12,7 @@ package engine.net.client.msg; @@ -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 { @@ -440,7 +441,7 @@ public class ManageNPCMsg extends ClientNetMsg {
//TODO add runemaster list here
ArrayList<Building> buildingList = npc.getProtectedBuildings();
ArrayList<Building> buildingList = NPCManager.getProtectedBuildings(npc);
writer.putInt(buildingList.size());

25
src/engine/objects/NPC.java

@ -1271,31 +1271,6 @@ public class NPC extends AbstractCharacter { @@ -1271,31 +1271,6 @@ public class NPC extends AbstractCharacter {
}
}
public ArrayList<Building> getProtectedBuildings() {
ArrayList<Building> 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)

Loading…
Cancel
Save