From a7495bf94207a52f9b3f6199b8b5c8316792b329 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 12 Aug 2023 06:16:12 -0400 Subject: [PATCH] Bugfix: R8 slot locations. --- src/engine/gameManager/BuildingManager.java | 20 ++++++++++++++++++++ src/engine/objects/NPC.java | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index d9ea9810..b194b93e 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -55,6 +55,26 @@ public enum BuildingManager { return -1; } + public static int getLastAvailableSlot(Building building) { + + ArrayList slotLocations = _slotLocations.get(building.meshUUID); + + // Some meshes might not have slot locations assigned. + + if (slotLocations == null || + slotLocations.isEmpty()) + return -1; + + int numOfSlots = _slotLocations.get(building.meshUUID).size(); + + for (int i = numOfSlots; i > 0; i--) { + + if (!building.getHirelings().containsValue(i)) + return i; + } + return -1; + } + public static BuildingLocation getSlotLocation(Building building, int slot) { BuildingLocation buildingLocation = new BuildingLocation(); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index a45da7a3..e93e435b 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -793,8 +793,12 @@ public class NPC extends AbstractCharacter { // Get next available slot for this NPC and use it // to add the NPC to the building's hireling list + // Account for R8's having slots reversed. - slot = BuildingManager.getAvailableSlot(building); + if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.TOL) && building.getRank() == 8) + slot = BuildingManager.getLastAvailableSlot(building); + else + slot = BuildingManager.getAvailableSlot(building); if (slot == -1) Logger.error("No available slot for NPC: " + this.getObjectUUID());