From 32d71df8373bad6b08a0fea7dff0251c41164547 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 7 Aug 2023 08:39:08 -0400 Subject: [PATCH] _itemTables populated at startup. --- src/engine/db/handlers/dbLootHandler.java | 126 +++++++--------------- src/engine/gameManager/LootManager.java | 4 +- 2 files changed, 41 insertions(+), 89 deletions(-) diff --git a/src/engine/db/handlers/dbLootHandler.java b/src/engine/db/handlers/dbLootHandler.java index 5f267701..94ebaff5 100644 --- a/src/engine/db/handlers/dbLootHandler.java +++ b/src/engine/db/handlers/dbLootHandler.java @@ -13,7 +13,6 @@ import engine.gameManager.DbManager; import engine.gameManager.LootManager; import engine.loot.*; import engine.objects.Item; -import engine.objects.LootTable; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -38,7 +37,7 @@ public class dbLootHandler extends dbHandlerBase { int recordsRead = 0; try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `genTable`, `minRoll`, `maxRoll`, `itemTableID`, `pModTableID`, `sModTableID` FROM `static_gentables`")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_gentables`")) { ResultSet rs = preparedStatement.executeQuery(); @@ -68,15 +67,16 @@ public class dbLootHandler extends dbHandlerBase { return genTables; } - public HashMap> LOAD_BOOTY_TABLES() { + public HashMap> LOAD_ITEM_TABLES() { - HashMap> bootySets = new HashMap<>(); - BootySetEntry bootySetEntry; - int bootySetID; + HashMap> itemTables = new HashMap<>(); + ItemTableEntry itemTableEntry; + + int itemTableID; int recordsRead = 0; try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itemTables`")) { ResultSet rs = preparedStatement.executeQuery(); @@ -84,114 +84,64 @@ public class dbLootHandler extends dbHandlerBase { recordsRead++; - bootySetID = rs.getInt("bootySet"); - bootySetEntry = new BootySetEntry(rs); + itemTableID = rs.getInt("itemTable"); + itemTableEntry = new ItemTableEntry(rs); - if (bootySets.get(bootySetID) == null) { - ArrayList bootyList = new ArrayList<>(); - bootyList.add(bootySetEntry); - bootySets.put(bootySetID, bootyList); + if (itemTables.get(itemTableID) == null) { + ArrayList itemTableList = new ArrayList<>(); + itemTableList.add(itemTableEntry); + itemTables.put(itemTableID, itemTableList); } else { - ArrayList bootyList = bootySets.get(bootySetID); - bootyList.add(bootySetEntry); - bootySets.put(bootySetID, bootyList); + ArrayList itemTableList = itemTables.get(itemTableID); + itemTableList.add(itemTableEntry); + itemTables.put(itemTableID, itemTableList); } } } catch (SQLException e) { Logger.error(e); - return bootySets; + return itemTables; } - Logger.info("read: " + recordsRead + " cached: " + bootySets.size()); - return bootySets; + Logger.info("read: " + recordsRead + " cached: " + itemTables.size()); + return itemTables; } - public void populateGenTables() { - - int recordsRead = 0; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `genTable`, `minRoll`, `maxRoll`, `itemTableID`, `pModTableID`, `sModTableID` FROM `static_gentables`")) { - - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - recordsRead++; - LootTable lootTable = LootTable.getGenTable(rs.getInt("genTable")); - lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("itemTableID"), rs.getInt("pModTableID"), rs.getInt("sModTableID"), ""); - } - - } catch (SQLException e) { - Logger.error(e); - } - - Logger.info("read: " + recordsRead + " cached: " + LootTable.getGenTables().size()); - } - - public void populateItemTables() { + public HashMap> LOAD_BOOTY_TABLES() { + HashMap> bootySets = new HashMap<>(); + BootySetEntry bootySetEntry; + int bootySetID; int recordsRead = 0; try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `itemTable`, `minRoll`, `maxRoll`, `itemBaseUUID`, `minSpawn`, `maxSpawn` FROM `static_itemtables`")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { - recordsRead++; - LootTable lootTable = LootTable.getItemTable(rs.getInt("itemTable")); - lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("itemBaseUUID"), rs.getInt("minSpawn"), rs.getInt("maxSpawn"), ""); - } - - } catch (SQLException e) { - Logger.error(e); - } - - Logger.info("read: " + recordsRead + " cached: " + LootTable.getItemTables().size()); - } - - public void populateModTables() { - - int recordsRead = 0; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `modTable`,`minRoll`,`maxRoll`,`value`,`action` FROM `static_modtables`")) { - - ResultSet rs = preparedStatement.executeQuery(); - while (rs.next()) { recordsRead++; - LootTable lootTable = LootTable.getModTable(rs.getInt("modTable")); - lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("value"), 0, 0, rs.getString("action")); - } - } catch (SQLException e) { - Logger.error(e); - } - - Logger.info("read: " + recordsRead + " cached: " + LootTable.getModTables().size()); - } - - public void populateModTypeTables() { - - int recordsRead = 0; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT `modType`,`minRoll`,`maxRoll`,`subTableID` FROM `static_modtypetables`")) { - - ResultSet rs = preparedStatement.executeQuery(); + bootySetID = rs.getInt("bootySet"); + bootySetEntry = new BootySetEntry(rs); - while (rs.next()) { - recordsRead++; - LootTable lootTable = LootTable.getModTypeTable(rs.getInt("modType")); - lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("subTableID"), 0, 0, ""); + if (bootySets.get(bootySetID) == null) { + ArrayList bootyList = new ArrayList<>(); + bootyList.add(bootySetEntry); + bootySets.put(bootySetID, bootyList); + } else { + ArrayList bootyList = bootySets.get(bootySetID); + bootyList.add(bootySetEntry); + bootySets.put(bootySetID, bootyList); + } } - } catch (SQLException e) { Logger.error(e); + return bootySets; } - Logger.info("read: " + recordsRead + " cached: " + LootTable.getModTypeTables().size()); + Logger.info("read: " + recordsRead + " cached: " + bootySets.size()); + return bootySets; } public void LOAD_ENCHANT_VALUES() { diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 918ccb29..7558c024 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -30,7 +30,7 @@ public enum LootManager { // Newer tables public static HashMap> _genTables = new HashMap<>(); - public static HashMap> _itemTable = new HashMap<>(); + public static HashMap> _itemTables = new HashMap<>(); //new tables public static final HashMap generalItemTables = null; @@ -54,6 +54,8 @@ public enum LootManager { // Load loot tables from database. _genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES(); + _itemTables = DbManager.LootQueries.LOAD_ITEM_TABLES(); + DbManager.LootQueries.LOAD_ALL_GENTABLES(); DbManager.LootQueries.LOAD_ALL_ITEMTABLES();