Files
Server/src/engine/db/handlers/dbLootTableHandler.java
T

220 lines
7.7 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers;
2023-05-22 06:15:19 -04:00
import engine.gameManager.DbManager;
2023-08-03 08:27:08 -04:00
import engine.gameManager.LootManager;
import engine.loot.GenTableRow;
import engine.loot.ItemTableRow;
import engine.loot.ModTableRow;
import engine.loot.ModTypeTableRow;
2022-04-30 09:41:17 -04:00
import engine.objects.Item;
import engine.objects.LootTable;
import org.pmw.tinylog.Logger;
2023-05-22 06:15:19 -04:00
import java.sql.Connection;
import java.sql.PreparedStatement;
2022-04-30 09:41:17 -04:00
import java.sql.ResultSet;
import java.sql.SQLException;
public class dbLootTableHandler extends dbHandlerBase {
public dbLootTableHandler() {
}
2023-08-05 10:38:21 -04:00
public void populateGenTables() {
2023-05-22 06:15:19 -04:00
2022-04-30 09:41:17 -04:00
int recordsRead = 0;
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:48:21 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `genTable`, `minRoll`, `maxRoll`, `itemTableID`, `pModTableID`, `sModTableID` FROM `static_gentables`")) {
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-06 07:59:27 -04:00
LootTable lootTable = LootTable.getGenTable(rs.getInt("genTable"));
2023-08-05 10:48:21 -04:00
lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("itemTableID"), rs.getInt("pModTableID"), rs.getInt("sModTableID"), "");
2023-05-22 06:15:19 -04:00
}
2022-04-30 09:41:17 -04:00
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead + " cached: " + LootTable.getLootGroups().size());
2022-04-30 09:41:17 -04:00
}
2023-08-05 10:38:21 -04:00
public void populateItemTables() {
2023-05-22 06:15:19 -04:00
2022-04-30 09:41:17 -04:00
int recordsRead = 0;
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:48:21 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `itemTable`, `minRoll`, `maxRoll`, `itemBaseUUID`, `minSpawn`, `maxSpawn` FROM `static_itemtables`")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-05 10:38:21 -04:00
LootTable lootTable = LootTable.getLootTable(rs.getInt("itemTable"));
2023-05-22 06:15:19 -04:00
lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("itemBaseUUID"), rs.getInt("minSpawn"), rs.getInt("maxSpawn"), "");
}
2023-04-06 20:07:24 -05:00
2022-04-30 09:41:17 -04:00
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead + " cached: " + LootTable.getLootTables().size());
2022-04-30 09:41:17 -04:00
}
public void populateModTables() {
2023-04-06 20:07:24 -05:00
2022-04-30 09:41:17 -04:00
int recordsRead = 0;
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
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"));
}
2022-04-30 09:41:17 -04:00
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead + " cached: " + LootTable.getModTables().size());
2022-04-30 09:41:17 -04:00
}
2023-08-05 10:38:21 -04:00
public void populateModTypeTables() {
2023-04-06 20:07:24 -05:00
2022-04-30 09:41:17 -04:00
int recordsRead = 0;
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:48:21 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `modType`,`minRoll`,`maxRoll`,`subTableID` FROM `static_modtypetables`")) {
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-05 10:38:21 -04:00
LootTable lootTable = LootTable.getModGroup(rs.getInt("modType"));
2023-05-22 06:15:19 -04:00
lootTable.addRow(rs.getFloat("minRoll"), rs.getFloat("maxRoll"), rs.getInt("subTableID"), 0, 0, "");
}
2022-04-30 09:41:17 -04:00
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead + " cached: " + LootTable.getModGroups().size());
2022-04-30 09:41:17 -04:00
}
public void LOAD_ENCHANT_VALUES() {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `IDString`, `minMod` FROM `static_power_effectmod` WHERE `modType` = ?")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
preparedStatement.setString(1, "Value");
ResultSet rs = preparedStatement.executeQuery();
while (rs.next())
2022-04-30 09:41:17 -04:00
Item.addEnchantValue(rs.getString("IDString"), rs.getInt("minMod"));
2023-05-22 06:15:19 -04:00
2022-04-30 09:41:17 -04:00
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
}
2023-04-06 20:07:24 -05:00
2023-08-05 10:11:31 -04:00
public void LOAD_ALL_GENTABLES() {
2023-05-22 06:15:19 -04:00
2023-04-06 20:07:24 -05:00
int recordsRead = 0;
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:17:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_gentables")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-04-06 20:07:24 -05:00
while (rs.next()) {
GenTableRow row = new GenTableRow(rs);
2023-08-05 10:28:32 -04:00
LootManager.AddGenTableRow(rs.getInt("gentable"), row);
2023-04-06 20:07:24 -05:00
}
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2023-04-06 20:07:24 -05:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead);
2023-04-06 20:07:24 -05:00
}
2023-08-05 10:17:37 -04:00
public void LOAD_ALL_ITEMTABLES() {
2023-04-06 20:07:24 -05:00
int recordsRead = 0;
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:17:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itemtables")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-04-06 20:07:24 -05:00
while (rs.next()) {
recordsRead++;
ItemTableRow row = new ItemTableRow(rs);
2023-08-05 10:28:32 -04:00
LootManager.AddItemTableRow(rs.getInt("itemTable"), row);
2023-04-06 20:07:24 -05:00
}
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2023-04-06 20:07:24 -05:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead);
2023-04-06 20:07:24 -05:00
}
2023-08-05 10:28:32 -04:00
public void LOAD_ALL_MODTYPES() {
2023-04-06 20:07:24 -05:00
int recordsRead = 0;
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
2023-08-05 10:28:32 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_modtypetables")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-04-06 20:07:24 -05:00
while (rs.next()) {
recordsRead++;
ModTypeTableRow mttr = new ModTypeTableRow(rs);
2023-08-05 10:28:32 -04:00
LootManager.AddModTypeTableRow(rs.getInt("modType"), mttr);
2023-04-06 20:07:24 -05:00
}
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2023-04-06 20:07:24 -05:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead);
2023-04-06 20:07:24 -05:00
}
public void LOAD_ALL_MODTABLES() {
int recordsRead = 0;
2023-05-22 06:15:19 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_modtables")) {
2023-04-06 20:07:24 -05:00
2023-05-22 06:15:19 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-04-06 20:07:24 -05:00
while (rs.next()) {
recordsRead++;
ModTableRow mtr = new ModTableRow(rs);
2023-05-22 06:15:19 -04:00
LootManager.AddModTableRow(rs.getInt("modTable"), mtr);
2023-04-06 20:07:24 -05:00
}
} catch (SQLException e) {
2023-05-22 06:15:19 -04:00
Logger.error(e);
2023-04-06 20:07:24 -05:00
}
2023-05-22 06:15:19 -04:00
Logger.info("read: " + recordsRead);
2023-04-06 20:07:24 -05:00
}
2022-04-30 09:41:17 -04:00
}