From a30c041a174f9fd856dd70221367dcc6341d46f5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 17 Mar 2024 13:52:41 -0400 Subject: [PATCH] Logic update --- .../gameManager/MaintenanceManager.java | 76 +++++++++++++++---- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index fd5475fe..69dd7293 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -12,11 +12,15 @@ package engine.gameManager; // building maintenance system. 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 java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashMap; public enum MaintenanceManager { @@ -31,16 +35,23 @@ public enum MaintenanceManager { public static void processBuildingMaintenance() { - ArrayList buildingList; + ArrayList buildingList; ArrayList maintList; - ArrayList derankList = new ArrayList<>(); + ArrayList tolList; + ArrayList structureDerank = new ArrayList<>(); + ArrayList tolDerank = new ArrayList<>(); Logger.info("Starting Maintenance on Player Buildings"); // Build list of buildings to apply maintenance on. buildingList = new ArrayList(DbManager.getList(Enum.GameObjectType.Building)); - maintList = buildMaintList(buildingList); + HashMap> maintMap = new HashMap<>(); + + maintMap = buildMaintList(buildingList); + + maintList = maintMap.get("maint"); + tolList = maintMap.get("tol"); // Deduct upkeep and build list of buildings // which did not have funds available @@ -48,10 +59,11 @@ public enum MaintenanceManager { try { for (Building building : maintList) if (chargeUpkeep(building) == false) - derankList.add(building); + structureDerank.add(building); } catch (Exception e) { Logger.error(e); } + // Reset maintenance dates for these buildings for (Building building : maintList) @@ -61,25 +73,50 @@ public enum MaintenanceManager { // have funds available. 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); } catch (Exception 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 // returning a list of building for which maintenance is due. - private static ArrayList buildMaintList(ArrayList buildingList) { + private static HashMap> buildMaintList(ArrayList buildingList) { + HashMap> outMap = new HashMap<>(); ArrayList maintList = new ArrayList<>(); + ArrayList tolList = new ArrayList<>(); - for (AbstractGameObject gameObject : buildingList) { - - Building building = (Building) gameObject; + for (Building building : buildingList) { // No maintenance on NPC owned buildings (Cache loaded) @@ -126,16 +163,23 @@ public enum MaintenanceManager { continue; - //no maintenance if day of week doesnt match - if (LocalDateTime.now().getDayOfWeek().ordinal() != building.maintDateTime.getDayOfWeek().ordinal()) { + //no maintenance if day of week doesn't match + + if (LocalDateTime.now().getDayOfWeek() != building.maintDateTime.getDayOfWeek()) continue; - } + // 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