forked from MagicBane/Server
Cleanup in runafterload
This commit is contained in:
@@ -75,11 +75,14 @@ public class Building extends AbstractWorldObject {
|
|||||||
public int level;
|
public int level;
|
||||||
public AtomicBoolean isDeranking = new AtomicBoolean(false);
|
public AtomicBoolean isDeranking = new AtomicBoolean(false);
|
||||||
public LocalDateTime maintDateTime;
|
public LocalDateTime maintDateTime;
|
||||||
protected Resists resists;
|
|
||||||
/* 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,
|
||||||
*/
|
*/
|
||||||
public int blueprintUUID = 0;
|
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 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;
|
||||||
@@ -88,15 +91,12 @@ public class Building extends AbstractWorldObject {
|
|||||||
private int maxGold;
|
private int maxGold;
|
||||||
private int effectFlags = 0;
|
private int effectFlags = 0;
|
||||||
private String name = "";
|
private String name = "";
|
||||||
public int rank;
|
|
||||||
private boolean ownerIsNPC = true;
|
private boolean ownerIsNPC = true;
|
||||||
private boolean spireIsActive = false;
|
private boolean spireIsActive = false;
|
||||||
private ConcurrentHashMap<String, JobContainer> timers = null;
|
private ConcurrentHashMap<String, JobContainer> timers = null;
|
||||||
private ConcurrentHashMap<String, Long> timestamps = null;
|
private ConcurrentHashMap<String, Long> timestamps = null;
|
||||||
private ConcurrentHashMap<Integer, BuildingFriends> friends;
|
private ConcurrentHashMap<Integer, BuildingFriends> friends;
|
||||||
private ConcurrentHashMap<Integer, Condemned> condemned;
|
private ConcurrentHashMap<Integer, Condemned> condemned;
|
||||||
public ArrayList<Vector3fImmutable> patrolPoints;
|
|
||||||
public ProtectionState protectionState = ProtectionState.NONE;
|
|
||||||
private ArrayList<Building> children = null;
|
private ArrayList<Building> children = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +164,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
this.upgradeDateTime = LocalDateTime.ofInstant(upgradeTimeStamp.toInstant(), ZoneId.systemDefault());
|
this.upgradeDateTime = LocalDateTime.ofInstant(upgradeTimeStamp.toInstant(), ZoneId.systemDefault());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} 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 {
|
|||||||
Mine.SendMineAttackMessage(this);
|
Mine.SendMineAttackMessage(this);
|
||||||
|
|
||||||
City playerCity = ZoneManager.getCityAtLocation(this.loc);
|
City playerCity = ZoneManager.getCityAtLocation(this.loc);
|
||||||
if(playerCity != null){
|
if (playerCity != null) {
|
||||||
if(this.getGuild().getNation().equals(playerCity.getTOL().getGuild().getNation())){
|
if (this.getGuild().getNation().equals(playerCity.getTOL().getGuild().getNation())) {
|
||||||
//friendly building has been attacked, add attacker to city outlaw list
|
//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());
|
playerCity.cityOutlaws.add(attacker.getObjectUUID());
|
||||||
for(Mob guard : playerCity.getParent().zoneMobSet)
|
for (Mob guard : playerCity.getParent().zoneMobSet)
|
||||||
if(guard.combatTarget == null)
|
if (guard.combatTarget == null)
|
||||||
guard.setCombatTarget(attacker);
|
guard.setCombatTarget(attacker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,72 +888,71 @@ public class Building extends AbstractWorldObject {
|
|||||||
@Override
|
@Override
|
||||||
public void runAfterLoad() {
|
public void runAfterLoad() {
|
||||||
|
|
||||||
// Set Parent Zone
|
// Set Parent Zone
|
||||||
|
|
||||||
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
|
this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneUUID);
|
||||||
this.parentZone.zoneBuildingSet.add(this);
|
this.parentZone.zoneBuildingSet.add(this);
|
||||||
|
|
||||||
// Lookup building blueprint
|
// Lookup building blueprint
|
||||||
|
|
||||||
Blueprint 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)
|
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);
|
|
||||||
|
|
||||||
this.patrolPoints = BuildingManager._buildingPatrolPoints.computeIfAbsent(this.getObjectUUID(), k -> new ArrayList<>());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.healthMax = 100000; // Structures with no blueprint mesh
|
|
||||||
this.setHealth(healthMax);
|
this.setHealth(healthMax);
|
||||||
}
|
|
||||||
|
|
||||||
resists = new Resists("Building");
|
this.patrolPoints = BuildingManager._buildingPatrolPoints.computeIfAbsent(this.getObjectUUID(), k -> new ArrayList<>());
|
||||||
|
|
||||||
if (this.parentZone != null) {
|
} else {
|
||||||
if (this.parentBuildingID != 0) {
|
this.healthMax = 100000; // Structures with no blueprint mesh
|
||||||
Building parentBuilding = BuildingManager.getBuilding(this.parentBuildingID);
|
this.setHealth(healthMax);
|
||||||
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));
|
|
||||||
|
|
||||||
}
|
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 {
|
} else {
|
||||||
|
this.setLoc(new Vector3fImmutable(this.statLat + this.parentZone.absX, this.statAlt + this.parentZone.absY, this.statLon + this.parentZone.absZ));
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
} 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.
|
// Submit upgrade job if building is currently set to rank.
|
||||||
|
|
||||||
@@ -970,48 +969,36 @@ public class Building extends AbstractWorldObject {
|
|||||||
this.friends = BuildingManager._buildingFriends.computeIfAbsent(this.getObjectUUID(), k -> new ConcurrentHashMap<>());
|
this.friends = BuildingManager._buildingFriends.computeIfAbsent(this.getObjectUUID(), k -> new ConcurrentHashMap<>());
|
||||||
this.condemned = BuildingManager._buildingCondemned.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.
|
// Set bounds for this building
|
||||||
|
|
||||||
if (this.ownerIsNPC) {
|
Bounds buildingBounds = Bounds.borrow();
|
||||||
if (NPC.getNPC(this.ownerUUID) == null)
|
buildingBounds.setBounds(this);
|
||||||
Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString());
|
this.setBounds(buildingBounds);
|
||||||
|
|
||||||
} else if (this.ownerUUID != 0) {
|
//create a new list for children if the building is not a child. children list default is null.
|
||||||
if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) {
|
//TODO Remove Furniture/Child buildings from building class and move them into a seperate class.
|
||||||
Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString());
|
|
||||||
}
|
if (this.parentBuildingID == 0)
|
||||||
|
this.children = new ArrayList<>();
|
||||||
|
|
||||||
|
if (this.parentBuildingID != 0) {
|
||||||
|
Building parent = BuildingManager.getBuilding(this.parentBuildingID);
|
||||||
|
|
||||||
|
if (parent != null) {
|
||||||
|
parent.children.add(this);
|
||||||
|
|
||||||
|
//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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set bounds for this building
|
}
|
||||||
|
|
||||||
Bounds buildingBounds = Bounds.borrow();
|
if (this.upgradeDateTime != null)
|
||||||
buildingBounds.setBounds(this);
|
BuildingManager.submitUpgradeJob(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.
|
|
||||||
|
|
||||||
if (this.parentBuildingID == 0)
|
|
||||||
this.children = new ArrayList<>();
|
|
||||||
|
|
||||||
if (this.parentBuildingID != 0) {
|
|
||||||
Building parent = BuildingManager.getBuildingFromCache(this.parentBuildingID);
|
|
||||||
|
|
||||||
if (parent != null) {
|
|
||||||
parent.children.add(this);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.upgradeDateTime != null)
|
|
||||||
BuildingManager.submitUpgradeJob(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean setOwner(AbstractCharacter newOwner) {
|
public synchronized boolean setOwner(AbstractCharacter newOwner) {
|
||||||
@@ -1400,10 +1387,7 @@ public class Building extends AbstractWorldObject {
|
|||||||
|
|
||||||
public boolean assetIsProtected() {
|
public boolean assetIsProtected() {
|
||||||
|
|
||||||
boolean outValue = false;
|
boolean outValue = protectionState.equals(ProtectionState.PROTECTED);
|
||||||
|
|
||||||
if (protectionState.equals(ProtectionState.PROTECTED))
|
|
||||||
outValue = true;
|
|
||||||
|
|
||||||
if (protectionState.equals(ProtectionState.CONTRACT))
|
if (protectionState.equals(ProtectionState.CONTRACT))
|
||||||
outValue = true;
|
outValue = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user