Browse Source

New consolidated loot db handler.

Booty loading moved into new handler.
master
MagicBot 1 year ago
parent
commit
0013020bfa
  1. 38
      src/engine/db/handlers/dbItemBaseHandler.java
  2. 49
      src/engine/db/handlers/dbLootHandler.java
  3. 2
      src/engine/gameManager/DbManager.java
  4. 2
      src/engine/gameManager/NPCManager.java

38
src/engine/db/handlers/dbItemBaseHandler.java

@ -10,7 +10,6 @@ @@ -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 { @@ -136,41 +135,4 @@ public class dbItemBaseHandler extends dbHandlerBase {
return runeSets;
}
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_FOR_MOBS() {
HashMap<Integer, ArrayList<BootySetEntry>> 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<BootySetEntry> bootyList = new ArrayList<>();
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
} else {
ArrayList<BootySetEntry> 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;
}
}

49
src/engine/db/handlers/dbLootTableHandler.java → src/engine/db/handlers/dbLootHandler.java

@ -11,10 +11,7 @@ package engine.db.handlers; @@ -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; @@ -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<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_FOR_MOBS() {
HashMap<Integer, ArrayList<BootySetEntry>> 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<BootySetEntry> bootyList = new ArrayList<>();
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
} else {
ArrayList<BootySetEntry> 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;

2
src/engine/gameManager/DbManager.java

@ -49,7 +49,7 @@ public enum DbManager { @@ -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();

2
src/engine/gameManager/NPCManager.java

@ -25,7 +25,7 @@ public enum NPCManager { @@ -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) {

Loading…
Cancel
Save