|
|
@ -12,11 +12,15 @@ package engine.gameManager; |
|
|
|
// building maintenance system.
|
|
|
|
// building maintenance system.
|
|
|
|
|
|
|
|
|
|
|
|
import engine.Enum; |
|
|
|
import engine.Enum; |
|
|
|
import engine.objects.*; |
|
|
|
import engine.objects.Building; |
|
|
|
|
|
|
|
import engine.objects.City; |
|
|
|
|
|
|
|
import engine.objects.ItemBase; |
|
|
|
|
|
|
|
import engine.objects.Warehouse; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
|
public enum MaintenanceManager { |
|
|
|
public enum MaintenanceManager { |
|
|
|
|
|
|
|
|
|
|
@ -31,16 +35,23 @@ public enum MaintenanceManager { |
|
|
|
|
|
|
|
|
|
|
|
public static void processBuildingMaintenance() { |
|
|
|
public static void processBuildingMaintenance() { |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<AbstractGameObject> buildingList; |
|
|
|
ArrayList<Building> buildingList; |
|
|
|
ArrayList<Building> maintList; |
|
|
|
ArrayList<Building> maintList; |
|
|
|
ArrayList<Building> derankList = new ArrayList<>(); |
|
|
|
ArrayList<Building> tolList; |
|
|
|
|
|
|
|
ArrayList<Building> structureDerank = new ArrayList<>(); |
|
|
|
|
|
|
|
ArrayList<Building> tolDerank = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
Logger.info("Starting Maintenance on Player Buildings"); |
|
|
|
Logger.info("Starting Maintenance on Player Buildings"); |
|
|
|
|
|
|
|
|
|
|
|
// Build list of buildings to apply maintenance on.
|
|
|
|
// Build list of buildings to apply maintenance on.
|
|
|
|
|
|
|
|
|
|
|
|
buildingList = new ArrayList(DbManager.getList(Enum.GameObjectType.Building)); |
|
|
|
buildingList = new ArrayList(DbManager.getList(Enum.GameObjectType.Building)); |
|
|
|
maintList = buildMaintList(buildingList); |
|
|
|
HashMap<String, ArrayList<Building>> maintMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maintMap = buildMaintList(buildingList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maintList = maintMap.get("maint"); |
|
|
|
|
|
|
|
tolList = maintMap.get("tol"); |
|
|
|
|
|
|
|
|
|
|
|
// Deduct upkeep and build list of buildings
|
|
|
|
// Deduct upkeep and build list of buildings
|
|
|
|
// which did not have funds available
|
|
|
|
// which did not have funds available
|
|
|
@ -48,10 +59,11 @@ public enum MaintenanceManager { |
|
|
|
try { |
|
|
|
try { |
|
|
|
for (Building building : maintList) |
|
|
|
for (Building building : maintList) |
|
|
|
if (chargeUpkeep(building) == false) |
|
|
|
if (chargeUpkeep(building) == false) |
|
|
|
derankList.add(building); |
|
|
|
structureDerank.add(building); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
Logger.error(e); |
|
|
|
Logger.error(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Reset maintenance dates for these buildings
|
|
|
|
// Reset maintenance dates for these buildings
|
|
|
|
|
|
|
|
|
|
|
|
for (Building building : maintList) |
|
|
|
for (Building building : maintList) |
|
|
@ -61,25 +73,50 @@ public enum MaintenanceManager { |
|
|
|
// have funds available.
|
|
|
|
// have funds available.
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
for (Building building : derankList) |
|
|
|
for (Building building : structureDerank) |
|
|
|
|
|
|
|
building.destroyOrDerank(null); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process TOL maintenance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (Building building : tolList) |
|
|
|
|
|
|
|
if (chargeUpkeep(building) == false) |
|
|
|
|
|
|
|
tolDerank.add(building); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reset maintenance dates for these buildings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Building building : tolList) |
|
|
|
|
|
|
|
setMaintDateTime(building, LocalDateTime.now().plusDays(7)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Derak or destroy buildings that did not
|
|
|
|
|
|
|
|
// have funds available.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (Building building : tolDerank) |
|
|
|
building.destroyOrDerank(null); |
|
|
|
building.destroyOrDerank(null); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
Logger.error(e); |
|
|
|
Logger.error(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Logger.info("Structures: " + buildingList.size() + " Maint: " + maintList.size() + " Derank: " + derankList.size()); |
|
|
|
Logger.info("Structures: " + structureDerank.size() + "/" + maintList.size() + " TOLS: " + tolDerank.size() + "/" + tolList.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Iterate over all buildings in game and apply exclusion rules
|
|
|
|
// Iterate over all buildings in game and apply exclusion rules
|
|
|
|
// returning a list of building for which maintenance is due.
|
|
|
|
// returning a list of building for which maintenance is due.
|
|
|
|
|
|
|
|
|
|
|
|
private static ArrayList<Building> buildMaintList(ArrayList<AbstractGameObject> buildingList) { |
|
|
|
private static HashMap<String, ArrayList<Building>> buildMaintList(ArrayList<Building> buildingList) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, ArrayList<Building>> outMap = new HashMap<>(); |
|
|
|
ArrayList<Building> maintList = new ArrayList<>(); |
|
|
|
ArrayList<Building> maintList = new ArrayList<>(); |
|
|
|
|
|
|
|
ArrayList<Building> tolList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (AbstractGameObject gameObject : buildingList) { |
|
|
|
for (Building building : buildingList) { |
|
|
|
|
|
|
|
|
|
|
|
Building building = (Building) gameObject; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// No maintenance on NPC owned buildings (Cache loaded)
|
|
|
|
// No maintenance on NPC owned buildings (Cache loaded)
|
|
|
|
|
|
|
|
|
|
|
@ -126,16 +163,23 @@ public enum MaintenanceManager { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//no maintenance if day of week doesnt match
|
|
|
|
//no maintenance if day of week doesn't match
|
|
|
|
if (LocalDateTime.now().getDayOfWeek().ordinal() != building.maintDateTime.getDayOfWeek().ordinal()) { |
|
|
|
|
|
|
|
|
|
|
|
if (LocalDateTime.now().getDayOfWeek() != building.maintDateTime.getDayOfWeek()) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Add building to maintenance queue
|
|
|
|
// Add building to maintenance queue
|
|
|
|
|
|
|
|
|
|
|
|
maintList.add(building); |
|
|
|
if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL)) |
|
|
|
|
|
|
|
tolList.add(building); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
maintList.add(building); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return maintList; |
|
|
|
outMap.put("maint", maintList); |
|
|
|
|
|
|
|
outMap.put("tol", tolList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Method removes the appropriate amount of gold/resources from
|
|
|
|
// Method removes the appropriate amount of gold/resources from
|
|
|
|