Browse Source

Minor cleanup

combat-2
MagicBot 8 months ago
parent
commit
bc1ae9a2c9
  1. 81
      src/engine/gameManager/BuildingManager.java

81
src/engine/gameManager/BuildingManager.java

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

Loading…
Cancel
Save