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; @@ -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 { @@ -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 { @@ -68,15 +67,16 @@ public class dbLootHandler extends dbHandlerBase {
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<>();
BootySetEntry bootySetEntry;
int bootySetID;
HashMap<Integer, ArrayList<ItemTableEntry>> 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 { @@ -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<BootySetEntry> bootyList = new ArrayList<>();
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
if (itemTables.get(itemTableID) == null) {
ArrayList<ItemTableEntry> itemTableList = new ArrayList<>();
itemTableList.add(itemTableEntry);
itemTables.put(itemTableID, itemTableList);
} else {
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID);
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
ArrayList<ItemTableEntry> 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<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() {
HashMap<Integer, ArrayList<BootySetEntry>> 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<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: " + LootTable.getModTypeTables().size());
Logger.info("read: " + recordsRead + " cached: " + bootySets.size());
return bootySets;
}
public void LOAD_ENCHANT_VALUES() {

4
src/engine/gameManager/LootManager.java

@ -30,7 +30,7 @@ public enum LootManager { @@ -30,7 +30,7 @@ public enum LootManager {
// Newer tables
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
public static final HashMap<Integer, GenTable> generalItemTables = null;
@ -54,6 +54,8 @@ public enum LootManager { @@ -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();

Loading…
Cancel
Save