diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 6131dc04..e38adabb 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -74,11 +74,10 @@ public enum BuildingManager { int numOfSlots = _slotLocations.get(building.meshUUID).size(); - for (int i = numOfSlots; i > 0; i--) { - + for (int i = numOfSlots; i > 0; i--) if (!building.getHirelings().containsValue(i)) return i; - } + return -1; } @@ -91,9 +90,8 @@ public enum BuildingManager { buildingLocation = _slotLocations.get(building.meshUUID).get(slot - 1); // array index - if (buildingLocation == null) { + if (buildingLocation == null) Logger.error("Invalid slot for building: " + building.getObjectUUID()); - } return buildingLocation; } @@ -113,6 +111,7 @@ public enum BuildingManager { return true; //individual friend. + if (building.getFriends() != null && building.getFriends().get(player.getObjectUUID()) != null) return true; @@ -151,7 +150,6 @@ public enum BuildingManager { if (building == null) return false; - if (building.getRank() == -1) return false; @@ -161,10 +159,10 @@ public enum BuildingManager { //Somehow guild leader check fails? lets check if Player is true Guild GL. if (building.getGuild() != null && building.getGuild().isGuildLeader(player.getObjectUUID())) return true; + if (!GuildStatusController.isGuildLeader(player.getGuildStatus()) && !GuildStatusController.isInnerCouncil(player.getGuildStatus())) return false; - return false; } @@ -346,12 +344,9 @@ public enum BuildingManager { Mob hirelingMob = (Mob) hireling; - if (hirelingMob.parentZone != null) { - if (hirelingMob.parentZone.zoneMobSet.contains(hirelingMob)) { + if (hirelingMob.parentZone != null) + if (hirelingMob.parentZone.zoneMobSet.contains(hirelingMob)) hirelingMob.parentZone.zoneMobSet.remove(hireling); - } - } - } if (hireling.getObjectType().equals(GameObjectType.NPC)) { @@ -376,10 +371,8 @@ public enum BuildingManager { DbManager.MobQueries.DELETE_MOB((Mob) hireling); else DbManager.NPCQueries.DELETE_NPC((NPC) hireling); - } - public static void cleanupHirelings(Building building) { // Early exit: Cannot have hirelings in a building @@ -391,22 +384,17 @@ public enum BuildingManager { // Remove all hirelings for destroyed buildings if (building.getRank() < 1) { - for (AbstractCharacter slottedNPC : building.getHirelings().keySet()) BuildingManager.removeHireling(building, slottedNPC); - return; } // Delete hireling if building has deranked. - for (AbstractCharacter hireling : building.getHirelings().keySet()) { - + for (AbstractCharacter hireling : building.getHirelings().keySet()) if (building.getHirelings().get(hireling) > building.getBlueprint().getSlotsForRank(building.getRank())) BuildingManager.removeHireling(building, hireling); - } - refreshHirelings(building); } @@ -438,6 +426,7 @@ public enum BuildingManager { return false; //lets pass true if player is owner anyway. + if (building.getOwner().equals(player)) return true; @@ -453,21 +442,6 @@ public enum BuildingManager { return GuildStatusController.isGuildLeader(player.getGuildStatus()) || GuildStatusController.isInnerCouncil(player.getGuildStatus()); } - //This is mainly used for Rolling and gold sharing between building and warehouse. - - public static int GetWithdrawAmountForRolling(Building building, int cost) { - - //all funds are available to roll. - - if (cost <= GetAvailableGold(building)) - return cost; - - // cost is more than available gold, return available gold - - return GetAvailableGold(building); - - } - public static int GetAvailableGold(Building building) { if (building.getStrongboxValue() == 0) @@ -479,11 +453,6 @@ public enum BuildingManager { return building.getStrongboxValue() - building.reserve; } - public static int GetOverdraft(Building building, int cost) { - int availableGold = GetWithdrawAmountForRolling(building, cost); - return cost - availableGold; - } - public static boolean IsPlayerHostile(Building building, PlayerCharacter player) { //Nation Members and Guild members are not hostile. @@ -547,7 +516,7 @@ public enum BuildingManager { String pirateName = NPCManager.getPirateName(NpcID.getMobbaseID()); - NPC npc = null; + NPC npc; npc = NPC.createNPC(pirateName, NpcID.getObjectUUID(), NpcLoc, building.getGuild(), zone, (short) rank, building); @@ -563,7 +532,7 @@ public enum BuildingManager { public static synchronized boolean addHireling(Building building, PlayerCharacter contractOwner, Zone zone, Contract contract, Item item) { - int rank = 1; + int rank; if (building.getBlueprintUUID() == 0) return false; @@ -622,6 +591,7 @@ public enum BuildingManager { if (contract.getContractID() == 910) { //guard dog + mobile = Mob.createMob(contract.getMobbaseID(), Vector3fImmutable.ZERO, contractOwner.getGuild(), zone, building, contract, pirateName, rank, mbEnums.AIAgentType.GUARDCAPTAIN); if (mobile == null) @@ -681,9 +651,7 @@ public enum BuildingManager { if (building.getOwner() == null) return false; - return building.getOwner().getObjectUUID() == player.getObjectUUID(); - } public static float GetMissingHealth(Building building) { @@ -695,6 +663,7 @@ public enum BuildingManager { } public static Regions GetRegion(Building building, float x, float y, float z) { + if (building.getBounds() == null) return null; @@ -702,17 +671,18 @@ public enum BuildingManager { return null; Regions currentRegion = null; - for (Regions region : building.getBounds().getRegions()) { - if (region.isPointInPolygon(new Vector3fImmutable(x, y, z))) { + for (Regions region : building.getBounds().getRegions()) { + if (region.isPointInPolygon(new Vector3fImmutable(x, y, z))) if (y > (region.highLerp.y - 5)) currentRegion = region; - } } + return currentRegion; } public static Regions GetRegion(Building building, int room, int level, float x, float z) { + if (building.getBounds() == null) return null; @@ -723,12 +693,12 @@ public enum BuildingManager { if (region.getLevel() != level) continue; + if (region.getRoom() != room) continue; - if (region.isPointInPolygon(new Vector3fImmutable(x, 0, z))) { + if (region.isPointInPolygon(new Vector3fImmutable(x, 0, z))) return region; - } } return null; } @@ -740,11 +710,10 @@ public enum BuildingManager { if (building == null) return mbEnums.Ruins.getRandomRuin().getLocation(); - bindLoc = building.getLoc(); - float radius = Bounds.meshBoundsCache.get(building.getMeshUUID()).radius; + if (building.getRank() == 8) { bindLoc = building.getStuckLocation(); if (bindLoc != null) @@ -797,7 +766,6 @@ public enum BuildingManager { int newMeshUUID; boolean success; - // If this building has no blueprint then set rank and exit immediatly. if (building.blueprintUUID == 0 || building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE)) { @@ -809,14 +777,14 @@ public enum BuildingManager { // Delete any upgrade jobs before doing anything else. It won't quite work // if in a few lines we happen to delete this building. - JobContainer jc = building.getTimers().get("UPGRADE"); + JobContainer jobContainer = building.getTimers().get("UPGRADE"); - if (jc != null) { - if (!JobScheduler.getInstance().cancelScheduledJob(jc)) + if (jobContainer != null) { + if (!JobScheduler.getInstance().cancelScheduledJob(jobContainer)) Logger.error("failed to cancel existing upgrade job."); } - // Attempt write to database, or delete the building + // Attempt to write to database or delete the building // if we are destroying it. if (rank == -1) @@ -881,7 +849,6 @@ public enum BuildingManager { if (Bounds.collide(loc, building.getBounds())) return building; - } return null; }