From c2633d0d9f8d742bab089dd998d82411d864f2f1 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 20 Aug 2024 19:14:50 -0500 Subject: [PATCH] Usage of EffectsParser --- src/engine/gameManager/ConfigManager.java | 6 ++-- src/engine/gameManager/PowersManager.java | 30 +++++++++++------ src/engine/powers/EffectsBase.java | 39 ++++++++++++++++++++--- src/engine/wpak/EffectsParser.java | 5 +++ src/engine/wpak/data/EffectEntry.java | 5 +++ 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index eca6007a..409d48d4 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -170,9 +170,9 @@ public enum ConfigManager { Logger.info("Loading WPAK data"); - EffectsParser.parseWpakFile(); - PowersParser.parseWpakFile(); - PowerActionParser.parseWpakFile(); + //EffectsParser.parseWpakFile(); + //PowersParser.parseWpakFile(); + //PowerActionParser.parseWpakFile(); return true; } diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index e34e86ac..a98dfc60 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -31,6 +31,10 @@ import engine.objects.*; import engine.powers.*; import engine.powers.poweractions.AbstractPowerAction; 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 java.util.ArrayList; @@ -112,23 +116,29 @@ public enum PowersManager { return powerEntries; } - // This pre-loads all powers and effects - public static void InitializePowers() { - + public static void InitializeEffects(){ // Add EffectsBase - ArrayList ebList = dbEffectsBaseHandler.getAllEffectsBase(); - - for (EffectsBase eb : ebList) { - PowersManager.effectsBaseByToken.put(eb.getToken(), eb); - PowersManager.effectsBaseByIDString.put(eb.getIDString(), eb); + ArrayList effectList = new ArrayList<>(); + 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 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 - dbEffectsBaseHandler.cacheAllEffectModifiers(); + InitializeEffects(); // Add Source Types to Effects dbPowerHandler.addAllSourceTypes(); diff --git a/src/engine/powers/EffectsBase.java b/src/engine/powers/EffectsBase.java index cf1f1e26..ed1f3ce7 100644 --- a/src/engine/powers/EffectsBase.java +++ b/src/engine/powers/EffectsBase.java @@ -30,6 +30,8 @@ import engine.objects.Effect; import engine.objects.PlayerCharacter; import engine.powers.effectmodifiers.AbstractEffectModifier; import engine.server.MBServerStatics; +import engine.util.Hasher; +import engine.wpak.data.EffectEntry; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -62,7 +64,7 @@ public class EffectsBase { // flags private boolean isItemEffect; private boolean isSpireEffect; - private boolean ignoreMod; + private boolean ignoreNoMod; private boolean dontSave; private boolean cancelOnAttack = 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) { UUID = NewID++; @@ -102,7 +131,7 @@ public class EffectsBase { int flags = 0; this.isItemEffect = ((flags & 1) != 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; if (this.IDString.startsWith("PRE-")) @@ -117,7 +146,7 @@ public class EffectsBase { this.amountRamp = copyEffect.amountRamp; this.isItemEffect = copyEffect.isItemEffect; this.isSpireEffect = copyEffect.isSpireEffect; - this.ignoreMod = copyEffect.ignoreMod; + this.ignoreNoMod = copyEffect.ignoreNoMod; this.dontSave = copyEffect.dontSave; this.cancelOnAttack = copyEffect.cancelOnAttack; this.cancelOnAttackSwing = copyEffect.cancelOnAttackSwing; @@ -163,7 +192,7 @@ public class EffectsBase { int flags = rs.getInt("flags"); this.isItemEffect = ((flags & 1) != 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; if (this.IDString.startsWith("PRE-")) @@ -351,7 +380,7 @@ public class EffectsBase { } public boolean ignoreMod() { - return this.ignoreMod; + return this.ignoreNoMod; } public boolean dontSave() { diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 7a0a51c5..4d633ab6 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -61,6 +61,11 @@ public class EffectsParser { EffectEntry effectEntry = new EffectEntry(); // 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.trim(); diff --git a/src/engine/wpak/data/EffectEntry.java b/src/engine/wpak/data/EffectEntry.java index 053d5f90..ac027f23 100644 --- a/src/engine/wpak/data/EffectEntry.java +++ b/src/engine/wpak/data/EffectEntry.java @@ -19,4 +19,9 @@ public class EffectEntry { public HashSet sources = new HashSet<>(); public ArrayList mods = new ArrayList<>(); public HashMap conditions = new HashMap<>(); + + public boolean isItemEffect; + public boolean isSpireEffect; + public boolean ignoreNoMod; + public boolean dontSave; }