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

168 lines
6.1 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;
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
2024-08-25 15:18:40 -04:00
try {
cityZone = city.getParent();
newParent = cityZone.parent;
formerGuild = city.getTOL().getGuild();
2022-04-30 09:41:17 -04:00
2024-08-25 15:26:14 -04:00
Logger.info("Destroy city thread started for: " + newParent.zoneName);
2024-08-25 15:18:40 -04:00
// Former guild loses tree!
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
//Successful Update of guild
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
formerGuild.setGuildState(mbEnums.GuildState.Errant);
formerGuild.setNation(null);
formerGuild.setCityUUID(0);
GuildManager.updateAllGuildTags(formerGuild);
GuildManager.updateAllGuildBinds(formerGuild, null);
}
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// By losing the tree, the former owners lose all of their subguilds.
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
if (!formerGuild.getSubGuildList().isEmpty()) {
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
subGuildList = new ArrayList<>();
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
subGuildList.addAll(formerGuild.getSubGuildList());
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
for (Guild subGuild : subGuildList) {
formerGuild.removeSubGuild(subGuild);
}
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// Build list of buildings within this parent zone
2024-03-18 06:46:28 -04:00
2024-08-25 15:18:40 -04:00
for (Building cityBuilding : cityZone.zoneBuildingSet) {
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -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
2024-08-25 15:18:40 -04:00
if (cityBuilding == null)
continue;
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// Do nothing with the banestone. It will be removed elsewhere
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE))
continue;
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// All buildings are moved to a location relative
// to their new parent zone
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent);
2024-03-18 06:46:28 -04:00
2024-08-25 15:18:40 -04:00
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z);
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -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
2024-08-25 15:18:40 -04:00
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID())
cityBuilding.setParentZone(newParent);
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// No longer a tree, no longer any protection contract!
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
cityBuilding.setProtectionState(mbEnums.ProtectionState.NONE);
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// Remove warehouse entry if one exists.
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) {
DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse);
city.warehouse = null;
}
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
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)) {
2024-08-25 15:18:40 -04:00
if (cityBuilding.getRank() != -1)
BuildingManager.setRank(cityBuilding, -1);
}
}
2024-08-25 15:18:40 -04:00
if (city.realm != null) {
city.realm.removeCity(city.getObjectUUID());
city.realm = null;
2023-07-15 09:23:48 -04:00
}
2024-03-18 06:46:28 -04:00
2024-08-25 15:18:40 -04:00
// It's now safe to delete the city zone from the database
// which will cause a cascade delete of everything else
2024-03-18 06:46:28 -04:00
2024-08-25 15:18:40 -04:00
if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) {
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
return;
}
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
// Refresh the city for map requests
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
City.lastCityUpdate = System.currentTimeMillis();
2022-04-30 09:41:17 -04:00
2024-08-25 15:18:40 -04:00
} catch (Exception e) {
Logger.error(e);
2023-07-15 09:23:48 -04:00
}
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
}