diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index ffd08263..f1606434 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -10,8 +10,6 @@ package engine.gameManager; import engine.Enum; import engine.InterestManagement.Terrain; -import engine.db.archive.CityRecord; -import engine.db.archive.DataWarehouse; import engine.math.Bounds; import engine.math.Vector2f; import engine.math.Vector3f; @@ -424,33 +422,6 @@ public enum ZoneManager { return validLocation; } - public static void loadCities(Zone zone) { - - ArrayList cities = DbManager.CityQueries.GET_CITIES_BY_ZONE(zone.getObjectUUID()); - - for (City city : cities) { - - city.setParent(zone); - city.setObjectTypeMask(MBServerStatics.MASK_CITY); - city.setLoc(city.getLoc()); // huh? - -//not player city, must be npc city.. - - if (!zone.guild_zone) - zone.isNPCCity = true; - - if ((ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) && (city.getHash() == null)) { - - city.setHash(); - - if (DataWarehouse.recordExists(Enum.DataRecordType.CITY, city.getObjectUUID()) == false) { - CityRecord cityRecord = CityRecord.borrow(city, Enum.RecordEventType.CREATE); - DataWarehouse.pushToWarehouse(cityRecord); - } - } - } - } - public static float calculateGlobalZoneHeight(Zone zone) { float worldAlttitude = MBServerStatics.SEA_FLOOR_ALTITUDE; diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index c62c7e8c..0d6e0bc8 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -794,9 +794,6 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { zoneObject.global_height = ZoneManager.calculateGlobalZoneHeight(zoneObject); - cityObject.setParent(zoneObject); - cityObject.setObjectTypeMask(MBServerStatics.MASK_CITY); // *** Refactor : should have it already - //Link the tree of life with the new zone treeObject.setObjectTypeMask(MBServerStatics.MASK_BUILDING); diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 69ab5aba..9d9037b1 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -48,6 +48,8 @@ public class City extends AbstractWorldObject { public static long lastCityUpdate = 0; public final HashSet _playerMemory = new HashSet<>(); + private final boolean isOpen = false; + private final boolean reverseKOS = false; public java.time.LocalDateTime established; public boolean hasBeenTransfered = false; public LocalDateTime realmTaxDate; @@ -55,7 +57,8 @@ public class City extends AbstractWorldObject { public volatile boolean protectionEnforced = true; public ArrayList cityBarracks; public ArrayList cityOutlaws = new ArrayList<>(); - protected Zone parentZone; + public Zone parentZone; + public int parentZoneUUID; private String cityName; private String motto; private String description; @@ -73,15 +76,12 @@ public class City extends AbstractWorldObject { private boolean forceRename = false; private boolean noTeleport = false; //used by npc cities private boolean noRepledge = false; //used by npc cities - private final boolean isOpen = false; private int treeOfLifeID; private Vector3fImmutable location = Vector3fImmutable.ZERO; - // Players who have entered the city (used for adding and removing affects) private Vector3fImmutable bindLoc; private int warehouseBuildingID = 0; private boolean open = false; - private boolean reverseKOS = false; private String hash; /** @@ -91,6 +91,7 @@ public class City extends AbstractWorldObject { public City(ResultSet rs) throws SQLException { super(rs); try { + this.parentZoneUUID = rs.getInt("parent"); this.cityName = rs.getString("name"); this.motto = rs.getString("motto"); this.isNpc = rs.getByte("isNpc"); @@ -126,7 +127,9 @@ public class City extends AbstractWorldObject { this.location.getY(), this.location.getZ() + this.bindZ); this.radiusType = rs.getInt("radiusType"); + float bindradiustemp = rs.getFloat("bindRadius"); + if (bindradiustemp > 2) bindradiustemp -= 2; @@ -135,30 +138,8 @@ public class City extends AbstractWorldObject { this.forceRename = rs.getInt("forceRename") == 1; this.open = rs.getInt("open") == 1; - if (this.cityName.equals("Perdition") || this.cityName.equals("Bastion")) { - this.noTeleport = true; - this.noRepledge = true; - } else { - this.noTeleport = false; - this.noRepledge = false; - } - this.hash = rs.getString("hash"); - if (this.motto.isEmpty()) { - Guild guild = this.getGuild(); - - if (guild != null && guild.isEmptyGuild() == false) - this.motto = guild.getMotto(); - } - - Zone zone = ZoneManager.getZoneByUUID(rs.getInt("parent")); - - if (zone != null) - setParent(zone); - - //npc cities without heightmaps except swampstone are specials. - this.realmID = rs.getInt("realmID"); } catch (Exception e) { @@ -567,30 +548,6 @@ public class City extends AbstractWorldObject { return this.parentZone; } - public void setParent(Zone zone) { - - try { - - - this.parentZone = zone; - this.location = new Vector3fImmutable(zone.absX, zone.absY, zone.absZ); - this.bindLoc = new Vector3fImmutable(this.location.x + this.bindX, - this.location.y, - this.location.z + this.bindZ); - - // set city bounds - - Bounds cityBounds = Bounds.borrow(); - cityBounds.setBounds(new Vector2f(this.location.x + 64, this.location.z + 64), // location x and z are offset by 64 from the center of the city. - new Vector2f(Enum.CityBoundsType.GRID.halfExtents, Enum.CityBoundsType.GRID.halfExtents), - 0.0f); - this.setBounds(cityBounds); - - } catch (Exception e) { - Logger.error(e); - } - } - public AbstractCharacter getOwner() { if (this.getTOL() == null) @@ -720,9 +677,31 @@ public class City extends AbstractWorldObject { @Override public void runAfterLoad() { - // Set city bounds - // *** Note: Moved to SetParent() - // for some undocumented reason + this.setObjectTypeMask(MBServerStatics.MASK_CITY); + + // Set parent + + this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID); + + // If it's not a player city then must be an NPC city + + if (!parentZone.guild_zone) + parentZone.isNPCCity = true; + + // Set location for this city + + this.location = new Vector3fImmutable(this.parentZone.absX, this.parentZone.absY, this.parentZone.absZ); + this.bindLoc = new Vector3fImmutable(this.location.x + this.bindX, + this.location.y, + this.location.z + this.bindZ); + + // set city bounds + + Bounds cityBounds = Bounds.borrow(); + cityBounds.setBounds(new Vector2f(this.location.x + 64, this.location.z + 64), // location x and z are offset by 64 from the center of the city. + new Vector2f(Enum.CityBoundsType.GRID.halfExtents, Enum.CityBoundsType.GRID.halfExtents), + 0.0f); + this.setBounds(cityBounds); // Set city motto to current guild motto @@ -749,8 +728,10 @@ public class City extends AbstractWorldObject { for (Guild sub : this.getGuild().getSubGuildList()) { if ((sub.getGuildState() == GuildState.Protectorate) || - (sub.getGuildState() == GuildState.Province)) + (sub.getGuildState() == GuildState.Province)) { this.isCapital = 1; + break; + } } ArrayList guildList = Guild.GuildRoster(this.getGuild()); @@ -758,6 +739,26 @@ public class City extends AbstractWorldObject { this.population = guildList.size(); } + if (this.cityName.equals("Perdition") || this.cityName.equals("Bastion")) { + this.noTeleport = true; + this.noRepledge = true; + } else { + this.noTeleport = false; + this.noRepledge = false; + } + + // Add city entry to data warehouse if newly created + + if ((ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) && (this.getHash() == null)) { + + this.setHash(); + + if (DataWarehouse.recordExists(Enum.DataRecordType.CITY, this.getObjectUUID()) == false) { + CityRecord cityRecord = CityRecord.borrow(this, Enum.RecordEventType.CREATE); + DataWarehouse.pushToWarehouse(cityRecord); + } + } + // Banes are loaded for this city from the database at this point if (this.getBane() == null) @@ -765,12 +766,12 @@ public class City extends AbstractWorldObject { // if this city is baned, add the siege effect - try { - this.getTOL().addEffectBit((1 << 16)); - this.getBane().getStone().addEffectBit((1 << 19)); - } catch (Exception e) { - Logger.info("Failed ao add bane effects on city." + e.getMessage()); - } + this.getTOL().addEffectBit((1 << 16)); + this.getBane().getStone().addEffectBit((1 << 19)); + + // Spawn city + + this.setLoc(this.getLoc()); } public void addCityEffect(EffectsBase effectBase, int rank) {