From bcb40fecbb19330693214af37f5c50f2926745f7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 23 Apr 2024 14:56:30 -0400 Subject: [PATCH] Loading effect costmap data at bootsrap --- .../dbEffectsResourceCostHandler.java | 27 +++++++++++++++++++ src/engine/gameManager/PowersManager.java | 1 + src/engine/server/world/WorldServer.java | 3 +++ 3 files changed, 31 insertions(+) diff --git a/src/engine/db/handlers/dbEffectsResourceCostHandler.java b/src/engine/db/handlers/dbEffectsResourceCostHandler.java index dee88cf4..4ae2013a 100644 --- a/src/engine/db/handlers/dbEffectsResourceCostHandler.java +++ b/src/engine/db/handlers/dbEffectsResourceCostHandler.java @@ -10,6 +10,7 @@ package engine.db.handlers; import engine.gameManager.DbManager; +import engine.gameManager.PowersManager; import engine.mbEnums; import engine.objects.EffectsResourceCosts; import org.json.JSONObject; @@ -96,6 +97,32 @@ public class dbEffectsResourceCostHandler extends dbHandlerBase { return false; } + public void LOAD_ALL_COSTMAPS() { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_effect_costmaps`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + String effectID = rs.getString("effectID"); + String costString = rs.getString("costmap"); + JSONObject costJSON = new JSONObject(costString); + HashMap costmap = new HashMap<>(); + + for (String key : costJSON.keySet()) { + int value = costJSON.getInt(key); + costmap.put(mbEnums.ResourceType.valueOf(key), value); + } + + PowersManager._effect_costMaps.put(effectID, costmap); + } + + } catch (SQLException e) { + Logger.error(e); + } + } + public ArrayList GET_ALL_EFFECT_RESOURCES(String idString) { ArrayList effectsResourceCosts = new ArrayList<>(); diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 4578f79f..77c19da1 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -57,6 +57,7 @@ public enum PowersManager { public static HashMap AnimationOverrides = new HashMap<>(); public static HashMap> _allRunePowers; public static HashMap> _allRuneSkillAdjusts; + public static HashMap> _effect_costMaps = new HashMap<>(); private static JobScheduler js; public static void initPowersManager(boolean fullPowersLoad) { diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 821c9463..48de8981 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -449,6 +449,9 @@ public class WorldServer { Logger.info("Starting Mob Respawn Thread"); Respawner.start(); + Logger.info("Loading effect cost maps"); + DbManager.EffectsResourceCostsQueries.LOAD_ALL_COSTMAPS(); + Logger.info("Starting ForgeManager thread"); ForgeManager.start();