From 8c4d9b66ef127f1479180459d2235fe49ab2bd79 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 7 Aug 2023 08:49:43 -0400 Subject: [PATCH] _modTables populated at startup. --- src/engine/db/handlers/dbLootHandler.java | 39 +++++++++++++++++++++++ src/engine/gameManager/LootManager.java | 3 +- src/engine/loot/ModTableEntry.java | 26 +++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/engine/loot/ModTableEntry.java diff --git a/src/engine/db/handlers/dbLootHandler.java b/src/engine/db/handlers/dbLootHandler.java index 94ebaff5..75fe1454 100644 --- a/src/engine/db/handlers/dbLootHandler.java +++ b/src/engine/db/handlers/dbLootHandler.java @@ -106,6 +106,45 @@ public class dbLootHandler extends dbHandlerBase { return itemTables; } + public HashMap> LOAD_MOD_TABLES() { + + HashMap> modTables = new HashMap<>(); + ModTableEntry modTableEntry; + + int modTableID; + int recordsRead = 0; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_modTables`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + recordsRead++; + + modTableID = rs.getInt("itemTable"); + modTableEntry = new ModTableEntry(rs); + + if (modTables.get(modTableID) == null) { + ArrayList modTableList = new ArrayList<>(); + modTableList.add(modTableEntry); + modTables.put(modTableID, modTableList); + } else { + ArrayList modTableList = modTables.get(modTableID); + modTableList.add(modTableEntry); + modTables.put(modTableID, modTableList); + } + } + } catch (SQLException e) { + Logger.error(e); + return modTables; + } + + Logger.info("read: " + recordsRead + " cached: " + modTables.size()); + return modTables; + } + public HashMap> LOAD_BOOTY_TABLES() { HashMap> bootySets = new HashMap<>(); diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 7558c024..479cc8cf 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -31,6 +31,7 @@ public enum LootManager { public static HashMap> _genTables = new HashMap<>(); public static HashMap> _itemTables = new HashMap<>(); + public static HashMap> _modTables = new HashMap<>(); //new tables public static final HashMap generalItemTables = null; @@ -55,7 +56,7 @@ public enum LootManager { _genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES(); _itemTables = DbManager.LootQueries.LOAD_ITEM_TABLES(); - + _modTables = DbManager.LootQueries.LOAD_MOD_TABLES(); DbManager.LootQueries.LOAD_ALL_GENTABLES(); DbManager.LootQueries.LOAD_ALL_ITEMTABLES(); diff --git a/src/engine/loot/ModTableEntry.java b/src/engine/loot/ModTableEntry.java new file mode 100644 index 00000000..2572910a --- /dev/null +++ b/src/engine/loot/ModTableEntry.java @@ -0,0 +1,26 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.loot; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ModTableEntry { + public int minRoll; + public int maxRoll; + public String action; + public int level; + + public ModTableEntry(ResultSet rs) throws SQLException { + this.minRoll = rs.getInt("minRoll"); + this.maxRoll = rs.getInt("maxRoll"); + this.action = rs.getString("action"); + this.level = rs.getInt("level"); + } +}