Browse Source

Refactor to remove abstraction.

master
MagicBot 2 years ago
parent
commit
e9cb8112de
  1. 81
      src/engine/db/handlers/dbSkillReqHandler.java

81
src/engine/db/handlers/dbSkillReqHandler.java

@ -9,12 +9,15 @@
package engine.db.handlers; package engine.db.handlers;
import engine.objects.PreparedStatementShared; import engine.gameManager.DbManager;
import engine.objects.SkillReq; import engine.objects.SkillReq;
import engine.powers.PowersBase; import engine.powers.PowersBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -26,36 +29,39 @@ public class dbSkillReqHandler extends dbHandlerBase {
} }
public static ArrayList<PowersBase> getAllPowersBase() { public static ArrayList<PowersBase> getAllPowersBase() {
PreparedStatementShared ps = null;
ArrayList<PowersBase> out = new ArrayList<>(); ArrayList<PowersBase> powerBaseList = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_powerbase"); try (Connection connection = DbManager.getConnection();
ResultSet rs = ps.executeQuery(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powerbase")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
PowersBase toAdd = new PowersBase(rs); PowersBase toAdd = new PowersBase(rs);
out.add(toAdd); powerBaseList.add(toAdd);
} }
rs.close();
} catch (Exception e) { } catch (SQLException e) {
Logger.error(e.toString()); Logger.error(e);
} finally {
ps.release();
} }
return out;
return powerBaseList;
} }
public static void getFailConditions(HashMap<String, PowersBase> powers) { public static void getFailConditions(HashMap<String, PowersBase> powers) {
PreparedStatementShared ps = null;
try { try (Connection connection = DbManager.getConnection();
ps = new PreparedStatementShared("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'")) {
ResultSet rs = ps.executeQuery();
String type, IDString; ResultSet rs = preparedStatement.executeQuery();
PowersBase pb;
while (rs.next()) { while (rs.next()) {
type = rs.getString("type"); String type = rs.getString("type");
IDString = rs.getString("IDString"); String IDString = rs.getString("IDString");
pb = powers.get(IDString); PowersBase pb = powers.get(IDString);
if (pb != null) {
if (pb != null)
switch (type) { switch (type) {
case "CastSpell": case "CastSpell":
pb.cancelOnCastSpell = true; pb.cancelOnCastSpell = true;
@ -64,22 +70,29 @@ public class dbSkillReqHandler extends dbHandlerBase {
pb.cancelOnTakeDamage = true; pb.cancelOnTakeDamage = true;
break; break;
} }
} else {
Logger.error("null power for Grief " + IDString);
}
} }
rs.close(); } catch (SQLException e) {
} catch (Exception e) { Logger.error(e);
Logger.error(e.toString());
} finally {
ps.release();
} }
} }
public ArrayList<SkillReq> GET_REQS_FOR_RUNE(final int objectUUID) { public ArrayList<SkillReq> GET_REQS_FOR_RUNE(final int objectUUID) {
prepareCallable("SELECT * FROM `static_skill_skillreq` WHERE `runeID`=?");
setInt(1, objectUUID); ArrayList<SkillReq> skillReqsList = new ArrayList<>();
return getObjectList();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillreq` WHERE `runeID`=?")) {
preparedStatement.setInt(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
skillReqsList = getObjectsFromRs(rs, 5);
} catch (SQLException e) {
Logger.error(e);
}
return skillReqsList;
} }
} }

Loading…
Cancel
Save