Method made static and moved to manager.
This commit is contained in:
@@ -167,7 +167,7 @@ public class MakeBaneCmd extends AbstractDevCmd {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stone.addEffectBit((1 << 19));
|
stone.addEffectBit((1 << 19));
|
||||||
stone.setRank((byte) rank);
|
BuildingManager.setRank(stone, (byte) rank);
|
||||||
stone.setMaxHitPoints(blueprint.getMaxHealth(stone.getRank()));
|
stone.setMaxHitPoints(blueprint.getMaxHealth(stone.getRank()));
|
||||||
stone.setCurrentHitPoints(stone.getMaxHitPoints());
|
stone.setCurrentHitPoints(stone.getMaxHitPoints());
|
||||||
BuildingManager.setUpgradeDateTime(stone, null, 0);
|
BuildingManager.setUpgradeDateTime(stone, null, 0);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class SetRankCmd extends AbstractDevCmd {
|
|||||||
Blueprint blueprint = targetBuilding.getBlueprint();
|
Blueprint blueprint = targetBuilding.getBlueprint();
|
||||||
|
|
||||||
if (blueprint == null) {
|
if (blueprint == null) {
|
||||||
targetBuilding.setRank(targetRank);
|
BuildingManager.setRank(targetBuilding, targetRank);
|
||||||
ChatManager.chatSayInfo(player, "Building ranked without blueprint" + targetBuilding.getObjectUUID());
|
ChatManager.chatSayInfo(player, "Building ranked without blueprint" + targetBuilding.getObjectUUID());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,9 +68,8 @@ public class SetRankCmd extends AbstractDevCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the current targetRank
|
// Set the current targetRank
|
||||||
int lastMeshID = targetBuilding.getMeshUUID();
|
|
||||||
targetBuilding.setRank(targetRank);
|
|
||||||
|
|
||||||
|
BuildingManager.setRank(targetBuilding, targetRank);
|
||||||
ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank);
|
ChatManager.chatSayInfo(player, "Rank set for building with ID " + targetBuilding.getObjectUUID() + " to rank " + targetRank);
|
||||||
break;
|
break;
|
||||||
case NPC:
|
case NPC:
|
||||||
@@ -114,7 +113,7 @@ public class SetRankCmd extends AbstractDevCmd {
|
|||||||
|
|
||||||
// Set the current targetRank
|
// Set the current targetRank
|
||||||
int lastMeshID = targetBuilding.getMeshUUID();
|
int lastMeshID = targetBuilding.getMeshUUID();
|
||||||
targetBuilding.setRank(targetRank);
|
BuildingManager.setRank(targetBuilding, targetRank);
|
||||||
|
|
||||||
if (lastMeshID != targetBuilding.getMeshUUID())
|
if (lastMeshID != targetBuilding.getMeshUUID())
|
||||||
targetBuilding.refresh(true);
|
targetBuilding.refresh(true);
|
||||||
|
|||||||
@@ -853,7 +853,7 @@ public enum BuildingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void rebuildMine(Building mineBuilding) {
|
public static void rebuildMine(Building mineBuilding) {
|
||||||
mineBuilding.setRank(1);
|
setRank(mineBuilding, 1);
|
||||||
mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank);
|
mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank);
|
||||||
|
|
||||||
// New rank mean new max hit points.
|
// New rank mean new max hit points.
|
||||||
@@ -862,4 +862,84 @@ public enum BuildingManager {
|
|||||||
mineBuilding.setCurrentHitPoints(mineBuilding.healthMax);
|
mineBuilding.setCurrentHitPoints(mineBuilding.healthMax);
|
||||||
mineBuilding.getBounds().setBounds(mineBuilding);
|
mineBuilding.getBounds().setBounds(mineBuilding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setRank(Building building, int rank) {
|
||||||
|
|
||||||
|
int newMeshUUID;
|
||||||
|
boolean success;
|
||||||
|
|
||||||
|
|
||||||
|
// If this building has no blueprint then set rank and exit immediatly.
|
||||||
|
|
||||||
|
if (building.blueprintUUID == 0 || building.getBlueprint() != null && building.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE)) {
|
||||||
|
building.rank = rank;
|
||||||
|
DbManager.BuildingQueries.CHANGE_RANK(building.getObjectUUID(), rank);
|
||||||
|
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 = building.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 (rank == -1)
|
||||||
|
success = DbManager.BuildingQueries.DELETE_FROM_DATABASE(building);
|
||||||
|
else
|
||||||
|
success = DbManager.BuildingQueries.updateBuildingRank(building, rank);
|
||||||
|
|
||||||
|
if (success == false) {
|
||||||
|
Logger.error("Error writing to database UUID: " + building.getObjectUUID());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
building.isDeranking.compareAndSet(false, true);
|
||||||
|
|
||||||
|
// Change the building's rank
|
||||||
|
|
||||||
|
building.rank = rank;
|
||||||
|
|
||||||
|
// New rank means new mesh
|
||||||
|
|
||||||
|
newMeshUUID = building.getBlueprint().getMeshForRank(building.rank);
|
||||||
|
building.meshUUID = newMeshUUID;
|
||||||
|
|
||||||
|
// New rank mean new max hitpoints.
|
||||||
|
|
||||||
|
building.healthMax = building.getBlueprint().getMaxHealth(building.rank);
|
||||||
|
building.setCurrentHitPoints(building.healthMax);
|
||||||
|
|
||||||
|
if (building.getUpgradeDateTime() != null)
|
||||||
|
setUpgradeDateTime(building, null, 0);
|
||||||
|
|
||||||
|
// If we destroyed this building make sure to turn off
|
||||||
|
// protection
|
||||||
|
|
||||||
|
if (building.rank == -1)
|
||||||
|
building.protectionState = Enum.ProtectionState.NONE;
|
||||||
|
|
||||||
|
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL)
|
||||||
|
&& (building.rank == 8))
|
||||||
|
building.meshUUID = Realm.getRealmMesh(building.getCity());
|
||||||
|
|
||||||
|
// update object to clients
|
||||||
|
|
||||||
|
building.refresh(true);
|
||||||
|
|
||||||
|
if (building.getBounds() != null)
|
||||||
|
building.getBounds().setBounds(building);
|
||||||
|
|
||||||
|
// Cleanup hirelings resulting from rank change
|
||||||
|
|
||||||
|
cleanupHirelings(building);
|
||||||
|
|
||||||
|
building.isDeranking.compareAndSet(true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package engine.jobs;
|
package engine.jobs;
|
||||||
|
|
||||||
|
import engine.gameManager.BuildingManager;
|
||||||
import engine.job.AbstractScheduleJob;
|
import engine.job.AbstractScheduleJob;
|
||||||
import engine.objects.Building;
|
import engine.objects.Building;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
@@ -39,7 +40,7 @@ public class UpgradeBuildingJob extends AbstractScheduleJob {
|
|||||||
// SetCurrentRank also changes the mesh and maxhp
|
// SetCurrentRank also changes the mesh and maxhp
|
||||||
// accordingly for buildings with blueprints
|
// accordingly for buildings with blueprints
|
||||||
|
|
||||||
rankingBuilding.setRank(rankingBuilding.getRank() + 1);
|
BuildingManager.setRank(rankingBuilding, rankingBuilding.getRank() + 1);
|
||||||
|
|
||||||
// Reload the object
|
// Reload the object
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class DestroyBuildingHandler extends AbstractClientMsgHandler {
|
|||||||
city.setWarehouseBuildingID(0);
|
city.setWarehouseBuildingID(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
building.setRank(-1);
|
BuildingManager.setRank(building, -1);
|
||||||
WorldGrid.RemoveWorldObject(building);
|
WorldGrid.RemoveWorldObject(building);
|
||||||
WorldGrid.removeObject(building);
|
WorldGrid.removeObject(building);
|
||||||
building.getParentZone().zoneBuildingSet.remove(building);
|
building.getParentZone().zoneBuildingSet.remove(building);
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
|
|||||||
|
|
||||||
realm.claimRealmForCity(city, charterUUID);
|
realm.claimRealmForCity(city, charterUUID);
|
||||||
|
|
||||||
tol.setRank(8);
|
BuildingManager.setRank(tol, 8);
|
||||||
WorldGrid.updateObject(tol);
|
WorldGrid.updateObject(tol);
|
||||||
|
|
||||||
for (Building building : city.getParent().zoneBuildingSet) {
|
for (Building building : city.getParent().zoneBuildingSet) {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
/* The Blueprint class has methods able to derive
|
/* The Blueprint class has methods able to derive
|
||||||
* all defining characteristics of this building,
|
* all defining characteristics of this building,
|
||||||
*/
|
*/
|
||||||
private int blueprintUUID = 0;
|
public int blueprintUUID = 0;
|
||||||
private float w = 1.0f;
|
private float w = 1.0f;
|
||||||
private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f);
|
private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||||
private int doorState = 0;
|
private int doorState = 0;
|
||||||
@@ -96,7 +96,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
private ConcurrentHashMap<String, Long> timestamps = null;
|
private ConcurrentHashMap<String, Long> timestamps = null;
|
||||||
private ConcurrentHashMap<Integer, BuildingFriends> friends = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<Integer, BuildingFriends> friends = new ConcurrentHashMap<>();
|
||||||
private ConcurrentHashMap<Integer, Condemned> condemned = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<Integer, Condemned> condemned = new ConcurrentHashMap<>();
|
||||||
private ProtectionState protectionState = ProtectionState.NONE;
|
public ProtectionState protectionState = ProtectionState.NONE;
|
||||||
private ArrayList<Building> children = null;
|
private ArrayList<Building> children = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -277,86 +277,6 @@ public class Building extends AbstractWorldObject {
|
|||||||
return rank;
|
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() {
|
public final int getOwnerUUID() {
|
||||||
return ownerUUID;
|
return ownerUUID;
|
||||||
}
|
}
|
||||||
@@ -528,7 +448,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
MineRecord mineRecord = MineRecord.borrow(mine, attacker, RecordEventType.DESTROY);
|
MineRecord mineRecord = MineRecord.borrow(mine, attacker, RecordEventType.DESTROY);
|
||||||
DataWarehouse.pushToWarehouse(mineRecord);
|
DataWarehouse.pushToWarehouse(mineRecord);
|
||||||
|
|
||||||
this.setRank(-1);
|
BuildingManager.setRank(this, -1);
|
||||||
this.setCurrentHitPoints((float) 1);
|
this.setCurrentHitPoints((float) 1);
|
||||||
this.healthMax = (float) 1;
|
this.healthMax = (float) 1;
|
||||||
this.meshUUID = this.getBlueprint().getMeshForRank(this.rank);
|
this.meshUUID = this.getBlueprint().getMeshForRank(this.rank);
|
||||||
@@ -551,9 +471,9 @@ public class Building extends AbstractWorldObject {
|
|||||||
// Time to either derank or destroy the building.
|
// Time to either derank or destroy the building.
|
||||||
|
|
||||||
if ((this.rank - 1) < 1)
|
if ((this.rank - 1) < 1)
|
||||||
this.setRank(-1);
|
BuildingManager.setRank(this, -1);
|
||||||
else
|
else
|
||||||
this.setRank(this.rank - 1);
|
BuildingManager.setRank(this, this.rank - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,7 +531,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
|
|
||||||
if (spireBuilding != null) {
|
if (spireBuilding != null) {
|
||||||
spireBuilding.disableSpire(true);
|
spireBuilding.disableSpire(true);
|
||||||
spireBuilding.setRank(-1);
|
BuildingManager.setRank(spireBuilding, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +542,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
// Delete a random shrine
|
// Delete a random shrine
|
||||||
|
|
||||||
if (shrineBuilding != null)
|
if (shrineBuilding != null)
|
||||||
shrineBuilding.setRank(-1);
|
BuildingManager.setRank(shrineBuilding, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barracksBuildings.size() > this.rank - 1) {
|
if (barracksBuildings.size() > this.rank - 1) {
|
||||||
@@ -632,7 +552,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
// Delete a random barrack
|
// Delete a random barrack
|
||||||
|
|
||||||
if (barracksBuilding != null)
|
if (barracksBuilding != null)
|
||||||
barracksBuilding.setRank(-1);
|
BuildingManager.setRank(barracksBuilding, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the tree is R8 and deranking, we need to update it's
|
// 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
|
// Let's do so and early exit
|
||||||
|
|
||||||
if (this.rank > 1) {
|
if (this.rank > 1) {
|
||||||
this.setRank(rank - 1);
|
BuildingManager.setRank(this, rank - 1);
|
||||||
City.lastCityUpdate = System.currentTimeMillis();
|
City.lastCityUpdate = System.currentTimeMillis();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package engine.workthreads;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import engine.Enum;
|
import engine.Enum;
|
||||||
|
import engine.gameManager.BuildingManager;
|
||||||
import engine.gameManager.DbManager;
|
import engine.gameManager.DbManager;
|
||||||
import engine.gameManager.GuildManager;
|
import engine.gameManager.GuildManager;
|
||||||
import engine.gameManager.ZoneManager;
|
import engine.gameManager.ZoneManager;
|
||||||
@@ -127,7 +128,7 @@ public class DestroyCityThread implements Runnable {
|
|||||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) {
|
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) {
|
||||||
|
|
||||||
if (cityBuilding.getRank() != -1)
|
if (cityBuilding.getRank() != -1)
|
||||||
cityBuilding.setRank(-1);
|
BuildingManager.setRank(cityBuilding, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class HourlyJobThread implements Runnable {
|
|||||||
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
|
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
|
||||||
DataWarehouse.pushToWarehouse(mineRecord);
|
DataWarehouse.pushToWarehouse(mineRecord);
|
||||||
|
|
||||||
mineBuilding.setRank(mineBuilding.getRank());
|
BuildingManager.setRank(mineBuilding, mineBuilding.getRank());
|
||||||
mine.lastClaimer = null;
|
mine.lastClaimer = null;
|
||||||
mine.setActive(false);
|
mine.setActive(false);
|
||||||
mine.wasClaimed = true;
|
mine.wasClaimed = true;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class TransferCityThread implements Runnable {
|
|||||||
|
|
||||||
//Reset TOL to rank 1
|
//Reset TOL to rank 1
|
||||||
|
|
||||||
city.getTOL().setRank(1);
|
BuildingManager.setRank(city.getTOL(), 1);
|
||||||
|
|
||||||
// Transfer all assets to new owner
|
// Transfer all assets to new owner
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user