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

139 lines
4.8 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;
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
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -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-07-15 09:23:48 -04:00
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -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) {
Logger.error(e);
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void LOAD_ANIMATIONS(ItemBase itemBase) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ArrayList<Integer> tempList = new ArrayList<>();
ArrayList<Integer> tempListOff = new ArrayList<>();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
2023-05-21 08:36:39 -04:00
2023-07-15 09:23:48 -04:00
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
while (rs.next()) {
int animation = rs.getInt("animation");
boolean rightHand = rs.getBoolean("rightHand");
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (rightHand)
tempList.add(animation);
else
tempListOff.add(animation);
}
} catch (SQLException e) {
Logger.error(e);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
itemBase.setAnimations(tempList);
itemBase.setOffHandAnimations(tempListOff);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void LOAD_ALL_ITEMBASES() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ItemBase itemBase;
int recordsRead = 0;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
while (rs.next()) {
recordsRead++;
itemBase = new ItemBase(rs);
ItemBase.addToCache(itemBase);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-21 08:36:39 -04:00
2023-07-15 09:23:48 -04:00
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
int runeSetID;
int runeBaseID;
int recordsRead = 0;
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -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-07-15 09:23:48 -04:00
ResultSet rs = preparedStatement.executeQuery();
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
while (rs.next()) {
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
recordsRead++;
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
runeSetID = rs.getInt("runeSet");
runeBaseID = rs.getInt("runeBase");
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
if (runeSets.get(runeSetID) == null) {
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(runeSetID, runeList);
} else {
ArrayList<Integer> runeList = runeSets.get(runeSetID);
runeList.add(runeSetID);
runeSets.put(runeSetID, runeList);
}
}
2023-03-28 17:45:58 -04:00
2023-07-15 09:23:48 -04:00
} catch (SQLException e) {
Logger.error(e);
return runeSets;
}
2023-05-21 08:36:39 -04:00
2023-07-15 09:23:48 -04:00
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
return runeSets;
}
2022-04-30 09:41:17 -04:00
}