Browse Source

Method made static and moved to manager.

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
838776c471
  1. 2
      src/engine/devcmd/cmds/MakeBaneCmd.java
  2. 7
      src/engine/devcmd/cmds/SetRankCmd.java
  3. 82
      src/engine/gameManager/BuildingManager.java
  4. 3
      src/engine/jobs/UpgradeBuildingJob.java
  5. 2
      src/engine/net/client/handlers/DestroyBuildingHandler.java
  6. 2
      src/engine/net/client/handlers/ObjectActionMsgHandler.java
  7. 98
      src/engine/objects/Building.java
  8. 3
      src/engine/workthreads/DestroyCityThread.java
  9. 2
      src/engine/workthreads/HourlyJobThread.java
  10. 2
      src/engine/workthreads/TransferCityThread.java

2
src/engine/devcmd/cmds/MakeBaneCmd.java

@ -167,7 +167,7 @@ public class MakeBaneCmd extends AbstractDevCmd { @@ -167,7 +167,7 @@ public class MakeBaneCmd extends AbstractDevCmd {
return;
}
stone.addEffectBit((1 << 19));
stone.setRank((byte) rank);
BuildingManager.setRank(stone, (byte) rank);
stone.setMaxHitPoints(blueprint.getMaxHealth(stone.getRank()));
stone.setCurrentHitPoints(stone.getMaxHitPoints());
BuildingManager.setUpgradeDateTime(stone, null, 0);

7
src/engine/devcmd/cmds/SetRankCmd.java

@ -57,7 +57,7 @@ public class SetRankCmd extends AbstractDevCmd { @@ -57,7 +57,7 @@ public class SetRankCmd extends AbstractDevCmd {
Blueprint blueprint = targetBuilding.getBlueprint();
if (blueprint == null) {
targetBuilding.setRank(targetRank);
BuildingManager.setRank(targetBuilding, targetRank);
ChatManager.chatSayInfo(player, "Building ranked without blueprint" + targetBuilding.getObjectUUID());
return;
}
@ -68,9 +68,8 @@ public class SetRankCmd extends AbstractDevCmd { @@ -68,9 +68,8 @@ public class SetRankCmd extends AbstractDevCmd {
}
// 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);
break;
case NPC:
@ -114,7 +113,7 @@ public class SetRankCmd extends AbstractDevCmd { @@ -114,7 +113,7 @@ public class SetRankCmd extends AbstractDevCmd {
// Set the current targetRank
int lastMeshID = targetBuilding.getMeshUUID();
targetBuilding.setRank(targetRank);
BuildingManager.setRank(targetBuilding, targetRank);
if (lastMeshID != targetBuilding.getMeshUUID())
targetBuilding.refresh(true);

82
src/engine/gameManager/BuildingManager.java

@ -853,7 +853,7 @@ public enum BuildingManager { @@ -853,7 +853,7 @@ public enum BuildingManager {
}
public static void rebuildMine(Building mineBuilding) {
mineBuilding.setRank(1);
setRank(mineBuilding, 1);
mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank);
// New rank mean new max hit points.
@ -862,4 +862,84 @@ public enum BuildingManager { @@ -862,4 +862,84 @@ public enum BuildingManager {
mineBuilding.setCurrentHitPoints(mineBuilding.healthMax);
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);
}
}

3
src/engine/jobs/UpgradeBuildingJob.java

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
package engine.jobs;
import engine.gameManager.BuildingManager;
import engine.job.AbstractScheduleJob;
import engine.objects.Building;
import org.pmw.tinylog.Logger;
@ -39,7 +40,7 @@ public class UpgradeBuildingJob extends AbstractScheduleJob { @@ -39,7 +40,7 @@ public class UpgradeBuildingJob extends AbstractScheduleJob {
// SetCurrentRank also changes the mesh and maxhp
// accordingly for buildings with blueprints
rankingBuilding.setRank(rankingBuilding.getRank() + 1);
BuildingManager.setRank(rankingBuilding, rankingBuilding.getRank() + 1);
// Reload the object

2
src/engine/net/client/handlers/DestroyBuildingHandler.java

@ -95,7 +95,7 @@ public class DestroyBuildingHandler extends AbstractClientMsgHandler { @@ -95,7 +95,7 @@ public class DestroyBuildingHandler extends AbstractClientMsgHandler {
city.setWarehouseBuildingID(0);
}
building.setRank(-1);
BuildingManager.setRank(building, -1);
WorldGrid.RemoveWorldObject(building);
WorldGrid.removeObject(building);
building.getParentZone().zoneBuildingSet.remove(building);

2
src/engine/net/client/handlers/ObjectActionMsgHandler.java

@ -182,7 +182,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler { @@ -182,7 +182,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
realm.claimRealmForCity(city, charterUUID);
tol.setRank(8);
BuildingManager.setRank(tol, 8);
WorldGrid.updateObject(tol);
for (Building building : city.getParent().zoneBuildingSet) {

98
src/engine/objects/Building.java

@ -80,7 +80,7 @@ public class Building extends AbstractWorldObject { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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;
}

3
src/engine/workthreads/DestroyCityThread.java

@ -19,6 +19,7 @@ package engine.workthreads; @@ -19,6 +19,7 @@ package engine.workthreads;
*/
import engine.Enum;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.gameManager.GuildManager;
import engine.gameManager.ZoneManager;
@ -127,7 +128,7 @@ public class DestroyCityThread implements Runnable { @@ -127,7 +128,7 @@ public class DestroyCityThread implements Runnable {
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) {
if (cityBuilding.getRank() != -1)
cityBuilding.setRank(-1);
BuildingManager.setRank(cityBuilding, -1);
}
}

2
src/engine/workthreads/HourlyJobThread.java

@ -176,7 +176,7 @@ public class HourlyJobThread implements Runnable { @@ -176,7 +176,7 @@ public class HourlyJobThread implements Runnable {
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord);
mineBuilding.setRank(mineBuilding.getRank());
BuildingManager.setRank(mineBuilding, mineBuilding.getRank());
mine.lastClaimer = null;
mine.setActive(false);
mine.wasClaimed = true;

2
src/engine/workthreads/TransferCityThread.java

@ -74,7 +74,7 @@ public class TransferCityThread implements Runnable { @@ -74,7 +74,7 @@ public class TransferCityThread implements Runnable {
//Reset TOL to rank 1
city.getTOL().setRank(1);
BuildingManager.setRank(city.getTOL(), 1);
// Transfer all assets to new owner

Loading…
Cancel
Save