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

177 lines
5.2 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-21 08:36:39 -04:00
import engine.gameManager.DbManager;
import engine.objects.BootySetEntry;
2022-04-30 09:41:17 -04:00
import engine.objects.ItemBase;
import org.pmw.tinylog.Logger;
2023-05-21 08:36:39 -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;
import java.util.ArrayList;
import java.util.HashMap;
public class dbItemBaseHandler extends dbHandlerBase {
2023-05-23 10:27:03 -04:00
public dbItemBaseHandler() {
2022-04-30 09:41:17 -04:00
}
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
2023-05-21 08:36:39 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
2022-04-30 09:41:17 -04:00
2023-05-21 08:36:39 -04:00
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
while (rs.next()) {
if (rs.getBoolean("fromUse"))
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
else
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
}
} catch (SQLException e) {
2023-05-21 08:36:39 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
}
public void LOAD_ANIMATIONS(ItemBase itemBase) {
ArrayList<Integer> tempList = new ArrayList<>();
ArrayList<Integer> tempListOff = new ArrayList<>();
2023-05-21 08:36:39 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
while (rs.next()) {
int animation = rs.getInt("animation");
boolean rightHand = rs.getBoolean("rightHand");
if (rightHand)
tempList.add(animation);
else
tempListOff.add(animation);
}
} catch (SQLException e) {
2023-05-21 08:36:39 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
itemBase.setAnimations(tempList);
itemBase.setOffHandAnimations(tempListOff);
}
public void LOAD_ALL_ITEMBASES() {
ItemBase itemBase;
int recordsRead = 0;
2023-05-21 08:36:39 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
2022-04-30 09:41:17 -04:00
2023-05-21 08:36:39 -04:00
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
while (rs.next()) {
recordsRead++;
itemBase = new ItemBase(rs);
ItemBase.addToCache(itemBase);
}
} catch (SQLException e) {
2023-05-21 08:36:39 -04:00
Logger.error(e);
2022-04-30 09:41:17 -04:00
}
2023-05-21 08:36:39 -04:00
2023-05-21 15:48:55 -04:00
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
2022-04-30 09:41:17 -04:00
}
2023-03-28 17:45:58 -04:00
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
2023-05-21 08:36:39 -04:00
int runeSetID;
2023-03-28 17:45:58 -04:00
int runeBaseID;
int recordsRead = 0;
2023-05-21 08:36:39 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) {
2023-03-28 17:45:58 -04:00
2023-05-21 08:36:39 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-03-28 17:45:58 -04:00
while (rs.next()) {
recordsRead++;
runeSetID = rs.getInt("runeSet");
runeBaseID = rs.getInt("runeBase");
2023-05-21 08:36:39 -04:00
if (runeSets.get(runeSetID) == null) {
2023-03-28 17:45:58 -04:00
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(runeSetID, runeList);
2023-05-21 08:36:39 -04:00
} else {
ArrayList<Integer> runeList = runeSets.get(runeSetID);
2023-03-28 17:45:58 -04:00
runeList.add(runeSetID);
runeSets.put(runeSetID, runeList);
}
}
} catch (SQLException e) {
2023-05-21 08:36:39 -04:00
Logger.error(e);
return runeSets;
2023-03-28 17:45:58 -04:00
}
2023-05-21 08:36:39 -04:00
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
2023-03-28 17:45:58 -04:00
return runeSets;
}
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_FOR_MOBS() {
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>();
BootySetEntry bootySetEntry;
2023-05-21 08:36:39 -04:00
int bootySetID;
int recordsRead = 0;
2023-05-21 08:36:39 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_bootySet")) {
2023-05-21 08:36:39 -04:00
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
bootySetID = rs.getInt("bootySet");
bootySetEntry = new BootySetEntry(rs);
2023-05-21 08:36:39 -04:00
if (bootySets.get(bootySetID) == null) {
ArrayList<BootySetEntry> bootyList = new ArrayList<>();
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
2023-05-21 08:36:39 -04:00
} else {
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID);
bootyList.add(bootySetEntry);
bootySets.put(bootySetID, bootyList);
}
}
} catch (SQLException e) {
2023-05-21 08:36:39 -04:00
Logger.error(e);
return bootySets;
}
2023-05-21 08:36:39 -04:00
Logger.info("read: " + recordsRead + " cached: " + bootySets.size());
return bootySets;
}
2022-04-30 09:41:17 -04:00
}