From b602a7895096de1f1914b4fdfcf092bdbfcfb340 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 07:59:31 -0400 Subject: [PATCH] Debug code added --- src/engine/workthreads/DestroyCityThread.java | 165 +++++++++--------- 1 file changed, 86 insertions(+), 79 deletions(-) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 4ba0f073..526819da 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -52,105 +52,112 @@ public class DestroyCityThread implements Runnable { Vector3fImmutable localCoords; ArrayList subGuildList; - // Member variable assignment + Logger.info("Destroy city routing started"); - cityZone = city.getParent(); - newParent = cityZone.parent; - formerGuild = city.getTOL().getGuild(); + try { - // Former guild loses it's tree! + // Member variable assignment - if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { + cityZone = city.getParent(); + newParent = cityZone.parent; + formerGuild = city.getTOL().getGuild(); - //Successful Update of guild + // Former guild loses it's tree! - formerGuild.setGuildState(mbEnums.GuildState.Errant); - formerGuild.setNation(null); - formerGuild.setCityUUID(0); - GuildManager.updateAllGuildTags(formerGuild); - GuildManager.updateAllGuildBinds(formerGuild, null); - } + if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { - if (formerGuild.getSubGuildList().isEmpty() == false) { + //Successful Update of guild - subGuildList = new ArrayList<>(); - - for (Guild subGuild : formerGuild.getSubGuildList()) { - subGuildList.add(subGuild); + formerGuild.setGuildState(mbEnums.GuildState.Errant); + formerGuild.setNation(null); + formerGuild.setCityUUID(0); + GuildManager.updateAllGuildTags(formerGuild); + GuildManager.updateAllGuildBinds(formerGuild, null); } - for (Guild subGuild : subGuildList) { - formerGuild.removeSubGuild(subGuild); - } - } + if (formerGuild.getSubGuildList().isEmpty() == false) { - // Build list of buildings within this parent zone + subGuildList = new ArrayList<>(); - for (Building cityBuilding : cityZone.zoneBuildingSet) { + for (Guild subGuild : formerGuild.getSubGuildList()) { + subGuildList.add(subGuild); + } - // Sanity Check in case player deletes the building - // before this thread can get to it - - if (cityBuilding == null) - continue; - - // Do nothing with the banestone. It will be removed elsewhere - - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) - continue; - - // All buildings are moved to a location relative - // to their new parent zone - - localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); - - DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - - // All buildings are re-parented to a zone one node - // higher in the tree (continent) as we will be - // deleting the city zone very shortly. - - if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) - cityBuilding.setParentZone(newParent); - - // No longer a tree, no longer any protection contract! - - cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); - - // Remove warehouse entry if one exists. - - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.WAREHOUSE)) { - DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); - city.warehouse = null; + for (Guild subGuild : subGuildList) { + formerGuild.removeSubGuild(subGuild); + } } - // Destroy all remaining auto-protected city assets + // Build list of buildings within this parent zone - EnumSet assetsToDestroy = EnumSet.of(mbEnums.BuildingGroup.TOL, mbEnums.BuildingGroup.BARRACK, - mbEnums.BuildingGroup.SPIRE, mbEnums.BuildingGroup.SHRINE, mbEnums.BuildingGroup.WAREHOUSE); + for (Building cityBuilding : cityZone.zoneBuildingSet) { - if (assetsToDestroy.contains(cityBuilding.getBlueprint().getBuildingGroup())) { + // Sanity Check in case player deletes the building + // before this thread can get to it - if (cityBuilding.getRank() != -1) - BuildingManager.setRank(cityBuilding, -1); + if (cityBuilding == null) + continue; + + // Do nothing with the banestone. It will be removed elsewhere + + if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) + continue; + + // All buildings are moved to a location relative + // to their new parent zone + + localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); + + DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + + // All buildings are re-parented to a zone one node + // higher in the tree (continent) as we will be + // deleting the city zone very shortly. + + if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) + cityBuilding.setParentZone(newParent); + + // No longer a tree, no longer any protection contract! + + cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); + + // Remove warehouse entry if one exists. + + if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.WAREHOUSE)) { + DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); + city.warehouse = null; + } + + // Destroy all remaining auto-protected city assets + + EnumSet assetsToDestroy = EnumSet.of(mbEnums.BuildingGroup.TOL, mbEnums.BuildingGroup.BARRACK, + mbEnums.BuildingGroup.SPIRE, mbEnums.BuildingGroup.SHRINE, mbEnums.BuildingGroup.WAREHOUSE); + + if (assetsToDestroy.contains(cityBuilding.getBlueprint().getBuildingGroup())) { + + if (cityBuilding.getRank() != -1) + BuildingManager.setRank(cityBuilding, -1); + } } + + if (city.realm != null) + city.realm.removeCity(city.getObjectUUID()); + + // It's now safe to delete the city zone from the database + // which will cause a cascade delete of everything else + + if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { + Logger.error("DestroyCityThread", "Error when deleting city zone: " + cityZone.getObjectUUID()); + return; + } + + // Refresh the city for map requests + + City.lastCityUpdate = System.currentTimeMillis(); + } catch (Exception e) { + Logger.error(e); } - if (city.realm != null) - city.realm.removeCity(city.getObjectUUID()); - - // It's now safe to delete the city zone from the database - // which will cause a cascade delete of everything else - - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { - Logger.error("DestroyCityThread", "Error when deleting city zone: " + cityZone.getObjectUUID()); - return; - } - - // Refresh the city for map requests - - City.lastCityUpdate = System.currentTimeMillis(); - // Zone and city should vanish upon next reboot // if the codebase reaches here.