From 0013020bfa3b7d8770bba5e93f96cf5c18c43229 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 6 Aug 2023 17:47:49 -0400 Subject: [PATCH] New consolidated loot db handler. Booty loading moved into new handler. --- src/engine/db/handlers/dbItemBaseHandler.java | 38 -------------- ...otTableHandler.java => dbLootHandler.java} | 49 ++++++++++++++++--- src/engine/gameManager/DbManager.java | 2 +- src/engine/gameManager/NPCManager.java | 2 +- 4 files changed, 45 insertions(+), 46 deletions(-) rename src/engine/db/handlers/{dbLootTableHandler.java => dbLootHandler.java} (83%) diff --git a/src/engine/db/handlers/dbItemBaseHandler.java b/src/engine/db/handlers/dbItemBaseHandler.java index 804b8587..bf12b434 100644 --- a/src/engine/db/handlers/dbItemBaseHandler.java +++ b/src/engine/db/handlers/dbItemBaseHandler.java @@ -10,7 +10,6 @@ package engine.db.handlers; import engine.gameManager.DbManager; -import engine.loot.BootySetEntry; import engine.objects.ItemBase; import org.pmw.tinylog.Logger; @@ -136,41 +135,4 @@ public class dbItemBaseHandler extends dbHandlerBase { return runeSets; } - public HashMap> LOAD_BOOTY_FOR_MOBS() { - - HashMap> bootySets = new HashMap<>(); - BootySetEntry bootySetEntry; - int bootySetID; - int recordsRead = 0; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { - - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - - recordsRead++; - - bootySetID = rs.getInt("bootySet"); - bootySetEntry = new BootySetEntry(rs); - - 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: " + bootySets.size()); - return bootySets; - } } diff --git a/src/engine/db/handlers/dbLootTableHandler.java b/src/engine/db/handlers/dbLootHandler.java similarity index 83% rename from src/engine/db/handlers/dbLootTableHandler.java rename to src/engine/db/handlers/dbLootHandler.java index 40024d64..15b5289d 100644 --- a/src/engine/db/handlers/dbLootTableHandler.java +++ b/src/engine/db/handlers/dbLootHandler.java @@ -11,10 +11,7 @@ package engine.db.handlers; import engine.gameManager.DbManager; import engine.gameManager.LootManager; -import engine.loot.GenTableRow; -import engine.loot.ItemTableRow; -import engine.loot.ModTableRow; -import engine.loot.ModTypeTableRow; +import engine.loot.*; import engine.objects.Item; import engine.objects.LootTable; import org.pmw.tinylog.Logger; @@ -23,13 +20,53 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; -public class dbLootTableHandler extends dbHandlerBase { +public class dbLootHandler extends dbHandlerBase { - public dbLootTableHandler() { + public dbLootHandler() { } + public HashMap> LOAD_BOOTY_FOR_MOBS() { + + HashMap> bootySets = new HashMap<>(); + BootySetEntry bootySetEntry; + int bootySetID; + int recordsRead = 0; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + recordsRead++; + + bootySetID = rs.getInt("bootySet"); + bootySetEntry = new BootySetEntry(rs); + + 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: " + bootySets.size()); + return bootySets; + } + public void populateGenTables() { int recordsRead = 0; diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index a2e2522f..25792846 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -49,7 +49,7 @@ public enum DbManager { public static final dbItemHandler ItemQueries = new dbItemHandler(); public static final dbItemBaseHandler ItemBaseQueries = new dbItemBaseHandler(); public static final dbKitHandler KitQueries = new dbKitHandler(); - public static final dbLootTableHandler LootQueries = new dbLootTableHandler(); + public static final dbLootHandler LootQueries = new dbLootHandler(); public static final dbMenuHandler MenuQueries = new dbMenuHandler(); public static final dbMineHandler MineQueries = new dbMineHandler(); public static final dbMobHandler MobQueries = new dbMobHandler(); diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index 1e91ba5f..31e54704 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -25,7 +25,7 @@ public enum NPCManager { } public static void LoadAllBootySets() { - _bootySetMap = DbManager.ItemBaseQueries.LOAD_BOOTY_FOR_MOBS(); + _bootySetMap = DbManager.LootQueries.LOAD_BOOTY_FOR_MOBS(); } public static void applyRuneSetEffects(Mob mob) {