2026-07-26 19:08:44 -04:00
|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
|
// Magicbane Emulator Project © 2013 - 2026
|
|
|
|
|
// https://www.magicbane.com
|
2022-04-30 09:41:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
package engine.db.handlers;
|
|
|
|
|
|
2023-05-22 12:58:16 -04:00
|
|
|
import engine.gameManager.DbManager;
|
2024-04-05 07:59:44 -04:00
|
|
|
import engine.mbEnums;
|
2026-10-23 11:35:58 -04:00
|
|
|
import engine.objects.AbstractGameObject;
|
|
|
|
|
import engine.objects.BaseClass;
|
|
|
|
|
import engine.objects.PromotionClass;
|
|
|
|
|
import engine.objects.Race;
|
2022-04-30 09:41:17 -04:00
|
|
|
import engine.objects.RuneBase;
|
2023-09-03 08:18:48 -04:00
|
|
|
import engine.powers.RunePowerEntry;
|
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;
|
2024-04-05 07:59:44 -04:00
|
|
|
this.localObjectType = mbEnums.GameObjectType.valueOf(this.localClass.getSimpleName());
|
2023-05-23 10:27:03 -04:00
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-09-03 08:18:48 -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;
|
|
|
|
|
}
|
2026-10-23 11:35:58 -04:00
|
|
|
|
|
|
|
|
// static_rune_lookup is generated for the DB views; a failed write must never stop the boot
|
|
|
|
|
public static void WRITE_RUNE_LOOKUP() {
|
|
|
|
|
|
|
|
|
|
int rowsWritten = 0;
|
|
|
|
|
|
|
|
|
|
try (Connection connection = DbManager.getConnection();
|
|
|
|
|
PreparedStatement deleteStatement = connection.prepareStatement("DELETE FROM `static_rune_lookup`");
|
|
|
|
|
PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO `static_rune_lookup` (`ID`, `type`, `name`) VALUES (?, ?, ?)")) {
|
|
|
|
|
|
|
|
|
|
connection.setAutoCommit(false);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
deleteStatement.executeUpdate();
|
|
|
|
|
|
|
|
|
|
for (Race race : Race.getAllRaces()) {
|
|
|
|
|
addRuneLookupRow(insertStatement, race.getRaceRuneID(), "RACE", race.getName());
|
|
|
|
|
rowsWritten++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (AbstractGameObject baseClass : DbManager.getMap(mbEnums.GameObjectType.BaseClass).values()) {
|
|
|
|
|
addRuneLookupRow(insertStatement, baseClass.getObjectUUID(), "BASECLASS", ((BaseClass) baseClass).getName());
|
|
|
|
|
rowsWritten++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (AbstractGameObject promotionClass : DbManager.getMap(mbEnums.GameObjectType.PromotionClass).values()) {
|
|
|
|
|
addRuneLookupRow(insertStatement, promotionClass.getObjectUUID(), "PROMOTION", ((PromotionClass) promotionClass).getName());
|
|
|
|
|
rowsWritten++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertStatement.executeBatch();
|
|
|
|
|
connection.commit();
|
|
|
|
|
} catch (SQLException | RuntimeException e) {
|
|
|
|
|
// Roll back before setAutoCommit(true), which would otherwise commit the delete
|
|
|
|
|
connection.rollback();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
connection.setAutoCommit(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Logger.warn("static_rune_lookup not written; DB views keep their old names: " + e.getMessage());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.info("static_rune_lookup: wrote " + rowsWritten + " rows");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void addRuneLookupRow(PreparedStatement insertStatement, int runeID, String type, String name) throws SQLException {
|
|
|
|
|
insertStatement.setInt(1, runeID);
|
|
|
|
|
insertStatement.setString(2, type);
|
|
|
|
|
insertStatement.setString(3, name);
|
|
|
|
|
insertStatement.addBatch();
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
}
|