Browse Source

Cleanup in runafterload

combat-2
MagicBot 1 year ago
parent
commit
3ef444c128
  1. 168
      src/engine/objects/Building.java

168
src/engine/objects/Building.java

@ -75,11 +75,14 @@ public class Building extends AbstractWorldObject { @@ -75,11 +75,14 @@ public class Building extends AbstractWorldObject {
public int level;
public AtomicBoolean isDeranking = new AtomicBoolean(false);
public LocalDateTime maintDateTime;
protected Resists resists;
/* The Blueprint class has methods able to derive
* all defining characteristics of this building,
*/
public int blueprintUUID = 0;
public int rank;
public ArrayList<Vector3fImmutable> patrolPoints;
public ProtectionState protectionState = ProtectionState.NONE;
protected Resists resists;
private float w = 1.0f;
private Vector3f meshScale = new Vector3f(1.0f, 1.0f, 1.0f);
private int doorState = 0;
@ -88,15 +91,12 @@ public class Building extends AbstractWorldObject { @@ -88,15 +91,12 @@ public class Building extends AbstractWorldObject {
private int maxGold;
private int effectFlags = 0;
private String name = "";
public int rank;
private boolean ownerIsNPC = true;
private boolean spireIsActive = false;
private ConcurrentHashMap<String, JobContainer> timers = null;
private ConcurrentHashMap<String, Long> timestamps = null;
private ConcurrentHashMap<Integer, BuildingFriends> friends;
private ConcurrentHashMap<Integer, Condemned> condemned;
public ArrayList<Vector3fImmutable> patrolPoints;
public ProtectionState protectionState = ProtectionState.NONE;
private ArrayList<Building> children = null;
/**
@ -164,7 +164,7 @@ public class Building extends AbstractWorldObject { @@ -164,7 +164,7 @@ 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());
Logger.error("Failed for object " + this.blueprintUUID + ' ' + this.getObjectUUID() + e);
}
}
@ -385,14 +385,14 @@ public class Building extends AbstractWorldObject { @@ -385,14 +385,14 @@ public class Building extends AbstractWorldObject {
Mine.SendMineAttackMessage(this);
City playerCity = ZoneManager.getCityAtLocation(this.loc);
if(playerCity != null){
if(this.getGuild().getNation().equals(playerCity.getTOL().getGuild().getNation())){
if (playerCity != null) {
if (this.getGuild().getNation().equals(playerCity.getTOL().getGuild().getNation())) {
//friendly building has been attacked, add attacker to city outlaw list
if(!playerCity.cityOutlaws.contains(attacker.getObjectUUID()) && attacker.getObjectType().equals(GameObjectType.PlayerCharacter))
if (!playerCity.cityOutlaws.contains(attacker.getObjectUUID()) && attacker.getObjectType().equals(GameObjectType.PlayerCharacter))
playerCity.cityOutlaws.add(attacker.getObjectUUID());
for(Mob guard : playerCity.getParent().zoneMobSet)
if(guard.combatTarget == null)
guard.setCombatTarget(attacker);
for (Mob guard : playerCity.getParent().zoneMobSet)
if (guard.combatTarget == null)
guard.setCombatTarget(attacker);
}
}
@ -888,72 +888,71 @@ public class Building extends AbstractWorldObject { @@ -888,72 +888,71 @@ public class Building extends AbstractWorldObject {
@Override
public void runAfterLoad() {
// Set Parent Zone
// Set Parent Zone
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
this.parentZone.zoneBuildingSet.add(this);
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
this.parentZone.zoneBuildingSet.add(this);
// Lookup building blueprint
// 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
Blueprint blueprint;
if ((this.blueprintUUID != 0) && (blueprint == null))
Logger.error("Invalid blueprint for object: " + this.getObjectUUID());
if (this.blueprintUUID == 0)
blueprint = Blueprint._meshLookup.get(meshUUID);
else
blueprint = this.getBlueprint();
// 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.
// Log error if something went horrible wrong
if (blueprint != null) {
if ((this.blueprintUUID != 0) && (blueprint == null))
Logger.error("Invalid blueprint for object: " + this.getObjectUUID());
// Only switch mesh for player dropped structures
// 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 (this.blueprintUUID != 0)
this.meshUUID = blueprint.getMeshForRank(rank);
if (blueprint != null) {
this.healthMax = blueprint.getMaxHealth(this.rank);
// Only switch mesh for player dropped structures
// 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.meshUUID = blueprint.getMeshForRank(rank);
if (this.blueprintUUID == 0)
this.setHealth(healthMax);
this.healthMax = blueprint.getMaxHealth(this.rank);
this.patrolPoints = BuildingManager._buildingPatrolPoints.computeIfAbsent(this.getObjectUUID(), k -> new ArrayList<>());
// If this object has no blueprint but is a blueprint
// mesh then set it's current health to max health
} else {
this.healthMax = 100000; // Structures with no blueprint mesh
if (this.blueprintUUID == 0)
this.setHealth(healthMax);
}
resists = new Resists("Building");
this.patrolPoints = BuildingManager._buildingPatrolPoints.computeIfAbsent(this.getObjectUUID(), k -> new ArrayList<>());
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 {
this.healthMax = 100000; // Structures with no blueprint mesh
this.setHealth(healthMax);
}
}
} else {
resists = new Resists("Building");
// Altitude of this building is derived from the heightmap engine.
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));
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);
}
}
} 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);
}
}
// Submit upgrade job if building is currently set to rank.
@ -970,48 +969,36 @@ public class Building extends AbstractWorldObject { @@ -970,48 +969,36 @@ public class Building extends AbstractWorldObject {
this.friends = BuildingManager._buildingFriends.computeIfAbsent(this.getObjectUUID(), k -> new ConcurrentHashMap<>());
this.condemned = BuildingManager._buildingCondemned.computeIfAbsent(this.getObjectUUID(), k -> new ConcurrentHashMap<>());
//LOad Owners in Cache so we do not have to continuely look in the db for owner.
if (this.ownerIsNPC) {
if (NPC.getNPC(this.ownerUUID) == null)
Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString());
} else if (this.ownerUUID != 0) {
if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) {
Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString());
}
}
// Set bounds for this building
// Set bounds for this building
Bounds buildingBounds = Bounds.borrow();
buildingBounds.setBounds(this);
this.setBounds(buildingBounds);
Bounds buildingBounds = Bounds.borrow();
buildingBounds.setBounds(this);
this.setBounds(buildingBounds);
//create a new list for children if the building is not a child. children list default is null.
//TODO Remove Furniture/Child buildings from building class and move them into a seperate class.
//create a new list for children if the building is not a child. children list default is null.
//TODO Remove Furniture/Child buildings from building class and move them into a seperate class.
if (this.parentBuildingID == 0)
this.children = new ArrayList<>();
if (this.parentBuildingID == 0)
this.children = new ArrayList<>();
if (this.parentBuildingID != 0) {
Building parent = BuildingManager.getBuildingFromCache(this.parentBuildingID);
if (this.parentBuildingID != 0) {
Building parent = BuildingManager.getBuilding(this.parentBuildingID);
if (parent != null) {
parent.children.add(this);
if (parent != null) {
parent.children.add(this);
//add furniture to region cache. floor and level are reversed in database, //TODO Fix
//add furniture to region cache. floor and level are reversed in database, //TODO Fix
Regions region = BuildingManager.GetRegion(parent, this.level, this.floor, this.getLoc().x, this.getLoc().z);
if (region != null)
Regions.FurnitureRegionMap.put(this.getObjectUUID(), region);
}
Regions region = BuildingManager.GetRegion(parent, this.level, this.floor, this.getLoc().x, this.getLoc().z);
if (region != null)
Regions.FurnitureRegionMap.put(this.getObjectUUID(), region);
}
if (this.upgradeDateTime != null)
BuildingManager.submitUpgradeJob(this);
}
if (this.upgradeDateTime != null)
BuildingManager.submitUpgradeJob(this);
}
public synchronized boolean setOwner(AbstractCharacter newOwner) {
@ -1400,10 +1387,7 @@ public class Building extends AbstractWorldObject { @@ -1400,10 +1387,7 @@ public class Building extends AbstractWorldObject {
public boolean assetIsProtected() {
boolean outValue = false;
if (protectionState.equals(ProtectionState.PROTECTED))
outValue = true;
boolean outValue = protectionState.equals(ProtectionState.PROTECTED);
if (protectionState.equals(ProtectionState.CONTRACT))
outValue = true;

Loading…
Cancel
Save