Browse Source

Usage of EffectsParser

feature-config-parsing2
FatBoy-DOTC 3 months ago
parent
commit
c2633d0d9f
  1. 6
      src/engine/gameManager/ConfigManager.java
  2. 30
      src/engine/gameManager/PowersManager.java
  3. 39
      src/engine/powers/EffectsBase.java
  4. 5
      src/engine/wpak/EffectsParser.java
  5. 5
      src/engine/wpak/data/EffectEntry.java

6
src/engine/gameManager/ConfigManager.java

@ -170,9 +170,9 @@ public enum ConfigManager {
Logger.info("Loading WPAK data"); Logger.info("Loading WPAK data");
EffectsParser.parseWpakFile(); //EffectsParser.parseWpakFile();
PowersParser.parseWpakFile(); //PowersParser.parseWpakFile();
PowerActionParser.parseWpakFile(); //PowerActionParser.parseWpakFile();
return true; return true;
} }

30
src/engine/gameManager/PowersManager.java

@ -31,6 +31,10 @@ import engine.objects.*;
import engine.powers.*; import engine.powers.*;
import engine.powers.poweractions.AbstractPowerAction; import engine.powers.poweractions.AbstractPowerAction;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.wpak.EffectsParser;
import engine.wpak.PowerActionParser;
import engine.wpak.PowersParser;
import engine.wpak.data.EffectEntry;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -112,23 +116,29 @@ public enum PowersManager {
return powerEntries; return powerEntries;
} }
// This pre-loads all powers and effects public static void InitializeEffects(){
public static void InitializePowers() {
// Add EffectsBase // Add EffectsBase
ArrayList<EffectsBase> ebList = dbEffectsBaseHandler.getAllEffectsBase(); ArrayList<EffectsBase> effectList = new ArrayList<>();
for (EffectsBase eb : ebList) {
PowersManager.effectsBaseByToken.put(eb.getToken(), eb);
PowersManager.effectsBaseByIDString.put(eb.getIDString(), eb);
for (EffectEntry entry : EffectsParser.effect_data.values()) {
EffectsBase effectBase = new EffectsBase(entry);
effectList.add(effectBase);
PowersManager.effectsBaseByToken.put(effectBase.getToken(), effectBase);
PowersManager.effectsBaseByIDString.put(effectBase.getIDString(), effectBase);
} }
// Add Fail Conditions // Add Fail Conditions
EffectsBase.getFailConditions(PowersManager.effectsBaseByIDString); EffectsBase.getFailConditions(PowersManager.effectsBaseByIDString);
}
// This pre-loads all powers and effects
public static void InitializePowers() {
EffectsParser.parseWpakFile();
PowersParser.parseWpakFile();
PowerActionParser.parseWpakFile();
// Add Modifiers to Effects InitializeEffects();
dbEffectsBaseHandler.cacheAllEffectModifiers();
// Add Source Types to Effects // Add Source Types to Effects
dbPowerHandler.addAllSourceTypes(); dbPowerHandler.addAllSourceTypes();

39
src/engine/powers/EffectsBase.java

@ -30,6 +30,8 @@ import engine.objects.Effect;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.util.Hasher;
import engine.wpak.data.EffectEntry;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -62,7 +64,7 @@ public class EffectsBase {
// flags // flags
private boolean isItemEffect; private boolean isItemEffect;
private boolean isSpireEffect; private boolean isSpireEffect;
private boolean ignoreMod; private boolean ignoreNoMod;
private boolean dontSave; private boolean dontSave;
private boolean cancelOnAttack = false; private boolean cancelOnAttack = false;
private boolean cancelOnAttackSwing = false; private boolean cancelOnAttackSwing = false;
@ -91,6 +93,33 @@ public class EffectsBase {
} }
//EffectEntry constructor
public EffectsBase(EffectEntry entry) {
this.IDString = entry.effect_id;
this.name = entry.effect_name;
this.token = Hasher.SBStringHash(entry.effect_name);
//override tokens for some effects like Safemode that use the Action Token instead of the effect Token,
switch (this.IDString) {
case "INVIS-D":
this.token = -1661751254;
break;
case "SafeMode":
this.token = -1661750486;
break;
}
this.isItemEffect = entry.isItemEffect;
this.isSpireEffect = entry.isSpireEffect;
this.ignoreNoMod = entry.ignoreNoMod;
this.dontSave = entry.dontSave;
if (this.IDString.startsWith("PRE-"))
this.isPrefix = true;
else if (this.IDString.startsWith("SUF-"))
this.isSuffix = true;
}
public EffectsBase(EffectsBase copyEffect, int newToken, String IDString) { public EffectsBase(EffectsBase copyEffect, int newToken, String IDString) {
UUID = NewID++; UUID = NewID++;
@ -102,7 +131,7 @@ public class EffectsBase {
int flags = 0; int flags = 0;
this.isItemEffect = ((flags & 1) != 0) ? true : false; this.isItemEffect = ((flags & 1) != 0) ? true : false;
this.isSpireEffect = ((flags & 2) != 0) ? true : false; this.isSpireEffect = ((flags & 2) != 0) ? true : false;
this.ignoreMod = ((flags & 4) != 0) ? true : false; this.ignoreNoMod = ((flags & 4) != 0) ? true : false;
this.dontSave = ((flags & 8) != 0) ? true : false; this.dontSave = ((flags & 8) != 0) ? true : false;
if (this.IDString.startsWith("PRE-")) if (this.IDString.startsWith("PRE-"))
@ -117,7 +146,7 @@ public class EffectsBase {
this.amountRamp = copyEffect.amountRamp; this.amountRamp = copyEffect.amountRamp;
this.isItemEffect = copyEffect.isItemEffect; this.isItemEffect = copyEffect.isItemEffect;
this.isSpireEffect = copyEffect.isSpireEffect; this.isSpireEffect = copyEffect.isSpireEffect;
this.ignoreMod = copyEffect.ignoreMod; this.ignoreNoMod = copyEffect.ignoreNoMod;
this.dontSave = copyEffect.dontSave; this.dontSave = copyEffect.dontSave;
this.cancelOnAttack = copyEffect.cancelOnAttack; this.cancelOnAttack = copyEffect.cancelOnAttack;
this.cancelOnAttackSwing = copyEffect.cancelOnAttackSwing; this.cancelOnAttackSwing = copyEffect.cancelOnAttackSwing;
@ -163,7 +192,7 @@ public class EffectsBase {
int flags = rs.getInt("flags"); int flags = rs.getInt("flags");
this.isItemEffect = ((flags & 1) != 0) ? true : false; this.isItemEffect = ((flags & 1) != 0) ? true : false;
this.isSpireEffect = ((flags & 2) != 0) ? true : false; this.isSpireEffect = ((flags & 2) != 0) ? true : false;
this.ignoreMod = ((flags & 4) != 0) ? true : false; this.ignoreNoMod = ((flags & 4) != 0) ? true : false;
this.dontSave = ((flags & 8) != 0) ? true : false; this.dontSave = ((flags & 8) != 0) ? true : false;
if (this.IDString.startsWith("PRE-")) if (this.IDString.startsWith("PRE-"))
@ -351,7 +380,7 @@ public class EffectsBase {
} }
public boolean ignoreMod() { public boolean ignoreMod() {
return this.ignoreMod; return this.ignoreNoMod;
} }
public boolean dontSave() { public boolean dontSave() {

5
src/engine/wpak/EffectsParser.java

@ -61,6 +61,11 @@ public class EffectsParser {
EffectEntry effectEntry = new EffectEntry(); EffectEntry effectEntry = new EffectEntry();
// Remove all lines that contain a # and leading/trailing blank lines // Remove all lines that contain a # and leading/trailing blank lines
effectEntry.isItemEffect = effectData.contains("IsItemEffect");
effectEntry.isSpireEffect = effectData.contains("IsSpireEffect");
effectEntry.ignoreNoMod = effectData.contains("IgnoreNoMod");
effectEntry.dontSave = effectData.contains("DontSave");
effectData = effectData.replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""); effectData = effectData.replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", "");
effectData = effectData.trim(); effectData = effectData.trim();

5
src/engine/wpak/data/EffectEntry.java

@ -19,4 +19,9 @@ public class EffectEntry {
public HashSet<String> sources = new HashSet<>(); public HashSet<String> sources = new HashSet<>();
public ArrayList<EffectModifier> mods = new ArrayList<>(); public ArrayList<EffectModifier> mods = new ArrayList<>();
public HashMap<String, Float> conditions = new HashMap<>(); public HashMap<String, Float> conditions = new HashMap<>();
public boolean isItemEffect;
public boolean isSpireEffect;
public boolean ignoreNoMod;
public boolean dontSave;
} }

Loading…
Cancel
Save