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

101 lines
3.6 KiB
Java
Raw Normal View History

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;
2024-05-12 13:36:47 -04:00
import engine.gameManager.DbManager;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
2023-05-22 06:35:24 -04:00
import engine.objects.MobBase;
2022-04-30 09:41:17 -04:00
import org.pmw.tinylog.Logger;
2023-05-22 06:35:24 -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;
public class dbMobBaseHandler extends dbHandlerBase {
2023-05-23 10:27:03 -04:00
public dbMobBaseHandler() {
this.localClass = MobBase.class;
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-05-23 10:27:03 -04:00
public MobBase GET_MOBBASE(int id) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (id == 0)
return null;
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id);
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (mobBase != null)
return mobBase;
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_npc_mobbase` WHERE `ID`=? AND `ID` = `loadID`")) {
2023-05-22 06:35:24 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, id);
2023-05-22 06:35:24 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
mobBase = (MobBase) getObjectFromRs(rs);
2023-05-22 06:35:24 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-22 06:35:24 -04:00
2023-05-23 10:27:03 -04:00
return mobBase;
}
2022-04-30 09:41:17 -04:00
2023-05-22 06:35:24 -04:00
2023-05-23 10:27:03 -04:00
public ArrayList<MobBase> GET_ALL_MOBBASES() {
2023-05-22 06:46:30 -04:00
2023-05-23 10:27:03 -04:00
ArrayList<MobBase> mobbaseList = new ArrayList<>();
// ID <> loadID rows were junk server-made mobbases (15000-17266); skip them on databases that still have them.
2023-05-22 06:46:30 -04:00
2023-05-23 10:27:03 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID` = `loadID`;")) {
2023-05-22 06:46:30 -04:00
2023-05-23 10:27:03 -04:00
ResultSet rs = preparedStatement.executeQuery();
mobbaseList = getObjectsFromRs(rs, 1000);
2023-05-22 06:46:30 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
Logger.info("Loaded " + mobbaseList.size() + " mobbases");
2023-05-23 10:27:03 -04:00
return mobbaseList;
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) {
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
if (mobBase.getLoadID() == 0)
return;
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_npc_mobbase_race` WHERE `mobbaseID` = ?")) {
2023-05-22 06:46:30 -04:00
2023-05-23 10:27:03 -04:00
preparedStatement.setInt(1, mobBase.getLoadID());
ResultSet rs = preparedStatement.executeQuery();
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
while (rs.next()) {
float walk = rs.getFloat("walkStandard");
float walkCombat = rs.getFloat("walkCombat");
float run = rs.getFloat("runStandard");
float runCombat = rs.getFloat("runCombat");
mobBase.updateSpeeds(walk, walkCombat, run, runCombat);
}
2022-04-30 09:41:17 -04:00
2023-05-23 10:27:03 -04:00
} catch (SQLException e) {
Logger.error(e);
}
}
2022-04-30 09:41:17 -04:00
}