Browse Source

Cleanup building initialization

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
602f8bc843
  1. 40
      src/engine/db/handlers/dbZoneHandler.java
  2. 149
      src/engine/objects/Building.java

40
src/engine/db/handlers/dbZoneHandler.java

@ -44,27 +44,6 @@ public class dbZoneHandler extends dbHandlerBase { @@ -44,27 +44,6 @@ public class dbZoneHandler extends dbHandlerBase {
return zoneList;
}
public ArrayList<Zone> GET_ALL_NODES(Zone zone) {
ArrayList<Zone> wsmList = new ArrayList<>();
wsmList.addAll(zone.nodes);
if (zone.absX == 0.0f) {
zone.absX = zone.xOffset;
}
if (zone.absY == 0.0f) {
zone.absY = zone.yOffset;
}
if (zone.absZ == 0.0f) {
zone.absZ = zone.zOffset;
}
for (Zone child : zone.nodes) {
child.absX = child.xOffset + zone.absX;
child.absY = child.yOffset + zone.absY;
child.absZ = child.zOffset + zone.absZ;
wsmList.addAll(this.GET_ALL_NODES(child));
}
return wsmList;
}
public Zone GET_BY_UID(long ID) {
Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID);
@ -87,25 +66,6 @@ public class dbZoneHandler extends dbHandlerBase { @@ -87,25 +66,6 @@ public class dbZoneHandler extends dbHandlerBase {
return zone;
}
public ArrayList<Zone> GET_MAP_NODES(final int objectUUID) {
ArrayList<Zone> zoneList = new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
zoneList = getObjectsFromRs(rs, 2000);
} catch (SQLException e) {
Logger.error(e);
}
return zoneList;
}
public boolean DELETE_ZONE(final Zone zone) {
try (Connection connection = DbManager.getConnection();

149
src/engine/objects/Building.java

@ -55,6 +55,7 @@ public class Building extends AbstractWorldObject { @@ -55,6 +55,7 @@ public class Building extends AbstractWorldObject {
private final HashMap<Integer, DoorCloseJob> doorJobs = new HashMap<>();
public int meshUUID;
public Zone parentZone;
public int parentZoneUUID;
public boolean reverseKOS;
public int reserve = 0;
public float statLat;
@ -106,27 +107,23 @@ public class Building extends AbstractWorldObject { @@ -106,27 +107,23 @@ public class Building extends AbstractWorldObject {
super(rs);
float scale;
Blueprint blueprint = null;
try {
this.meshUUID = rs.getInt("meshUUID");
this.setObjectTypeMask(MBServerStatics.MASK_BUILDING);
this.blueprintUUID = rs.getInt("blueprintUUID");
this.gridObjectType = GridObjectType.STATIC;
this.parentZone = DbManager.ZoneQueries.GET_BY_UID(rs.getLong("parent"));
this.parentZoneUUID = rs.getInt("parent");
this.name = rs.getString("name");
this.ownerUUID = rs.getInt("ownerUUID");
// Orphaned Object Sanity Check
//This was causing ABANDONED Tols.
// if (objectType == DbObjectType.INVALID)
// this.ownerUUID = 0;
this.doorState = rs.getInt("doorState");
this.setHealth(rs.getInt("currentHP"));
this.w = rs.getFloat("w");
this.setRot(new Vector3f(0f, rs.getFloat("rotY"), 0f));
this.reverseKOS = rs.getByte("reverseKOS") == 1 ? true : false;
this.reverseKOS = rs.getByte("reverseKOS") == 1;
this.statLat = rs.getFloat("locationX");
this.statAlt = rs.getFloat("locationY");
this.statLon = rs.getFloat("locationZ");
scale = rs.getFloat("scale");
this.meshScale = new Vector3f(scale, scale, scale);
@ -143,79 +140,10 @@ public class Building extends AbstractWorldObject { @@ -143,79 +140,10 @@ public class Building extends AbstractWorldObject {
this.level = rs.getInt("level");
this.isFurniture = (rs.getBoolean("isFurniture"));
// Lookup building blueprint
if (this.blueprintUUID == 0)
blueprint = Blueprint._meshLookup.get(meshUUID);
else
blueprint = this.getBlueprint();
// Log error if something went horrible wrong
if ((this.blueprintUUID != 0) && (blueprint == null))
Logger.error("Invalid blueprint for object: " + this.getObjectUUID());
// Note: We handle R8 tree edge case for mesh and health
// after city is loaded to avoid recursive result set call
// in City resulting in a stack ovreflow.
if (blueprint != null) {
// Only switch mesh for player dropped structures
if (this.blueprintUUID != 0)
this.meshUUID = blueprint.getMeshForRank(rank);
this.healthMax = blueprint.getMaxHealth(this.rank);
// If this object has no blueprint but is a blueprint
// mesh then set it's current health to max health
if (this.blueprintUUID == 0)
this.setHealth(healthMax);
if (blueprint.getBuildingGroup().equals(BuildingGroup.BARRACK))
this.patrolPoints = DbManager.BuildingQueries.LOAD_PATROL_POINTS(this);
} else {
this.healthMax = 100000; // Structures with no blueprint mesh
this.setHealth(healthMax);
}
// Null out blueprint if not needed (npc building)
if (blueprintUUID == 0)
blueprint = null;
resists = new Resists("Building");
this.statLat = rs.getFloat("locationX");
this.statAlt = rs.getFloat("locationY");
this.statLon = rs.getFloat("locationZ");
if (this.parentZone != null) {
if (this.parentBuildingID != 0) {
Building parentBuilding = BuildingManager.getBuilding(this.parentBuildingID);
if (parentBuilding != null) {
this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX + parentBuilding.statLat, this.statAlt + this.parentZone.absY + parentBuilding.statAlt, this.statLon + this.parentZone.absZ + parentBuilding.statLon));
} else {
this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX, this.statAlt + this.parentZone.absY, this.statLon + this.parentZone.absZ));
}
} else {
// Altitude of this building is derived from the heightmap engine.
Vector3fImmutable tempLoc = new Vector3fImmutable(this.statLat + this.parentZone.absX, 0, this.statLon + this.parentZone.absZ);
tempLoc = new Vector3fImmutable(tempLoc.x, Terrain.getWorldHeight(tempLoc), tempLoc.z);
this.setLoc(tempLoc);
}
}
this._strongboxValue = rs.getInt("currentGold");
this.maxGold = 15000000; // *** Refactor to blueprint method
this.reserve = rs.getInt("reserve");
// Does building have a protection contract?
this.taxType = TaxType.valueOf(rs.getString("taxType"));
this.taxAmount = rs.getInt("taxAmount");
this.protectionState = ProtectionState.valueOf(rs.getString("protectionState"));
@ -236,7 +164,6 @@ public class Building extends AbstractWorldObject { @@ -236,7 +164,6 @@ public class Building extends AbstractWorldObject {
this.upgradeDateTime = LocalDateTime.ofInstant(upgradeTimeStamp.toInstant(), ZoneId.systemDefault());
} catch (Exception e) {
Logger.error("Failed for object " + this.blueprintUUID + ' ' + this.getObjectUUID() + e.toString());
}
}
@ -1076,8 +1003,72 @@ public class Building extends AbstractWorldObject { @@ -1076,8 +1003,72 @@ public class Building extends AbstractWorldObject {
try {
// Lookup building blueprint
Blueprint blueprint;
if (this.blueprintUUID == 0)
blueprint = Blueprint._meshLookup.get(meshUUID);
else
blueprint = this.getBlueprint();
// Log error if something went horrible wrong
if ((this.blueprintUUID != 0) && (blueprint == null))
Logger.error("Invalid blueprint for object: " + this.getObjectUUID());
// Note: We handle R8 tree edge case for mesh and health
// after city is loaded to avoid recursive result set call
// in City resulting in a stack ovreflow.
if (blueprint != null) {
// Only switch mesh for player dropped structures
if (this.blueprintUUID != 0)
this.meshUUID = blueprint.getMeshForRank(rank);
this.healthMax = blueprint.getMaxHealth(this.rank);
// If this object has no blueprint but is a blueprint
// mesh then set it's current health to max health
if (this.blueprintUUID == 0)
this.setHealth(healthMax);
if (blueprint.getBuildingGroup().equals(BuildingGroup.BARRACK))
this.patrolPoints = DbManager.BuildingQueries.LOAD_PATROL_POINTS(this);
} else {
this.healthMax = 100000; // Structures with no blueprint mesh
this.setHealth(healthMax);
}
resists = new Resists("Building");
if (this.parentZone != null) {
if (this.parentBuildingID != 0) {
Building parentBuilding = BuildingManager.getBuilding(this.parentBuildingID);
if (parentBuilding != null) {
this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX + parentBuilding.statLat, this.statAlt + this.parentZone.absY + parentBuilding.statAlt, this.statLon + this.parentZone.absZ + parentBuilding.statLon));
} else {
this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX, this.statAlt + this.parentZone.absY, this.statLon + this.parentZone.absZ));
}
} else {
// Altitude of this building is derived from the heightmap engine.
Vector3fImmutable tempLoc = new Vector3fImmutable(this.statLat + this.parentZone.absX, 0, this.statLon + this.parentZone.absZ);
tempLoc = new Vector3fImmutable(tempLoc.x, Terrain.getWorldHeight(tempLoc), tempLoc.z);
this.setLoc(tempLoc);
}
}
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
this.parentZone.zoneBuildingSet.add(this);
// Submit upgrade job if building is currently set to rank.
try {

Loading…
Cancel
Save