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

241 lines
8.6 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-06 17:47:49 -04:00
import engine.loot.*;
2022-04-30 09:41:17 -04:00
import engine.objects.Item;
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;
2023-08-06 17:47:49 -04:00
import java.util.ArrayList;
import java.util.HashMap;
2022-04-30 09:41:17 -04:00
2023-08-06 17:47:49 -04:00
public class dbLootHandler extends dbHandlerBase {
2022-04-30 09:41:17 -04:00
2023-08-06 17:47:49 -04:00
public dbLootHandler() {
2022-04-30 09:41:17 -04:00
}
2023-08-06 18:00:45 -04:00
public HashMap<Integer, ArrayList<GenTableEntry>> LOAD_GEN_ITEM_TABLES() {
HashMap<Integer, ArrayList<GenTableEntry>> genTables = new HashMap<>();
GenTableEntry genTableEntry;
int genTableID;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
2023-08-07 10:52:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_gen`")) {
2023-08-06 18:00:45 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-07 10:52:37 -04:00
genTableID = rs.getInt("genTable");
2023-08-06 18:00:45 -04:00
genTableEntry = new GenTableEntry(rs);
if (genTables.get(genTableID) == null) {
ArrayList<GenTableEntry> genItemList = new ArrayList<>();
genItemList.add(genTableEntry);
genTables.put(genTableID, genItemList);
} else {
ArrayList<GenTableEntry> genItemList = genTables.get(genTableID);
genItemList.add(genTableEntry);
genTables.put(genTableID, genItemList);
}
}
} catch (SQLException e) {
Logger.error(e);
return genTables;
}
Logger.info("read: " + recordsRead + " cached: " + genTables.size());
return genTables;
}
2023-08-07 08:39:08 -04:00
public HashMap<Integer, ArrayList<ItemTableEntry>> LOAD_ITEM_TABLES() {
2023-08-06 17:47:49 -04:00
2023-08-07 08:39:08 -04:00
HashMap<Integer, ArrayList<ItemTableEntry>> itemTables = new HashMap<>();
ItemTableEntry itemTableEntry;
int itemTableID;
2023-08-06 17:47:49 -04:00
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
2023-08-07 10:52:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_item`")) {
2023-08-06 17:47:49 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-07 08:39:08 -04:00
itemTableID = rs.getInt("itemTable");
itemTableEntry = new ItemTableEntry(rs);
2023-08-06 17:47:49 -04:00
2023-08-07 08:39:08 -04:00
if (itemTables.get(itemTableID) == null) {
ArrayList<ItemTableEntry> itemTableList = new ArrayList<>();
itemTableList.add(itemTableEntry);
itemTables.put(itemTableID, itemTableList);
2023-08-06 17:47:49 -04:00
} else {
2023-08-07 08:39:08 -04:00
ArrayList<ItemTableEntry> itemTableList = itemTables.get(itemTableID);
itemTableList.add(itemTableEntry);
itemTables.put(itemTableID, itemTableList);
2023-08-06 17:47:49 -04:00
}
}
} catch (SQLException e) {
Logger.error(e);
2023-08-07 08:39:08 -04:00
return itemTables;
2023-08-06 17:47:49 -04:00
}
2023-08-07 08:39:08 -04:00
Logger.info("read: " + recordsRead + " cached: " + itemTables.size());
return itemTables;
2023-08-06 17:47:49 -04:00
}
2023-08-07 08:49:43 -04:00
public HashMap<Integer, ArrayList<ModTableEntry>> LOAD_MOD_TABLES() {
HashMap<Integer, ArrayList<ModTableEntry>> modTables = new HashMap<>();
ModTableEntry modTableEntry;
int modTableID;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
2023-08-07 10:52:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_mod`")) {
2023-08-07 08:49:43 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
2023-08-07 10:52:37 -04:00
modTableID = rs.getInt("modTable");
2023-08-07 08:49:43 -04:00
modTableEntry = new ModTableEntry(rs);
if (modTables.get(modTableID) == null) {
ArrayList<ModTableEntry> modTableList = new ArrayList<>();
modTableList.add(modTableEntry);
modTables.put(modTableID, modTableList);
} else {
ArrayList<ModTableEntry> modTableList = modTables.get(modTableID);
modTableList.add(modTableEntry);
modTables.put(modTableID, modTableList);
}
}
} catch (SQLException e) {
Logger.error(e);
return modTables;
}
Logger.info("read: " + recordsRead + " cached: " + modTables.size());
return modTables;
}
2023-08-07 08:58:44 -04:00
public HashMap<Integer, ArrayList<ModTypeTableEntry>> LOAD_MOD_TYPE_TABLES() {
HashMap<Integer, ArrayList<ModTypeTableEntry>> modTypeTables = new HashMap<>();
ModTypeTableEntry modTypeTableEntry;
int modTableID;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
2023-08-07 10:52:37 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_modtype`")) {
2023-08-07 08:58:44 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
modTableID = rs.getInt("modType");
modTypeTableEntry = new ModTypeTableEntry(rs);
if (modTypeTables.get(modTableID) == null) {
ArrayList<ModTypeTableEntry> modTypeTableList = new ArrayList<>();
modTypeTableList.add(modTypeTableEntry);
modTypeTables.put(modTableID, modTypeTableList);
} else {
ArrayList<ModTypeTableEntry> modTypeTableList = modTypeTables.get(modTableID);
modTypeTableList.add(modTypeTableEntry);
modTypeTables.put(modTableID, modTypeTableList);
}
}
} catch (SQLException e) {
Logger.error(e);
return modTypeTables;
}
Logger.info("read: " + recordsRead + " cached: " + modTypeTables.size());
return modTypeTables;
}
2023-08-07 08:39:08 -04:00
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() {
2023-05-22 06:15:19 -04:00
2023-08-07 08:39:08 -04:00
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>();
BootySetEntry bootySetEntry;
int bootySetID;
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-08 18:25:40 -04:00
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_loot_bootySet")) {
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-07 08:39:08 -04:00
bootySetID = rs.getInt("bootySet");
bootySetEntry = new BootySetEntry(rs);
2023-05-22 06:15:19 -04:00
2023-08-07 08:39:08 -04:00
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);
}
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);
2023-08-07 08:39:08 -04:00
return bootySets;
2022-04-30 09:41:17 -04:00
}
2023-05-22 06:15:19 -04:00
2023-08-07 08:39:08 -04:00
Logger.info("read: " + recordsRead + " cached: " + bootySets.size());
return bootySets;
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
2022-04-30 09:41:17 -04:00
}