Garbage cleanup in SetZone().

Package reformat.
This commit is contained in:
2023-05-23 10:27:03 -04:00
parent a2d62ec221
commit 6dd7315786
29 changed files with 2901 additions and 2937 deletions
+115 -150
View File
@@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap;
public class Zone extends AbstractGameObject {
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final int playerCityID;
private final String zoneName;
private final float xCoord;
private final float zCoord;
private final float yCoord;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
private final int loadNum;
private final byte safeZone;
private final String Icon1;
private final String Icon2;
private final String Icon3;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
public int minLvl;
public int maxLvl;
public boolean hasBeenHotzone = false;
private ArrayList<Zone> nodes = null;
private int parentZoneID;
private Zone parent = null;
@@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject {
private boolean isNPCCity = false;
private boolean isPlayerCity = false;
private String hash;
public int minLvl;
public int maxLvl;
private float worldAltitude = 0;
private float seaLevel = 0;
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public boolean hasBeenHotzone = false;
/**
* ResultSet Constructor
*/
@@ -87,7 +86,7 @@ public class Zone extends AbstractGameObject {
this.setParent(parentZone);
if (this.minLvl == 0 && parentZone != null){
if (this.minLvl == 0 && parentZone != null) {
this.minLvl = parentZone.minLvl;
this.maxLvl = parentZone.maxLvl;
}
@@ -99,8 +98,61 @@ public class Zone extends AbstractGameObject {
if (hash == null)
setHash();
}
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
} else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child, writer);
}
}
/* Method sets a default value for player cities
@@ -123,38 +175,18 @@ public class Zone extends AbstractGameObject {
return;
}
// All other zones have bounding boxes loaded from database
ResultSet rs = DbManager.ZoneQueries.GET_ZONE_EXTENTS(this.loadNum);
boolean loaded = false;
Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum);
if (rs != null)
try {
if (rs.next()) {
halfExtentX = rs.getFloat("xRadius");
halfExtentY = rs.getFloat("zRadius");
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(halfExtentX, halfExtentY), 0.0f);
loaded = true;
}
} catch (SQLException e) {
Logger.error("SQLException: " + e.getMessage());
}
if (!loaded) {
// Default to Citygrid size on error
// Default to player zone size on error? Maybe log this
if (zoneSize != null)
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f);
else
bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f);
}
}
/*
* Getters
*/
public int getPlayerCityUUID() {
if (this.playerCityID == 0)
return 0;
return this.playerCityID;
}
@@ -178,10 +210,6 @@ public class Zone extends AbstractGameObject {
return loadNum;
}
public int getLoadNumClient() {
return loadNum;
}
public byte getSafeZone() {
return safeZone;
}
@@ -190,45 +218,9 @@ public class Zone extends AbstractGameObject {
return Icon1;
}
public String getIcon2() {
return Icon2;
}
public void generateWorldAltitude() {
public String getIcon3() {
return Icon3;
}
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0){
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public void generateWorldAltitude(){
if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()){
if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) {
this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE;
return;
}
@@ -240,9 +232,9 @@ public class Zone extends AbstractGameObject {
//seafloor only zone with null parent;
while(parentZone != ZoneManager.getSeaFloor()){
while (parentZone != ZoneManager.getSeaFloor()) {
if(parentZone.getHeightMap() != null){
if (parentZone.getHeightMap() != null) {
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone);
altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
@@ -258,14 +250,14 @@ public class Zone extends AbstractGameObject {
if (ZoneManager.getSeaFloor().equals(this))
this.seaLevel = 0;
else if
(this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0){
this.seaLevel = this.parent.seaLevel;
(this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) {
this.seaLevel = this.parent.seaLevel;
}else if (this.getHeightMap() != null){
} else if (this.getHeightMap() != null) {
this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel();
}else {
this.seaLevel = this.parent.seaLevel;
}
} else {
this.seaLevel = this.parent.seaLevel;
}
}
@@ -273,6 +265,34 @@ public class Zone extends AbstractGameObject {
return this.parent;
}
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0) {
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public float getAbsX() {
return this.absX;
}
@@ -302,14 +322,14 @@ public class Zone extends AbstractGameObject {
return this.isNPCCity;
}
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setNPCCity(boolean value) {
this.isNPCCity = value;
}
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setPlayerCity(boolean value) {
this.isPlayerCity = value;
}
@@ -336,67 +356,12 @@ public class Zone extends AbstractGameObject {
return nodes;
}
public void addNode(Zone child) {
this.nodes.add(child);
}
/*
* Serializing
*/
public static void serializeForClientMsg(Zone zone,ByteBufferWriter writer) {
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn( "Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
}
else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child,writer);
}
public void addNode(Zone child) {
this.nodes.add(child);
}
@Override
@@ -442,7 +407,7 @@ public class Zone extends AbstractGameObject {
// Return heightmap for this Zone.
public HeightMap getHeightMap() {
if (this.isPlayerCity)
return HeightMap.PlayerCityHeightMap;