Method made static and moved to manager.
This commit is contained in:
@@ -80,7 +80,7 @@ public class Building extends AbstractWorldObject {
|
||||
/* The Blueprint class has methods able to derive
|
||||
* all defining characteristics of this building,
|
||||
*/
|
||||
private int blueprintUUID = 0;
|
||||
public int blueprintUUID = 0;
|
||||
private float w = 1.0f;
|
||||
private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
private int doorState = 0;
|
||||
@@ -96,7 +96,7 @@ public class Building extends AbstractWorldObject {
|
||||
private ConcurrentHashMap<String, Long> timestamps = null;
|
||||
private ConcurrentHashMap<Integer, BuildingFriends> friends = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<Integer, Condemned> condemned = new ConcurrentHashMap<>();
|
||||
private ProtectionState protectionState = ProtectionState.NONE;
|
||||
public ProtectionState protectionState = ProtectionState.NONE;
|
||||
private ArrayList<Building> children = null;
|
||||
|
||||
/**
|
||||
@@ -277,86 +277,6 @@ public class Building extends AbstractWorldObject {
|
||||
return rank;
|
||||
}
|
||||
|
||||
public final void setRank(int newRank) {
|
||||
|
||||
int newMeshUUID;
|
||||
boolean success;
|
||||
|
||||
|
||||
// If this building has no blueprint then set rank and exit immediatly.
|
||||
|
||||
if (this.blueprintUUID == 0 || this.getBlueprint() != null && this.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE)) {
|
||||
this.rank = newRank;
|
||||
DbManager.BuildingQueries.CHANGE_RANK(this.getObjectUUID(), newRank);
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete any upgrade jobs before doing anything else. It won't quite work
|
||||
// if in a few lines we happen to delete this building.
|
||||
|
||||
JobContainer jc = this.getTimers().get("UPGRADE");
|
||||
|
||||
if (jc != null) {
|
||||
if (!JobScheduler.getInstance().cancelScheduledJob(jc))
|
||||
Logger.error("failed to cancel existing upgrade job.");
|
||||
}
|
||||
|
||||
// Attempt write to database, or delete the building
|
||||
// if we are destroying it.
|
||||
|
||||
if (newRank == -1)
|
||||
success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(this);
|
||||
else
|
||||
success = DbManager.BuildingQueries.updateBuildingRank(this, newRank);
|
||||
|
||||
if (success == false) {
|
||||
Logger.error("Error writing to database UUID: " + this.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
this.isDeranking.compareAndSet(false, true);
|
||||
|
||||
// Change the building's rank
|
||||
|
||||
this.rank = newRank;
|
||||
|
||||
// New rank means new mesh
|
||||
|
||||
newMeshUUID = this.getBlueprint().getMeshForRank(this.rank);
|
||||
this.meshUUID = newMeshUUID;
|
||||
|
||||
// New rank mean new max hitpoints.
|
||||
|
||||
this.healthMax = this.getBlueprint().getMaxHealth(this.rank);
|
||||
this.setCurrentHitPoints(this.healthMax);
|
||||
|
||||
if (this.getUpgradeDateTime() != null)
|
||||
BuildingManager.setUpgradeDateTime(this, null, 0);
|
||||
|
||||
// If we destroyed this building make sure to turn off
|
||||
// protection
|
||||
|
||||
if (this.rank == -1)
|
||||
this.protectionState = ProtectionState.NONE;
|
||||
|
||||
if ((this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)
|
||||
&& (this.rank == 8))
|
||||
this.meshUUID = Realm.getRealmMesh(this.getCity());
|
||||
;
|
||||
|
||||
// update object to clients
|
||||
|
||||
this.refresh(true);
|
||||
if (this.getBounds() != null)
|
||||
this.getBounds().setBounds(this);
|
||||
|
||||
// Cleanup hirelings resulting from rank change
|
||||
|
||||
BuildingManager.cleanupHirelings(this);
|
||||
|
||||
this.isDeranking.compareAndSet(true, false);
|
||||
}
|
||||
|
||||
public final int getOwnerUUID() {
|
||||
return ownerUUID;
|
||||
}
|
||||
@@ -528,7 +448,7 @@ public class Building extends AbstractWorldObject {
|
||||
MineRecord mineRecord = MineRecord.borrow(mine, attacker, RecordEventType.DESTROY);
|
||||
DataWarehouse.pushToWarehouse(mineRecord);
|
||||
|
||||
this.setRank(-1);
|
||||
BuildingManager.setRank(this, -1);
|
||||
this.setCurrentHitPoints((float) 1);
|
||||
this.healthMax = (float) 1;
|
||||
this.meshUUID = this.getBlueprint().getMeshForRank(this.rank);
|
||||
@@ -551,9 +471,9 @@ public class Building extends AbstractWorldObject {
|
||||
// Time to either derank or destroy the building.
|
||||
|
||||
if ((this.rank - 1) < 1)
|
||||
this.setRank(-1);
|
||||
BuildingManager.setRank(this, -1);
|
||||
else
|
||||
this.setRank(this.rank - 1);
|
||||
BuildingManager.setRank(this, this.rank - 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -611,7 +531,7 @@ public class Building extends AbstractWorldObject {
|
||||
|
||||
if (spireBuilding != null) {
|
||||
spireBuilding.disableSpire(true);
|
||||
spireBuilding.setRank(-1);
|
||||
BuildingManager.setRank(spireBuilding, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,7 +542,7 @@ public class Building extends AbstractWorldObject {
|
||||
// Delete a random shrine
|
||||
|
||||
if (shrineBuilding != null)
|
||||
shrineBuilding.setRank(-1);
|
||||
BuildingManager.setRank(shrineBuilding, -1);
|
||||
}
|
||||
|
||||
if (barracksBuildings.size() > this.rank - 1) {
|
||||
@@ -632,7 +552,7 @@ public class Building extends AbstractWorldObject {
|
||||
// Delete a random barrack
|
||||
|
||||
if (barracksBuilding != null)
|
||||
barracksBuilding.setRank(-1);
|
||||
BuildingManager.setRank(barracksBuilding, -1);
|
||||
}
|
||||
|
||||
// If the tree is R8 and deranking, we need to update it's
|
||||
@@ -661,7 +581,7 @@ public class Building extends AbstractWorldObject {
|
||||
// Let's do so and early exit
|
||||
|
||||
if (this.rank > 1) {
|
||||
this.setRank(rank - 1);
|
||||
BuildingManager.setRank(this, rank - 1);
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user