From e082a0b49cf28edc8e4d54739e0def569d381626 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:18:40 -0400 Subject: [PATCH 01/11] Bane logic tweaking --- src/engine/objects/Building.java | 2 +- src/engine/workthreads/DestroyCityThread.java | 144 ++++++++---------- 2 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 5367c8f7..0a356546 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -561,7 +561,7 @@ public class Building extends AbstractWorldObject { BuildingManager.setRank(barracksBuilding, -1); } - // If the tree is R8 and deranking, we need to update it's + // If the tree is R8 and deranking, we need to update the // mesh along with buildings losing their health bonus if (this.rank == 8) { diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 9c5b2050..ae4ac2d8 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -53,120 +53,110 @@ public class DestroyCityThread implements Runnable { // Member variable assignment - cityZone = city.getParent(); - newParent = cityZone.parent; - formerGuild = city.getTOL().getGuild(); + try { + cityZone = city.getParent(); + newParent = cityZone.parent; + formerGuild = city.getTOL().getGuild(); - // Former guild loses it's tree! + // Former guild loses tree! - if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { + if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { - //Successful Update of guild + //Successful Update of guild - formerGuild.setGuildState(mbEnums.GuildState.Errant); - formerGuild.setNation(null); - formerGuild.setCityUUID(0); - GuildManager.updateAllGuildTags(formerGuild); - GuildManager.updateAllGuildBinds(formerGuild, null); - } + formerGuild.setGuildState(mbEnums.GuildState.Errant); + formerGuild.setNation(null); + formerGuild.setCityUUID(0); + GuildManager.updateAllGuildTags(formerGuild); + GuildManager.updateAllGuildBinds(formerGuild, null); + } - // By losing the tree, the former owners lose all of their subguilds. + // By losing the tree, the former owners lose all of their subguilds. - if (!formerGuild.getSubGuildList().isEmpty()) { + if (!formerGuild.getSubGuildList().isEmpty()) { - subGuildList = new ArrayList<>(); + subGuildList = new ArrayList<>(); - subGuildList.addAll(formerGuild.getSubGuildList()); + subGuildList.addAll(formerGuild.getSubGuildList()); - for (Guild subGuild : subGuildList) { - formerGuild.removeSubGuild(subGuild); + for (Guild subGuild : subGuildList) { + formerGuild.removeSubGuild(subGuild); + } } - } - Building tol = null; + // Build list of buildings within this parent zone - // Build list of buildings within this parent zone + for (Building cityBuilding : cityZone.zoneBuildingSet) { - for (Building cityBuilding : cityZone.zoneBuildingSet) { + // Sanity Check in case player deletes the building + // before this thread can get to it - // Sanity Check in case player deletes the building - // before this thread can get to it + if (cityBuilding == null) + continue; - if (cityBuilding == null) - continue; + // Do nothing with the banestone. It will be removed elsewhere - // Do nothing with the banestone. It will be removed elsewhere + if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) + continue; - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) - continue; + // All buildings are moved to a location relative + // to their new parent zone - // TOL is processed after all other structures in the city zone + localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.TOL)) { - tol = cityBuilding; - continue; - } - - // All buildings are moved to a location relative - // to their new parent zone + DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); - localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent); + // 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. - DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z); + if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) + cityBuilding.setParentZone(newParent); - // 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. + // No longer a tree, no longer any protection contract! - if (cityBuilding.getParentZoneID() != newParent.getParentZoneID()) - cityBuilding.setParentZone(newParent); + cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); - // No longer a tree, no longer any protection contract! + // Remove warehouse entry if one exists. - cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE); + if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) { + DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); + city.warehouse = null; + } - // Remove warehouse entry if one exists. + if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) + || (cityBuilding.getBlueprint().isWallPiece()) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) + || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { - if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) { - DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); - city.warehouse = null; + if (cityBuilding.getRank() != -1) + BuildingManager.setRank(cityBuilding, -1); + } } - // Destroy all remaining city assets - - if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { - - if (cityBuilding.getRank() != -1) - BuildingManager.setRank(cityBuilding, -1); + if (city.realm != null) { + city.realm.removeCity(city.getObjectUUID()); + city.realm = null; } - } - - // Destroy the tol - if (tol != null) - BuildingManager.setRank(tol, -1); + // It's now safe to delete the city zone from the database + // which will cause a cascade delete of everything else - if (city.realm != null) - city.realm.removeCity(city.getObjectUUID()); + if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { + Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); + return; + } - // It's now safe to delete the city zone from the database - // which will cause a cascade delete of everything else + // Refresh the city for map requests + City.lastCityUpdate = System.currentTimeMillis(); - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { - Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); - return; + } catch (Exception e) { + Logger.error(e); } - // Refresh the city for map requests - - City.lastCityUpdate = System.currentTimeMillis(); - // Zone and city should vanish upon next reboot // if the codebase reaches here. From eff44c334d66366ae5d2f30cd2ab2612c707f54e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:26:14 -0400 Subject: [PATCH 02/11] Error trapping and output --- src/engine/workthreads/DestroyCityThread.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index ae4ac2d8..40c22605 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -58,6 +58,8 @@ public class DestroyCityThread implements Runnable { newParent = cityZone.parent; formerGuild = city.getTOL().getGuild(); + Logger.info("Destroy city thread started for: " + newParent.zoneName); + // Former guild loses tree! if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) { From d304d0706c19d281d1e6bf2b7f20e8ade3c3b10c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 15:28:12 -0400 Subject: [PATCH 03/11] Owner set to null --- src/engine/workthreads/DestroyCityThread.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 40c22605..04b38e18 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -143,6 +143,8 @@ public class DestroyCityThread implements Runnable { city.realm = null; } + city.getTOL().setOwner(null); + // It's now safe to delete the city zone from the database // which will cause a cascade delete of everything else From 93befc088787127a59e89759959dc60407a9facd Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:13:22 -0400 Subject: [PATCH 04/11] Update to console output --- src/engine/objects/City.java | 4 ++-- src/engine/workthreads/DestroyCityThread.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 8f674de8..375bd854 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1104,7 +1104,7 @@ public class City extends AbstractWorldObject { Thread destroyCityThread = new Thread(new DestroyCityThread(this)); - destroyCityThread.setName("destroyCity:" + this.getName()); + destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); destroyCityThread.start(); } @@ -1112,7 +1112,7 @@ public class City extends AbstractWorldObject { Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); - transferCityThread.setName("TransferCity:" + this.getName()); + transferCityThread.setName("TransferCity:" + this.getParent().zoneName)); transferCityThread.start(); } diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 04b38e18..64ef509f 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -58,7 +58,7 @@ public class DestroyCityThread implements Runnable { newParent = cityZone.parent; formerGuild = city.getTOL().getGuild(); - Logger.info("Destroy city thread started for: " + newParent.zoneName); + Logger.info("Destroy city thread started for: " + cityZone.zoneName); // Former guild loses tree! @@ -164,6 +164,6 @@ public class DestroyCityThread implements Runnable { // Zone and city should vanish upon next reboot // if the codebase reaches here. - Logger.info(city.getParent().zoneName + " uuid:" + city.getObjectUUID() + "has been destroyed!"); + Logger.info(city.getParent().zoneName + " uuid: " + city.getObjectUUID() + " has been destroyed!"); } } From aaff28d720bc66961f92ad6a33da6116b55c6148 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:13:37 -0400 Subject: [PATCH 05/11] Update to console output --- src/engine/objects/City.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 375bd854..a4591532 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1112,7 +1112,7 @@ public class City extends AbstractWorldObject { Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner)); - transferCityThread.setName("TransferCity:" + this.getParent().zoneName)); + transferCityThread.setName("TransferCity:" + this.getParent().zoneName); transferCityThread.start(); } From 4da089e9b880e728a94c8a299aa94594e067a0e0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:20:27 -0400 Subject: [PATCH 06/11] Update to thread logic --- src/engine/workthreads/DestroyCityThread.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 64ef509f..77453c71 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -88,6 +88,8 @@ public class DestroyCityThread implements Runnable { // Build list of buildings within this parent zone + ArrayList destroySet = new ArrayList<>(); + for (Building cityBuilding : cityZone.zoneBuildingSet) { // Sanity Check in case player deletes the building @@ -126,29 +128,27 @@ public class DestroyCityThread implements Runnable { city.warehouse = null; } - if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { + // Mark all auto protected buildings for destruction - if (cityBuilding.getRank() != -1) - BuildingManager.setRank(cityBuilding, -1); - } + if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) || (cityBuilding.getBlueprint().isWallPiece()) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) + destroySet.add(cityBuilding); } + // Destroy set of auto-protected buildings + + for (Building building : destroySet) + if (building.getRank() != -1) + BuildingManager.setRank(building, -1); + if (city.realm != null) { city.realm.removeCity(city.getObjectUUID()); city.realm = null; } - city.getTOL().setOwner(null); - // 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) { + if (!DbManager.ZoneQueries.DELETE_ZONE(cityZone)) { Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); return; } From 983dd46870fbeaed320af717d6654442f43d9f17 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:23:28 -0400 Subject: [PATCH 07/11] Update to thread logic --- src/engine/gameManager/BuildingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 8907339a..6292c457 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -798,7 +798,7 @@ public enum BuildingManager { // Attempt to write to database or delete the building // if we are destroying it. - if (rank == -1) + if (rank < 0) success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building); else success = DbManager.BuildingQueries.updateBuildingRank(building, rank); From 62235497ad948265675cdca66fb4d9db126112fb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 16:53:51 -0400 Subject: [PATCH 08/11] Returns all not just active mines --- src/engine/objects/Mine.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index dabfb557..553c1036 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -220,8 +220,7 @@ public class Mine extends AbstractGameObject { // Only inactive mines are returned. for (Mine mine : Mine.mineMap.keySet()) { - if (mine.owningGuild.getObjectUUID() == guildID && - mine.isActive == false) + if (mine.owningGuild.getObjectUUID() == guildID) mineList.add(mine); } return mineList; From 20c032fa4dd49149b424d8956eccf28551ca1d4e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:03:48 -0400 Subject: [PATCH 09/11] Hash value updated. --- src/engine/mbEnums.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/mbEnums.java b/src/engine/mbEnums.java index c75d7a05..1ef6443e 100644 --- a/src/engine/mbEnums.java +++ b/src/engine/mbEnums.java @@ -2732,7 +2732,7 @@ public class mbEnums { DIAMOND(1580010, 1540225085, -1730704107, 2000, 20), GALVOR(1580017, -1683992404, -1596311545, 2000, 5), IRON(1580002, -1673518119, 2504297, 2000, 20), - LUMBER(1580004, 1628412684, -1603256692, 10000, 100), + LUMBER(1580004, -1628412684, -1603256692, 10000, 100), MANDRAKE(1580007, 1519910613, 1191391799, 1000, 10), MITHRIL(1580021, 626743397, -1761257186, 500, 5), OAK(1580005, -1653034775, 74767, 3000, 30), From 668b61b734fdf176cf55515a0f9755a987eaaeaa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:11:01 -0400 Subject: [PATCH 10/11] city.isDestroyed --- src/engine/objects/City.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index a4591532..52f09882 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -41,6 +41,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; public class City extends AbstractWorldObject { @@ -80,6 +81,7 @@ public class City extends AbstractWorldObject { private String hash; public Warehouse warehouse; public Realm realm; + public AtomicBoolean isDestroyed = new AtomicBoolean(false); /** * ResultSet Constructor @@ -1102,10 +1104,14 @@ public class City extends AbstractWorldObject { public final void destroy() { - Thread destroyCityThread = new Thread(new DestroyCityThread(this)); + if (this.isDestroyed.compareAndSet(false, true)) { - destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); - destroyCityThread.start(); + Thread destroyCityThread = new Thread(new DestroyCityThread(this)); + + destroyCityThread.setName("destroyCity:" + this.getParent().zoneName); + destroyCityThread.start(); + } else + Logger.error("Attempt to destroy destroyed city"); } public final void transfer(AbstractCharacter newOwner) { From dfa646d8280786acfbe047e95c526bda408bfc0e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 17:31:28 -0400 Subject: [PATCH 11/11] Update to player city filter --- src/engine/objects/City.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 52f09882..a9fae4b6 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -308,6 +308,21 @@ public class City extends AbstractWorldObject { if (city.parentZone == null) continue; + // Can't teleport to something without a tree + + if (city.getTOL() == null) + continue; + + // No abandoned cities + + if (city.getTOL().getGuild().isEmptyGuild()) + continue; + + // No destroyed cities + + if (city.getTOL().getRank() == -1) + continue; + //can't repledge to a guild you're already part of if (repledge && city.getGuild().equals(playerCharacter.guild))