From f7fd544a00841289c9738958b0d552745d92a1df Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 7 Aug 2023 08:58:44 -0400 Subject: [PATCH] _modtypeTables populated at startup. --- src/engine/db/handlers/dbLootHandler.java | 39 +++++++++++++++++++++++ src/engine/gameManager/LootManager.java | 3 ++ src/engine/loot/ModTypeTableEntry.java | 24 ++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/engine/loot/ModTypeTableEntry.java diff --git a/src/engine/db/handlers/dbLootHandler.java b/src/engine/db/handlers/dbLootHandler.java index 75fe1454..36763a58 100644 --- a/src/engine/db/handlers/dbLootHandler.java +++ b/src/engine/db/handlers/dbLootHandler.java @@ -145,6 +145,45 @@ public class dbLootHandler extends dbHandlerBase { return modTables; } + public HashMap> LOAD_MOD_TYPE_TABLES() { + + HashMap> modTypeTables = new HashMap<>(); + ModTypeTableEntry modTypeTableEntry; + + int modTableID; + int recordsRead = 0; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_modtypeTables`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + recordsRead++; + + modTableID = rs.getInt("modType"); + modTypeTableEntry = new ModTypeTableEntry(rs); + + if (modTypeTables.get(modTableID) == null) { + ArrayList modTypeTableList = new ArrayList<>(); + modTypeTableList.add(modTypeTableEntry); + modTypeTables.put(modTableID, modTypeTableList); + } else { + ArrayList modTypeTableList = modTypeTables.get(modTableID); + modTypeTableList.add(modTypeTableEntry); + modTypeTables.put(modTableID, modTypeTableList); + } + } + } catch (SQLException e) { + Logger.error(e); + return modTypeTables; + } + + Logger.info("read: " + recordsRead + " cached: " + modTypeTables.size()); + return modTypeTables; + } + public HashMap> LOAD_BOOTY_TABLES() { HashMap> bootySets = new HashMap<>(); diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 479cc8cf..0c0acdb6 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -32,6 +32,7 @@ public enum LootManager { public static HashMap> _genTables = new HashMap<>(); public static HashMap> _itemTables = new HashMap<>(); public static HashMap> _modTables = new HashMap<>(); + public static HashMap> _modTypeTables = new HashMap<>(); //new tables public static final HashMap generalItemTables = null; @@ -57,6 +58,8 @@ public enum LootManager { _genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES(); _itemTables = DbManager.LootQueries.LOAD_ITEM_TABLES(); _modTables = DbManager.LootQueries.LOAD_MOD_TABLES(); + _modTypeTables = DbManager.LootQueries.LOAD_MOD_TYPE_TABLES(); + DbManager.LootQueries.LOAD_ALL_GENTABLES(); DbManager.LootQueries.LOAD_ALL_ITEMTABLES(); diff --git a/src/engine/loot/ModTypeTableEntry.java b/src/engine/loot/ModTypeTableEntry.java new file mode 100644 index 00000000..b8cd13bd --- /dev/null +++ b/src/engine/loot/ModTypeTableEntry.java @@ -0,0 +1,24 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ModTypeTableEntry { + public int minRoll; + public int maxRoll; + public int modTableID; + + public ModTypeTableEntry(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.modTableID = rs.getInt("subTableID"); + } +}