Browse Source

_itemTables populated at startup.

master
MagicBot 1 year ago
parent
commit
32d71df837
  1. 126
      src/engine/db/handlers/dbLootHandler.java
  2. 4
      src/engine/gameManager/LootManager.java

126
src/engine/db/handlers/dbLootHandler.java

@ -13,7 +13,6 @@ import engine.gameManager.DbManager;
import engine.gameManager.LootManager; import engine.gameManager.LootManager;
import engine.loot.*; import engine.loot.*;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.LootTable;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -38,7 +37,7 @@ public class dbLootHandler extends dbHandlerBase {
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); 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(); ResultSet rs = preparedStatement.executeQuery();
@ -68,15 +67,16 @@ public class dbLootHandler extends dbHandlerBase {
return genTables; return genTables;
} }
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() { public HashMap<Integer, ArrayList<ItemTableEntry>> LOAD_ITEM_TABLES() {
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>(); HashMap<Integer, ArrayList<ItemTableEntry>> itemTables = new HashMap<>();
BootySetEntry bootySetEntry; ItemTableEntry itemTableEntry;
int bootySetID;
int itemTableID;
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); 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(); ResultSet rs = preparedStatement.executeQuery();
@ -84,114 +84,64 @@ public class dbLootHandler extends dbHandlerBase {
recordsRead++; recordsRead++;
bootySetID = rs.getInt("bootySet"); itemTableID = rs.getInt("itemTable");
bootySetEntry = new BootySetEntry(rs); itemTableEntry = new ItemTableEntry(rs);
if (bootySets.get(bootySetID) == null) { if (itemTables.get(itemTableID) == null) {
ArrayList<BootySetEntry> bootyList = new ArrayList<>(); ArrayList<ItemTableEntry> itemTableList = new ArrayList<>();
bootyList.add(bootySetEntry); itemTableList.add(itemTableEntry);
bootySets.put(bootySetID, bootyList); itemTables.put(itemTableID, itemTableList);
} else { } else {
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID); ArrayList<ItemTableEntry> itemTableList = itemTables.get(itemTableID);
bootyList.add(bootySetEntry); itemTableList.add(itemTableEntry);
bootySets.put(bootySetID, bootyList); itemTables.put(itemTableID, itemTableList);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return bootySets; return itemTables;
} }
Logger.info("read: " + recordsRead + " cached: " + bootySets.size()); Logger.info("read: " + recordsRead + " cached: " + itemTables.size());
return bootySets; return itemTables;
} }
public void populateGenTables() { public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() {
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() {
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>();
BootySetEntry bootySetEntry;
int bootySetID;
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); 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(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { 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++; 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) { bootySetID = rs.getInt("bootySet");
Logger.error(e); bootySetEntry = new BootySetEntry(rs);
}
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();
while (rs.next()) { if (bootySets.get(bootySetID) == null) {
recordsRead++; ArrayList<BootySetEntry> bootyList = new ArrayList<>();
LootTable lootTable = LootTable.getModTypeTable(rs.getInt("modType")); bootyList.add(bootySetEntry);
lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("subTableID"), 0, 0, ""); bootySets.put(bootySetID, bootyList);
} else {
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID);
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
}
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(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() { public void LOAD_ENCHANT_VALUES() {

4
src/engine/gameManager/LootManager.java

@ -30,7 +30,7 @@ public enum LootManager {
// Newer tables // Newer tables
public static HashMap<Integer, ArrayList<GenTableEntry>> _genTables = new HashMap<>(); public static HashMap<Integer, ArrayList<GenTableEntry>> _genTables = new HashMap<>();
public static HashMap<Integer, ArrayList<ItemTableEntry>> _itemTable = new HashMap<>(); public static HashMap<Integer, ArrayList<ItemTableEntry>> _itemTables = new HashMap<>();
//new tables //new tables
public static final HashMap<Integer, GenTable> generalItemTables = null; public static final HashMap<Integer, GenTable> generalItemTables = null;
@ -54,6 +54,8 @@ public enum LootManager {
// Load loot tables from database. // Load loot tables from database.
_genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES(); _genTables = DbManager.LootQueries.LOAD_GEN_ITEM_TABLES();
_itemTables = DbManager.LootQueries.LOAD_ITEM_TABLES();
DbManager.LootQueries.LOAD_ALL_GENTABLES(); DbManager.LootQueries.LOAD_ALL_GENTABLES();
DbManager.LootQueries.LOAD_ALL_ITEMTABLES(); DbManager.LootQueries.LOAD_ALL_ITEMTABLES();

Loading…
Cancel
Save