Compare commits

..

4 Commits

4 changed files with 121 additions and 116 deletions
+1 -1
View File
@@ -798,7 +798,7 @@ public enum BuildingManager {
// Attempt to write to database or delete the building
// if we are destroying it.
if (rank < 0)
if (rank == -1)
success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building);
else
success = DbManager.BuildingQueries.updateBuildingRank(building, rank);
+1 -1
View File
@@ -561,7 +561,7 @@ public class Building extends AbstractWorldObject {
BuildingManager.setRank(barracksBuilding, -1);
}
// If the tree is R8 and deranking, we need to update the
// If the tree is R8 and deranking, we need to update it's
// mesh along with buildings losing their health bonus
if (this.rank == 8) {
+2 -9
View File
@@ -41,7 +41,6 @@ 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 {
@@ -81,7 +80,6 @@ public class City extends AbstractWorldObject {
private String hash;
public Warehouse warehouse;
public Realm realm;
public AtomicBoolean isDestroyed = new AtomicBoolean(false);
/**
* ResultSet Constructor
@@ -324,7 +322,6 @@ public class City extends AbstractWorldObject {
continue;
//can't repledge to a guild you're already part of
if (repledge && city.getGuild().equals(playerCharacter.guild))
continue;
@@ -1119,21 +1116,17 @@ public class City extends AbstractWorldObject {
public final void destroy() {
if (this.isDestroyed.compareAndSet(false, true)) {
Thread destroyCityThread = new Thread(new DestroyCityThread(this));
destroyCityThread.setName("destroyCity:" + this.getParent().zoneName);
destroyCityThread.setName("destroyCity:" + this.getName());
destroyCityThread.start();
} else
Logger.error("Attempt to destroy destroyed city");
}
public final void transfer(AbstractCharacter newOwner) {
Thread transferCityThread = new Thread(new TransferCityThread(this, newOwner));
transferCityThread.setName("TransferCity:" + this.getParent().zoneName);
transferCityThread.setName("TransferCity:" + this.getName());
transferCityThread.start();
}
+34 -22
View File
@@ -53,14 +53,11 @@ public class DestroyCityThread implements Runnable {
// Member variable assignment
try {
cityZone = city.getParent();
newParent = cityZone.parent;
formerGuild = city.getTOL().getGuild();
Logger.info("Destroy city thread started for: " + cityZone.zoneName);
// Former guild loses tree!
// Former guild loses it's tree!
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
@@ -86,9 +83,9 @@ public class DestroyCityThread implements Runnable {
}
}
// Build list of buildings within this parent zone
Building tol = null;
ArrayList<Building> destroySet = new ArrayList<>();
// Build list of buildings within this parent zone
for (Building cityBuilding : cityZone.zoneBuildingSet) {
@@ -98,11 +95,24 @@ public class DestroyCityThread implements Runnable {
if (cityBuilding == null)
continue;
// check null bluepritn and log error
if (cityBuilding.getBlueprint() == null){
Logger.error("Null Blueprint for building ID: " + cityBuilding.getObjectUUID());
continue;
}
// Do nothing with the banestone. It will be removed elsewhere
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE))
continue;
// TOL is processed after all other structures in the city zone
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.TOL)) {
tol = cityBuilding;
continue;
}
// All buildings are moved to a location relative
// to their new parent zone
@@ -128,27 +138,33 @@ public class DestroyCityThread implements Runnable {
city.warehouse = null;
}
// Mark all auto protected buildings for destruction
// 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))
destroySet.add(cityBuilding);
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);
}
}
// Destroy set of auto-protected buildings
// Destroy the tol
for (Building building : destroySet)
if (building.getRank() != -1)
BuildingManager.setRank(building, -1);
if (tol != null)
BuildingManager.setRank(tol, -1);
if (city.realm != null) {
if (city.realm != null)
city.realm.removeCity(city.getObjectUUID());
city.realm = 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)) {
if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) {
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
return;
}
@@ -157,13 +173,9 @@ public class DestroyCityThread implements Runnable {
City.lastCityUpdate = System.currentTimeMillis();
} catch (Exception e) {
Logger.error(e);
}
// 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!");
}
}