Browse Source

Bonus code removed and replaced with a db call actually used.

master
MagicBot 2 years ago
parent
commit
55d9a3516c
  1. 186
      src/engine/db/handlers/dbEffectsBaseHandler.java
  2. 3
      src/engine/gameManager/PowersManager.java
  3. 76
      src/engine/powers/EffectsBase.java

186
src/engine/db/handlers/dbEffectsBaseHandler.java

@ -9,173 +9,37 @@ @@ -9,173 +9,37 @@
package engine.db.handlers;
public class dbEffectsBaseHandler extends dbHandlerBase {
public dbEffectsBaseHandler() {
}
public boolean CreateEffectBase(int token, String IDString,String name,int flags){
prepareCallable("INSERT INTO `wpak_static_power_effectbase` (`token`,`IDString`,`name`,`flags`) VALUES (?,?,?,?)");
setInt(1,token);
setString(2,IDString);
setString(3,name);
setInt(4,flags);
return (executeUpdate() > 0);
}
public boolean CreateEffectBaseRAW(String IDString,String type,String detail){
prepareCallable("INSERT INTO `wpak_effect_effectbase_raw` (`token`,`IDString`,`name`,`flags`) VALUES (?,?,?,?)");
setString(1,IDString);
setString(2,type);
setString(3,detail);
return (executeUpdate() > 0);
}
public boolean CreateEffectSource(String IDString,String source){
prepareCallable("INSERT INTO `wpak_static_power_sourcetype` (`IDString`,`source`) VALUES (?,?)");
setString(1,IDString);
setString(2,source);
return (executeUpdate() > 0);
}
public boolean CreateEffectSourceRAW(String IDString,String type,String detail){
prepareCallable("INSERT INTO `wpak_effect_source_raw` (`effectID`,`type`, `text`) VALUES (?,?,?)");
setString(1,IDString);
setString(2,type);
setString(3,detail);
return (executeUpdate() > 0);
}
public boolean CreateEffectCondition(String IDString,String powerOrEffect,String type,float amount,float ramp,byte useAddFormula,String damageType1,String damageType2,String damageType3){
prepareCallable("INSERT INTO `wpak_static_power_failcondition` (`IDString`,`powerOrEffect`,`type`,`amount`,`ramp`,`useAddFormula`,`damageType1`,`damageType2`,`damageType3`) VALUES (?,?,?,?,?,?,?,?,?)");
setString(1,IDString);
setString(2,powerOrEffect);
setString(3,type);
setFloat(4,amount);
setFloat(5,ramp);
setByte(6,useAddFormula);
setString(7,damageType1);
setString(8,damageType2);
setString(9,damageType3);
return (executeUpdate() > 0);
}
public boolean CreateEffectConditionRAW(String IDString,String type,String detail){
prepareCallable("INSERT INTO `wpak_effect_condition_raw` (`effectID`,`type`, `text`) VALUES (?,?,?)");
setString(1,IDString);
setString(2,type);
setString(3,detail);
return (executeUpdate() > 0);
}
public boolean CreateEffectMod(String IDString,String modType,float minMod,float maxMod,float percentMod,float ramp,byte useRampAdd,String type,String string1,String string2){
prepareCallable("INSERT INTO `wpak_static_power_effectmod` (`IDString`,`modType`,`minMod`,`maxMod`,`percentMod`,`ramp`,`useRampAdd`,`type`,`string1`,`string2`) VALUES (?,?,?,?,?,?,?,?,?,?)");
setString(1, IDString);
setString(2, modType);
setFloat(3, minMod);
setFloat(4, maxMod);
setFloat(5, percentMod);
setFloat(6, ramp);
setByte(7, useRampAdd);
setString(8, type);
setString(9, string1);
setString(10, string2);
return (executeUpdate() > 0);
}
public boolean CreateEffectModRAW(String IDString,String type,String detail){
prepareCallable("INSERT INTO `wpak_effect_mod_raw` (`effectID`,`type`, `text`) VALUES (?,?,?)");
setString(1,IDString);
setString(2,type);
setString(3,detail);
return (executeUpdate() > 0);
}
public boolean CreatePowerPowerAction(String IDString,String type,String effectID,String effectID2,String deferredPowerID,float levelCap,float levelCapRamp,String damageType,int numIterations,String effectSourceToRemove,String trackFilter,int maxTrack,int mobID,int mobLevel,int simpleDamage,String transferFromType,String transferToType,float transferAmount,float transferRamp,float transferEfficiency,float transferEfficiencyRamp,int flags){
prepareCallable("INSERT INTO `wpak_static_power_poweraction` (`IDString`,`type`,`effectID`,`effectID2`,`deferredPowerID`,`levelCap`,`levelCapRamp`,`damageType`,`numIterations`,`effectSourceToRemove`,`trackFilter`,`maxTrack`,`mobID`,`mobLevel`,`simpleDamage`,`transferFromType`,`transferToType`,`transferAmount`,`transferRamp`,`transferEfficiency`,`transferEfficiencyRamp`,`flags`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
setString(1,IDString);
setString(2,type);
setString(3,effectID);
setString(4,effectID2);
setString(5,deferredPowerID);
setFloat(6,levelCap);
setFloat(7,levelCapRamp);
setString(8,damageType);
setInt(9,numIterations);
setString(10,effectSourceToRemove);
setString(11,trackFilter);
setInt(12,maxTrack);
setInt(13,mobID);
setInt(14,mobLevel);
setInt(15,simpleDamage);
setString(16,transferFromType);
setString(17,transferToType);
setFloat(18,transferAmount);
setFloat(19,transferRamp);
setFloat(20,transferEfficiency);
setFloat(21,transferEfficiencyRamp);
setInt(22,flags);
return (executeUpdate() > 0);
}
public boolean CreatePowerPowerActionRAW(String IDString,String type,String detail){
prepareCallable("INSERT INTO `wpak_effect_poweraction_raw` (`effectID`,`type`, `text`) VALUES (?,?,?)");
import engine.objects.PreparedStatementShared;
import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger;
setString(1,IDString);
setString(2,type);
setString(3,detail);
import java.sql.ResultSet;
import java.util.ArrayList;
return (executeUpdate() > 0);
}
public boolean ClearAllEffectBase(){
prepareCallable("DELETE from `wpak_static_power_effectbase`");
executeUpdate();
prepareCallable(" DELETE from `wpak_static_power_sourcetype` ");
executeUpdate();
prepareCallable(" DELETE from `wpak_static_power_failcondition` WHERE `powerOrEffect` = ?");
setString(1,"Effect");
executeUpdate();
prepareCallable(" DELETE from `wpak_static_power_effectmod` ");
executeUpdate();
public class dbEffectsBaseHandler extends dbHandlerBase {
return true;
public dbEffectsBaseHandler() {
}
public boolean ResetIncrement(){
prepareCallable("ALTER TABLE `wpak_static_power_effectbase` AUTO_INCREMENT = 1");
executeUpdate();
prepareCallable("ALTER TABLE `wpak_static_power_sourcetype` AUTO_INCREMENT = 1");
executeUpdate();
prepareCallable("ALTER TABLE `wpak_static_power_failcondition` AUTO_INCREMENT = 1");
executeUpdate();
prepareCallable("ALTER TABLE `wpak_static_power_effectmod` AUTO_INCREMENT = 1");
executeUpdate();
return true;
public static ArrayList<EffectsBase> getAllEffectsBase() {
PreparedStatementShared ps = null;
ArrayList<EffectsBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
EffectsBase toAdd = new EffectsBase(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
}
//testHash(out);
return out;
}
}

3
src/engine/gameManager/PowersManager.java

@ -11,6 +11,7 @@ package engine.gameManager; @@ -11,6 +11,7 @@ package engine.gameManager;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid;
import engine.db.handlers.dbEffectsBaseHandler;
import engine.job.AbstractJob;
import engine.job.AbstractScheduleJob;
import engine.job.JobContainer;
@ -111,7 +112,7 @@ public enum PowersManager { @@ -111,7 +112,7 @@ public enum PowersManager {
public static void InitializePowers() {
// Add EffectsBase
ArrayList<EffectsBase> ebList = EffectsBase.getAllEffectsBase();
ArrayList<EffectsBase> ebList = dbEffectsBaseHandler.getAllEffectsBase();
for (EffectsBase eb : ebList) {
PowersManager.effectsBaseByToken.put(eb.getToken(), eb);

76
src/engine/powers/EffectsBase.java

@ -183,82 +183,6 @@ public class EffectsBase { @@ -183,82 +183,6 @@ public class EffectsBase {
// getFailConditions();
}
public static ArrayList<EffectsBase> getAllEffectsBase() {
PreparedStatementShared ps = null;
ArrayList<EffectsBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
EffectsBase toAdd = new EffectsBase(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
}
//testHash(out);
return out;
}
public static ArrayList<EffectsBase> getAllLiveEffectsBase() {
PreparedStatementShared ps = null;
ArrayList<EffectsBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_effectbase_24 ORDER BY `IDString` DESC");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
EffectsBase toAdd = new EffectsBase(rs);
out.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
}
//testHash(out);
return out;
}
//private static void testHash(ArrayList<EffectsBase> effs) {
// int valid = 0, invalid = 0;
// for (EffectsBase eff : effs) {
// String ids = eff.getIDString();
// int tok = eff.getToken();
// if (ids.length() != 8 || ids.startsWith("PRE-") || ids.startsWith("SUF-") || ids.endsWith("X") || !ids.substring(3,4).equals("-"))
// continue;
//
//// if ((tok > 1 || tok < 0) && ids.length() == 8) {
// int out = Hash(ids);
// if (out != tok) {
// System.out.println(ids + ": " + Integer.toHexString(out) + "(" + out + ")");
// invalid++;
// } else
// valid++;
//// }
// }
// System.out.println("valid: " + valid + ", invalid: " + invalid);
//}
//private static int Hash(String IDString) {
// char[] val = IDString.toCharArray();
// int out = 360;
// out ^= val[0];
// out ^= (val[1] << 5);
// out ^= (val[2] << 10);
// out ^= (val[4] << 23);
// out ^= (val[5] << 19);
// out ^= (val[6] << 15);
// out ^= (val[7] << 26);
// out ^= (val[7] >> 6);
// out ^= 17;
// return out;
//}
public static void getFailConditions(HashMap<String, EffectsBase> effects) {
PreparedStatementShared ps = null;
try {

Loading…
Cancel
Save