From 3419c1ceeacb0cfd88839e30c4197ec9cb1039e7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 24 Apr 2023 09:22:01 -0400 Subject: [PATCH] Refactored isWallArcher(). --- src/engine/gameManager/BuildingManager.java | 14 ++++++------ src/engine/objects/Mob.java | 2 +- src/engine/objects/NPC.java | 24 +++++++-------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 7b98b34f..8d316e2a 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -450,7 +450,7 @@ public enum BuildingManager { } - public static synchronized boolean addHireling(Building building, PlayerCharacter contractOwner, Vector3fImmutable NpcLoc, Zone zone, Contract contractID, Item item) { + public static synchronized boolean addHireling(Building building, PlayerCharacter contractOwner, Vector3fImmutable NpcLoc, Zone zone, Contract contract, Item item) { int rank = 1; @@ -460,7 +460,7 @@ public enum BuildingManager { if (building.getBlueprint().getMaxSlots() == building.getHirelings().size()) return false; - String pirateName = NPC.getPirateName(contractID.getMobbaseID()); + String pirateName = NPC.getPirateName(contract.getMobbaseID()); if (item.getChargesRemaining() > 0) rank = item.getChargesRemaining() * 10; @@ -469,9 +469,9 @@ public enum BuildingManager { Mob mob; NPC npc; - if (NPC.ISWallArcher(contractID.getContractID())) { + if (NPC.ISWallArcher(contract)) { - mob = Mob.createMob( contractID.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contractID.getContractID(), pirateName, rank * 10); + mob = Mob.createMob( contract.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contract.getContractID(), pirateName, rank * 10); if (mob == null) return false; @@ -482,9 +482,9 @@ public enum BuildingManager { MovementManager.translocate(mob,mob.getBindLoc(),mob.getRegion()); return true; } - if (NPC.ISGuardCaptain(contractID.getContractID())) { + if (NPC.ISGuardCaptain(contract.getContractID())) { - mob = Mob.createMob( contractID.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contractID.getContractID(), pirateName, rank); + mob = Mob.createMob( contract.getMobbaseID(), NpcLoc, contractOwner.getGuild(), true, zone, building, contract.getContractID(), pirateName, rank); if (mob == null) return false; @@ -494,7 +494,7 @@ public enum BuildingManager { mob.setParentZone(zone); return true; } - npc = NPC.createNPC( pirateName, contractID.getObjectUUID(), NpcLoc, contractOwner.getGuild(), false, zone, (short) rank, false, building); + npc = NPC.createNPC( pirateName, contract.getObjectUUID(), NpcLoc, contractOwner.getGuild(), false, zone, (short) rank, false, building); if (npc == null) return false; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index c5b0426f..93d2166e 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1903,7 +1903,7 @@ public class Mob extends AbstractIntelligenceAgent { if (this.BehaviourType == null) this.BehaviourType = this.getMobBase().fsm; - if (this.isPlayerGuard() && this.contract != null) if (NPC.ISWallArcher(this.getContract().getContractID())) + if (this.isPlayerGuard() && this.contract != null) if (NPC.ISWallArcher(this.getContract())) this.BehaviourType = MobBehaviourType.GuardWallArcher; else this.BehaviourType = MobBehaviourType.GuardCaptain; diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index cea3cf73..5217d7c1 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -289,23 +289,15 @@ public class NPC extends AbstractCharacter { } - public static boolean ISWallArcher(int contractID) { + public static boolean ISWallArcher(Contract contract) { + + if (contract == null) + return false; + //838, 950, 1051, 1181, 1251, 1351, 1451, 1501, 1526, 1551, 980101, - switch(contractID) { - case 838: - case 950: - case 1051: - case 1181: - case 1251: - case 1351: - case 1451: - case 150: - case 1526: - case 1551: - case 980101: - return true; - } - return false; + + return contract.getAllowedBuildings().contains(BuildingGroup.WALLCORNER) || + contract.getAllowedBuildings().contains(BuildingGroup.WALLSTRAIGHTTOWER); } //This method restarts an upgrade timer when a building is loaded from the database.