From 7c079c39982b145d682e4e266d3d79c8cbfa1efe Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 24 Apr 2023 15:37:30 -0400 Subject: [PATCH] Begin refactor location collections. --- .../handlers/dbBuildingLocationHandler.java | 9 +++++ src/engine/gameManager/BuildingManager.java | 5 +++ src/engine/objects/BuildingLocation.java | 33 +++++++++++++++++++ src/engine/server/world/WorldServer.java | 1 + 4 files changed, 48 insertions(+) diff --git a/src/engine/db/handlers/dbBuildingLocationHandler.java b/src/engine/db/handlers/dbBuildingLocationHandler.java index c9dadd64..2c642e83 100644 --- a/src/engine/db/handlers/dbBuildingLocationHandler.java +++ b/src/engine/db/handlers/dbBuildingLocationHandler.java @@ -20,8 +20,17 @@ public class dbBuildingLocationHandler extends dbHandlerBase { this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); } + public ArrayList LOAD_BUILDING_LOCATIONS() { + prepareCallable("select * from static_building_location " + + "where type = 6 or type = 8 " + + "GROUP BY buildingID, slot " + + "ORDER BY buildingID, slot ASC;"); + return getObjectList(); + } + public ArrayList LOAD_ALL_BUILDING_LOCATIONS() { prepareCallable("SELECT * FROM `static_building_location`;"); return getObjectList(); } + } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 8d316e2a..4712e742 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -25,12 +25,17 @@ import org.pmw.tinylog.Logger; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.ArrayList; +import java.util.HashMap; import java.util.concurrent.ThreadLocalRandom; public enum BuildingManager { BUILDINGMANAGER; + public static HashMap> _stuckLocations; + public static HashMap> _slotLocations; + public static boolean playerCanManage(PlayerCharacter player, Building building) { if (player == null) diff --git a/src/engine/objects/BuildingLocation.java b/src/engine/objects/BuildingLocation.java index e703a65b..10570578 100644 --- a/src/engine/objects/BuildingLocation.java +++ b/src/engine/objects/BuildingLocation.java @@ -9,12 +9,16 @@ package engine.objects; +import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; import engine.math.Vector3fImmutable; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -122,6 +126,35 @@ public class BuildingLocation extends AbstractGameObject { public void updateDatabase() { } + public static void loadBuildingLocations() { + + ArrayList buildingLocations = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS(); + HashMap> locationCollection = new HashMap<>(); + + // Only slot locations and stuck locations are currently loaded. + + for (BuildingLocation buildingLocation : buildingLocations) { + + switch (buildingLocation.type) { + case 6: + locationCollection = BuildingManager._slotLocations; + break; + case 8: + locationCollection = BuildingManager._stuckLocations; + break; + } + + // Add location to the collection in BuildingManager + + if (locationCollection.containsKey(buildingLocation.buildingUUID)) + locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); + else { + locationCollection.put(buildingLocation.buildingUUID, new ArrayList<>()); + locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); + } + + } + } public static void loadAllLocations() { ArrayList bls = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS(); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 22570711..5e1d7fa8 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -338,6 +338,7 @@ public class WorldServer { Logger.info("Loading building mountpoint data."); BuildingLocation.loadAllLocations(); + BuildingLocation.loadBuildingLocations(); // Starting before loading of structures/guilds/characters // so the database connections are available to write