Files
lakebane/src/engine/db/handlers/dbRuneBaseHandler.java
T

260 lines
9.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-22 12:58:16 -04:00
import engine.gameManager.DbManager;
2022-04-30 09:41:17 -04:00
import engine.objects.RuneBase;
import engine.powers.RunePowerEntry;
import engine.powers.RuneSkillAdjustEntry;
2022-04-30 09:41:17 -04:00
import org.pmw.tinylog.Logger;
2023-05-22 12:58:16 -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 dbRuneBaseHandler extends dbHandlerBase {
2023-05-23 10:27:03 -04:00
public dbRuneBaseHandler() {
this.localClass = RuneBase.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
2022-04-30 09:41:17 -04:00
public static HashMap<Integer, ArrayList<RunePowerEntry>> LOAD_RUNE_POWERS() {
HashMap<Integer, ArrayList<RunePowerEntry>> mobPowers = new HashMap<>();
RunePowerEntry runePowerEntry;
int rune_id;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_powers")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
rune_id = rs.getInt("rune_id");
runePowerEntry = new RunePowerEntry(rs);
if (mobPowers.get(rune_id) == null) {
ArrayList<RunePowerEntry> runePowerList = new ArrayList<>();
runePowerList.add(runePowerEntry);
mobPowers.put(rune_id, runePowerList);
} else {
ArrayList<RunePowerEntry> powerList = mobPowers.get(rune_id);
powerList.add(runePowerEntry);
mobPowers.put(rune_id, powerList);
}
}
} catch (SQLException e) {
Logger.error(e);
return mobPowers;
}
Logger.info("read: " + recordsRead + " cached: " + mobPowers.size());
return mobPowers;
}
public static HashMap<Integer, ArrayList<RuneSkillAdjustEntry>> LOAD_RUNE_SKILL_ADJUSTS() {
HashMap<Integer, ArrayList<RuneSkillAdjustEntry>> runeSkillAdjusts = new HashMap<>();
RuneSkillAdjustEntry runeSkillAdjustEntry;
int rune_id;
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_skill_adjusts")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
rune_id = rs.getInt("rune_id");
runeSkillAdjustEntry = new RuneSkillAdjustEntry(rs);
if (runeSkillAdjusts.get(rune_id) == null) {
ArrayList<RuneSkillAdjustEntry> skillAdjustList = new ArrayList<>();
skillAdjustList.add(runeSkillAdjustEntry);
runeSkillAdjusts.put(rune_id, skillAdjustList);
} else {
ArrayList<RuneSkillAdjustEntry> powerList = runeSkillAdjusts.get(rune_id);
powerList.add(runeSkillAdjustEntry);
runeSkillAdjusts.put(rune_id, powerList);
}
}
} catch (SQLException e) {
Logger.error(e);
return runeSkillAdjusts;
}
Logger.info("read: " + recordsRead + " cached: " + runeSkillAdjusts.size());
return runeSkillAdjusts;
}
2023-05-23 10:27:03 -04:00
public void GET_RUNE_REQS(final RuneBase rb) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) {
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, rb.getObjectUUID());
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next()) {
int type = rs.getInt("type");
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
switch (type) {
case 1:
rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break;
case 2:
rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break;
case 3:
rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break;
case 4:
rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break;
case 5:
rb.getOverwrite().add(rs.getInt("requiredRuneID"));
break;
case 6:
rb.setLevelRequired(rs.getInt("requiredRuneID"));
break;
}
}
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public RuneBase GET_RUNEBASE(final int id) {
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
RuneBase runeBase = null;
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) {
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, id);
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
runeBase = (RuneBase) getObjectFromRs(rs);
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
return runeBase;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
ArrayList<RuneBase> runeBasesList = new ArrayList<>();
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) {
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
runeBasesList = getObjectsFromRs(rs, 1000);
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
return runeBasesList;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
int recordsRead = 0;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next()) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
recordsRead++;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
int baseClassID = rs.getInt("BaseClassesID");
int runeBaseID = rs.getInt("RuneBaseID");
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (runeSets.get(baseClassID) == null) {
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList);
} else {
ArrayList<Integer> runeList = runeSets.get(baseClassID);
runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList);
}
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
2023-05-22 12:58:16 -04:00
2023-05-23 10:27:03 -04:00
return runeSets;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
HashMap<Integer, ArrayList<Integer>> runeSets;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
runeSets = new HashMap<>();
int recordsRead = 0;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next()) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
recordsRead++;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
int raceID = rs.getInt("RaceID");
int runeBaseID = rs.getInt("RuneBaseID");
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (runeSets.get(raceID) == null) {
ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID);
runeSets.put(raceID, runeList);
} else {
ArrayList<Integer> runeList = runeSets.get(raceID);
runeList.add(runeBaseID);
runeSets.put(raceID, runeList);
}
}
} catch (SQLException e) {
Logger.error(e);
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
return runeSets;
}
2022-04-30 09:41:17 -04:00
}