Browse Source

Db methods moved to db system.

master
MagicBot 2 years ago
parent
commit
962649c0f2
  1. 62
      src/engine/db/handlers/dbSkillReqHandler.java
  2. 7
      src/engine/gameManager/PowersManager.java
  3. 53
      src/engine/powers/PowersBase.java

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

@ -9,9 +9,14 @@ @@ -9,9 +9,14 @@
package engine.db.handlers;
import engine.objects.PreparedStatementShared;
import engine.objects.SkillReq;
import engine.powers.PowersBase;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
public class dbSkillReqHandler extends dbHandlerBase {
@ -20,16 +25,61 @@ public class dbSkillReqHandler extends dbHandlerBase { @@ -20,16 +25,61 @@ public class dbSkillReqHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public static ArrayList<PowersBase> getAllPowersBase() {
PreparedStatementShared ps = null;
ArrayList<PowersBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_powerbase");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
PowersBase toAdd = new PowersBase(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e.toString());
} finally {
ps.release();
}
return out;
}
public static void getFailConditions(HashMap<String, PowersBase> powers) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'");
ResultSet rs = ps.executeQuery();
String type, IDString;
PowersBase pb;
while (rs.next()) {
type = rs.getString("type");
IDString = rs.getString("IDString");
pb = powers.get(IDString);
if (pb != null) {
switch (type) {
case "CastSpell":
pb.cancelOnCastSpell = true;
break;
case "TakeDamage":
pb.cancelOnTakeDamage = true;
break;
}
} else {
Logger.error("null power for Grief " + IDString);
}
}
rs.close();
} catch (Exception e) {
Logger.error(e.toString());
} finally {
ps.release();
}
}
public ArrayList<SkillReq> GET_REQS_FOR_RUNE(final int objectUUID) {
prepareCallable("SELECT * FROM `static_skill_skillreq` WHERE `runeID`=?");
setInt(1, objectUUID);
return getObjectList();
}
public SkillReq GET_REQS_BY_SKILLID(int skillID) {
prepareCallable("SELECT * FROM `static_skill_skillreq` WHERE `skillID` = ?");
setInt(1,skillID);
int objectUUID = (int) getUUID();
return (SkillReq) this.getObjectSingle(objectUUID);
}
}

7
src/engine/gameManager/PowersManager.java

@ -12,6 +12,7 @@ import engine.Enum.*; @@ -12,6 +12,7 @@ import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid;
import engine.db.handlers.dbEffectsBaseHandler;
import engine.db.handlers.dbSkillReqHandler;
import engine.job.AbstractJob;
import engine.job.AbstractScheduleJob;
import engine.job.JobContainer;
@ -100,7 +101,7 @@ public enum PowersManager { @@ -100,7 +101,7 @@ public enum PowersManager {
public static void InitializeLoginPowers() {
// get all PowersBase
ArrayList<PowersBase> pbList = PowersBase.getAllPowersBase();
ArrayList<PowersBase> pbList = dbSkillReqHandler.getAllPowersBase();
for (PowersBase pb : pbList) {
if (pb.getToken() != 0)
@ -137,7 +138,7 @@ public enum PowersManager { @@ -137,7 +138,7 @@ public enum PowersManager {
// AbstractPowerAction.loadValidItemFlags(PowersManager.powerActionsByIDString);
// get all PowersBase
ArrayList<PowersBase> pbList = PowersBase.getAllPowersBase();
ArrayList<PowersBase> pbList = dbSkillReqHandler.getAllPowersBase();
for (PowersBase pb : pbList) {
if (pb.getToken() != 0) {
PowersManager.powersBaseByIDString.put(pb.getIDString(), pb);
@ -148,7 +149,7 @@ public enum PowersManager { @@ -148,7 +149,7 @@ public enum PowersManager {
// Add Power Prereqs
PowerPrereq.getAllPowerPrereqs(PowersManager.powersBaseByIDString);
// Add Fail Conditions
PowersBase.getFailConditions(PowersManager.powersBaseByIDString);
dbSkillReqHandler.getFailConditions(PowersManager.powersBaseByIDString);
// Add Actions Base
ActionsBase.getActionsBase(PowersManager.powersBaseByIDString,
PowersManager.powerActionsByIDString);

53
src/engine/powers/PowersBase.java

@ -11,13 +11,11 @@ package engine.powers; @@ -11,13 +11,11 @@ package engine.powers;
import engine.Enum.PowerCategoryType;
import engine.Enum.PowerTargetType;
import engine.objects.PreparedStatementShared;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
public class PowersBase {
@ -340,57 +338,6 @@ public class PowersBase { @@ -340,57 +338,6 @@ public class PowersBase {
this.monsterTypeRestrictions.add(ct);
}
public static ArrayList<PowersBase> getAllPowersBase() {
PreparedStatementShared ps = null;
ArrayList<PowersBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_powerbase");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
PowersBase toAdd = new PowersBase(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error( e.toString());
} finally {
ps.release();
}
return out;
}
public static void getFailConditions(HashMap<String, PowersBase> powers) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'");
ResultSet rs = ps.executeQuery();
String type, IDString; PowersBase pb;
while (rs.next()) {
type = rs.getString("type");
IDString = rs.getString("IDString");
pb = powers.get(IDString);
if (pb != null) {
switch (type) {
case "CastSpell":
pb.cancelOnCastSpell = true;
break;
case "TakeDamage":
pb.cancelOnTakeDamage = true;
break;
}
}else{
Logger.error("null power for Grief " + IDString);
}
}
rs.close();
} catch (Exception e) {
Logger.error( e.toString());
} finally {
ps.release();
}
}
public String getName() {
return this.name;

Loading…
Cancel
Save