Files
prestonbane/src/engine/workthreads/DestroyCityThread.java
T

160 lines
5.5 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.workthreads;
/*
* This thread is spawned to process destruction
* of a player owned city, including subguild
* and database cleanup.
*
* The 'destroyed' city zone persists until the
* next reboot.
*/
2023-10-18 11:30:22 -04:00
import engine.gameManager.BuildingManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.DbManager;
import engine.gameManager.GuildManager;
import engine.gameManager.ZoneManager;
import engine.math.Vector3fImmutable;
2024-04-27 11:32:05 -04:00
import engine.mbEnums;
2022-04-30 09:41:17 -04:00
import engine.objects.Building;
import engine.objects.City;
import engine.objects.Guild;
import engine.objects.Zone;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
2024-08-25 07:56:44 -04:00
import java.util.EnumSet;
2022-04-30 09:41:17 -04:00
public class DestroyCityThread implements Runnable {
2023-07-15 09:23:48 -04:00
City city;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public DestroyCityThread(City city) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
this.city = city;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void run() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable declaration
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Zone cityZone;
Zone newParent;
Guild formerGuild;
Vector3fImmutable localCoords;
ArrayList<Guild> subGuildList;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable assignment
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
cityZone = city.getParent();
2023-09-20 15:43:01 -04:00
newParent = cityZone.parent;
2023-07-15 09:23:48 -04:00
formerGuild = city.getTOL().getGuild();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Former guild loses it's tree!
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Successful Update of guild
2022-04-30 09:41:17 -04:00
formerGuild.setGuildState(mbEnums.GuildState.Errant);
2023-07-15 09:23:48 -04:00
formerGuild.setNation(null);
formerGuild.setCityUUID(0);
GuildManager.updateAllGuildTags(formerGuild);
GuildManager.updateAllGuildBinds(formerGuild, null);
}
2022-04-30 09:41:17 -04:00
2024-08-25 07:56:44 -04:00
if (formerGuild.getSubGuildList().isEmpty() == false) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
subGuildList = new ArrayList<>();
2022-04-30 09:41:17 -04:00
2024-08-25 07:56:44 -04:00
for (Guild subGuild : formerGuild.getSubGuildList()) {
subGuildList.add(subGuild);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (Guild subGuild : subGuildList) {
formerGuild.removeSubGuild(subGuild);
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Build list of buildings within this parent zone
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (Building cityBuilding : cityZone.zoneBuildingSet) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Sanity Check in case player deletes the building
// before this thread can get to it
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (cityBuilding == null)
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Do nothing with the banestone. It will be removed elsewhere
2022-04-30 09:41:17 -04:00
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE))
2023-07-15 09:23:48 -04:00
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// All buildings are moved to a location relative
// to their new parent zone
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// 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.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID())
cityBuilding.setParentZone(newParent);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// No longer a tree, no longer any protection contract!
2022-04-30 09:41:17 -04:00
cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE);
2022-04-30 09:41:17 -04:00
// Remove warehouse entry if one exists.
2024-08-25 07:56:44 -04:00
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.WAREHOUSE)) {
DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse);
city.warehouse = null;
}
2024-08-25 07:56:44 -04:00
// Destroy all remaining auto-protected city assets
EnumSet<mbEnums.BuildingGroup> assetsToDestroy = EnumSet.of(mbEnums.BuildingGroup.TOL, mbEnums.BuildingGroup.BARRACK,
mbEnums.BuildingGroup.SPIRE, mbEnums.BuildingGroup.SHRINE, mbEnums.BuildingGroup.WAREHOUSE);
2022-04-30 09:41:17 -04:00
2024-08-25 07:56:44 -04:00
if (assetsToDestroy.contains(cityBuilding.getBlueprint().getBuildingGroup())) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (cityBuilding.getRank() != -1)
2023-10-18 11:30:22 -04:00
BuildingManager.setRank(cityBuilding, -1);
2023-07-15 09:23:48 -04:00
}
}
2022-04-30 09:41:17 -04:00
2024-04-27 11:32:05 -04:00
if (city.realm != null)
city.realm.removeCity(city.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// It's now safe to delete the city zone from the database
// which will cause a cascade delete of everything else
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) {
2024-08-25 07:56:44 -04:00
Logger.error("DestroyCityThread", "Error when deleting city zone: " + cityZone.getObjectUUID());
2023-07-15 09:23:48 -04:00
return;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Refresh the city for map requests
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
City.lastCityUpdate = System.currentTimeMillis();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Zone and city should vanish upon next reboot
// if the codebase reaches here.
2023-09-20 15:43:01 -04:00
Logger.info(city.getParent().zoneName + " uuid:" + city.getObjectUUID() + "has been destroyed!");
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
}