diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index da6fb5c4..c0805c4e 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -27,12 +27,14 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.objects.*; import engine.powers.*; -import engine.powers.poweractions.AbstractPowerAction; +import engine.powers.poweractions.*; import engine.server.MBServerStatics; import engine.wpak.EffectsParser; import engine.wpak.PowerActionParser; import engine.wpak.PowersParser; +import engine.wpak.data.ActionEntry; import engine.wpak.data.Effect; +import engine.wpak.data.PowerAction; import org.pmw.tinylog.Logger; import java.sql.SQLException; @@ -127,6 +129,124 @@ public enum PowersManager { } + public static void InitializePowerActions(){ + // Add PowerActions + //AbstractPowerAction.getAllPowerActions(PowersManager.powerActionsByIDString, PowersManager.powerActionsByID, PowersManager.effectsBaseByIDString); + + HashMap effects = PowersManager.effectsBaseByIDString; + for (PowerAction rs : PowerActionParser.power_actions) { + AbstractPowerAction apa; + String type = rs.action_type; + String IDString = rs.action_id; + int token = DbManager.hasher.SBStringHash(IDString); + //cache token, used for applying effects. + PowersManager.ActionTokenByIDString.put(IDString, token); + apa = null; + switch (type) { + default: + Logger.error("valid type not found for poweraction of ID" + IDString); + break; + case "ApplyEffect": + apa = new ApplyEffectPowerAction(rs, effects); + break; + case "ApplyEffects": + apa = new ApplyEffectsPowerAction(rs, effects); + break; + case "DeferredPower": + apa = new DeferredPowerPowerAction(rs, effects); + break; + case "DamageOverTime": + apa = new DamageOverTimePowerAction(rs, effects); + break; + case "Peek": + apa = new PeekPowerAction(rs); + break; + case "Charm": + apa = new CharmPowerAction(rs); + break; + case "Fear": + apa = new FearPowerAction(rs); + break; + case "Confusion": + apa = new ConfusionPowerAction(rs); + break; + case "RemoveEffect": + apa = new RemoveEffectPowerAction(rs); + break; + case "Track": + apa = new TrackPowerAction(rs, effects); + break; + case "DirectDamage": + apa = new DirectDamagePowerAction(rs, effects); + break; + case "Transform": + apa = new TransformPowerAction(rs, effects); + break; + case "CreateMob": + apa = new CreateMobPowerAction(rs); + break; + case "Invis": + apa = new InvisPowerAction(rs, effects); + break; + case "ClearNearbyAggro": + apa = new ClearNearbyAggroPowerAction(rs); + break; + case "MobRecall": + apa = new MobRecallPowerAction(rs); + break; + case "SetItemFlag": + apa = new SetItemFlagPowerAction(rs); + break; + case "SimpleDamage": + apa = new SimpleDamagePowerAction(rs); + break; + case "TransferStatOT": + apa = new TransferStatOTPowerAction(rs, effects); + break; + case "TransferStat": + apa = new TransferStatPowerAction(rs, effects); + break; + case "Teleport": + apa = new TeleportPowerAction(rs); + break; + case "TreeChoke": + apa = new TreeChokePowerAction(rs); + break; + case "Block": + apa = new BlockPowerAction(rs); + break; + case "Resurrect": + apa = new ResurrectPowerAction(rs); + break; + case "ClearAggro": + apa = new ClearAggroPowerAction(rs); + break; + case "ClaimMine": + apa = new ClaimMinePowerAction(rs); + break; + case "Recall": + apa = new RecallPowerAction(rs); + break; + case "SpireDisable": + apa = new SpireDisablePowerAction(rs); + break; + case "Steal": + apa = new StealPowerAction(rs); + break; + case "Summon": + apa = new SummonPowerAction(rs); + break; + case "RunegateTeleport": + apa = new RunegateTeleportPowerAction(rs); + break; + case "OpenGate": + apa = new OpenGatePowerAction(rs); + break; + } + PowersManager.powerActionsByIDString.put(IDString, apa); + } + } + // This pre-loads all powers and effects public static void InitializePowers() { @@ -137,11 +257,8 @@ public enum PowersManager { //Initialize Effects Data InitializeEffects(); - // Add PowerActions - AbstractPowerAction.getAllPowerActions(PowersManager.powerActionsByIDString, PowersManager.powerActionsByID, PowersManager.effectsBaseByIDString); - - // Load valid Item Flags - // AbstractPowerAction.loadValidItemFlags(PowersManager.powerActionsByIDString); + //Initialize Power Actions + InitializePowerActions(); // get all PowersBase ArrayList pbList = dbSkillReqHandler.getAllPowersBase(); diff --git a/src/engine/powers/poweractions/AbstractPowerAction.java b/src/engine/powers/poweractions/AbstractPowerAction.java index 26197daa..915ed25b 100644 --- a/src/engine/powers/poweractions/AbstractPowerAction.java +++ b/src/engine/powers/poweractions/AbstractPowerAction.java @@ -18,6 +18,7 @@ import engine.objects.Item; import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -46,13 +47,12 @@ public abstract class AbstractPowerAction { /** * ResultSet Constructor */ - public AbstractPowerAction(ResultSet rs) throws SQLException { + public AbstractPowerAction(PowerAction rs){ - this.UUID = rs.getInt("ID"); - this.IDString = rs.getString("IDString"); - this.type = rs.getString("type"); - int flags = rs.getInt("flags"); - this.isAggressive = ((flags & 128) != 0) ? true : false; + this.IDString = rs.action_id; + this.type = rs.action_type; + int flags = rs.itemFlag.ordinal(); + this.isAggressive = rs.isAggressive; } public AbstractPowerAction(int uUID, String iDString, String type, boolean isAggressive, @@ -64,139 +64,6 @@ public abstract class AbstractPowerAction { this.isAggressive = false; } - public static void getAllPowerActions(HashMap powerActions, HashMap powerActionsByID, HashMap effects) { - - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_poweraction")) { - - ResultSet rs = preparedStatement.executeQuery(); - String IDString, type; - - while (rs.next()) { - AbstractPowerAction apa; - type = rs.getString("type"); - IDString = rs.getString("IDString"); - int token = DbManager.hasher.SBStringHash(IDString); - //cache token, used for applying effects. - PowersManager.ActionTokenByIDString.put(IDString, token); - apa = null; - switch (type) { - default: - Logger.error("valid type not found for poweraction of ID" + rs.getInt("ID")); - break; - case "ApplyEffect": - apa = new ApplyEffectPowerAction(rs, effects); - break; - case "ApplyEffects": - apa = new ApplyEffectsPowerAction(rs, effects); - break; - case "DeferredPower": - apa = new DeferredPowerPowerAction(rs, effects); - break; - case "DamageOverTime": - apa = new DamageOverTimePowerAction(rs, effects); - break; - case "Peek": - apa = new PeekPowerAction(rs); - break; - case "Charm": - apa = new CharmPowerAction(rs); - break; - case "Fear": - apa = new FearPowerAction(rs); - break; - case "Confusion": - apa = new ConfusionPowerAction(rs); - break; - case "RemoveEffect": - apa = new RemoveEffectPowerAction(rs); - break; - case "Track": - apa = new TrackPowerAction(rs, effects); - break; - case "DirectDamage": - apa = new DirectDamagePowerAction(rs, effects); - break; - case "Transform": - apa = new TransformPowerAction(rs, effects); - break; - case "CreateMob": - apa = new CreateMobPowerAction(rs); - break; - case "Invis": - apa = new InvisPowerAction(rs, effects); - break; - case "ClearNearbyAggro": - apa = new ClearNearbyAggroPowerAction(rs); - break; - case "MobRecall": - apa = new MobRecallPowerAction(rs); - break; - case "SetItemFlag": - apa = new SetItemFlagPowerAction(rs); - break; - case "SimpleDamage": - apa = new SimpleDamagePowerAction(rs); - break; - case "TransferStatOT": - apa = new TransferStatOTPowerAction(rs, effects); - break; - case "TransferStat": - apa = new TransferStatPowerAction(rs, effects); - break; - case "Teleport": - apa = new TeleportPowerAction(rs); - break; - case "TreeChoke": - apa = new TreeChokePowerAction(rs); - break; - case "Block": - apa = new BlockPowerAction(rs); - break; - case "Resurrect": - apa = new ResurrectPowerAction(rs); - break; - case "ClearAggro": - apa = new ClearAggroPowerAction(rs); - break; - case "ClaimMine": - apa = new ClaimMinePowerAction(rs); - break; - case "Recall": - apa = new RecallPowerAction(rs); - break; - case "SpireDisable": - apa = new SpireDisablePowerAction(rs); - break; - case "Steal": - apa = new StealPowerAction(rs); - break; - case "Summon": - apa = new SummonPowerAction(rs); - break; - case "RunegateTeleport": - apa = new RunegateTeleportPowerAction(rs); - break; - case "OpenGate": - apa = new OpenGatePowerAction(rs); - break; - } - powerActions.put(IDString, apa); - powerActionsByID.put(apa.UUID, apa); - apa.validItemFlags = 0; - } - rs.close(); - } catch (Exception e) { - Logger.error(e.toString()); - } - - //Add OpenGatePowerAction - AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0); - powerActions.put("OPENGATE", openGateAction); - powerActionsByID.put(openGateAction.UUID, openGateAction); - } - public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) { this._startAction(source, awo, targetLoc, numTrains, ab, pb); } diff --git a/src/engine/powers/poweractions/ApplyEffectPowerAction.java b/src/engine/powers/poweractions/ApplyEffectPowerAction.java index c4f61bb2..70b125ff 100644 --- a/src/engine/powers/poweractions/ApplyEffectPowerAction.java +++ b/src/engine/powers/poweractions/ApplyEffectPowerAction.java @@ -25,6 +25,7 @@ import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; import engine.server.MBServerStatics; +import engine.wpak.data.PowerAction; import org.pmw.tinylog.Logger; import java.sql.ResultSet; @@ -38,11 +39,11 @@ public class ApplyEffectPowerAction extends AbstractPowerAction { private String effectParentID; private EffectsBase effectParent; - public ApplyEffectPowerAction(ResultSet rs, HashMap effects) throws SQLException { + public ApplyEffectPowerAction(PowerAction rs, HashMap effects){ super(rs); - this.effectParentID = rs.getString("IDString"); + this.effectParentID = rs.effects.get(0).effect_id; this.effectParent = effects.get(this.effectParentID); - this.effectID = rs.getString("effectID"); + this.effectID = rs.effects.get(0).effect_id; this.effect = effects.get(this.effectID); } diff --git a/src/engine/powers/poweractions/ApplyEffectsPowerAction.java b/src/engine/powers/poweractions/ApplyEffectsPowerAction.java index 2ef45305..d23c8a46 100644 --- a/src/engine/powers/poweractions/ApplyEffectsPowerAction.java +++ b/src/engine/powers/poweractions/ApplyEffectsPowerAction.java @@ -17,6 +17,7 @@ import engine.objects.Item; import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import org.pmw.tinylog.Logger; import java.sql.ResultSet; @@ -32,11 +33,11 @@ public class ApplyEffectsPowerAction extends AbstractPowerAction { private EffectsBase effect2; private EffectsBase effectParent; - public ApplyEffectsPowerAction(ResultSet rs, HashMap effects) throws SQLException { + public ApplyEffectsPowerAction(PowerAction rs, HashMap effects){ super(rs); - this.IDString = rs.getString("IDString"); - this.effectID = rs.getString("effectID"); - this.effectID2 = rs.getString("effectID2"); + this.IDString = rs.action_id; + this.effectID = rs.effects.get(0).effect_id; + this.effectID2 = rs.effects.get(2).effect_id; this.effect = effects.get(this.effectID); this.effect2 = effects.get(this.effectID2); this.effectParent = effects.get(this.IDString); diff --git a/src/engine/powers/poweractions/CharmPowerAction.java b/src/engine/powers/poweractions/CharmPowerAction.java index 93ab7531..e7e5bb88 100644 --- a/src/engine/powers/poweractions/CharmPowerAction.java +++ b/src/engine/powers/poweractions/CharmPowerAction.java @@ -18,6 +18,7 @@ import engine.objects.Mob; import engine.objects.PlayerCharacter; import engine.powers.ActionsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -28,10 +29,10 @@ public class CharmPowerAction extends AbstractPowerAction { private int levelCap; private int levelCapRamp; - public CharmPowerAction(ResultSet rs) throws SQLException { + public CharmPowerAction(PowerAction rs){ super(rs); - this.levelCap = rs.getInt("levelCap"); - this.levelCapRamp = rs.getInt("levelCapRamp"); + this.levelCap = rs.levelCap; + this.levelCapRamp = rs.levelCurve.ordinal(); } @Override diff --git a/src/engine/powers/poweractions/ConfusionPowerAction.java b/src/engine/powers/poweractions/ConfusionPowerAction.java index ca22c8eb..0829ea91 100644 --- a/src/engine/powers/poweractions/ConfusionPowerAction.java +++ b/src/engine/powers/poweractions/ConfusionPowerAction.java @@ -14,6 +14,7 @@ import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; import engine.powers.ActionsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -21,7 +22,7 @@ import java.sql.SQLException; public class ConfusionPowerAction extends AbstractPowerAction { - public ConfusionPowerAction(ResultSet rs) throws SQLException { + public ConfusionPowerAction(PowerAction rs){ super(rs); } diff --git a/src/engine/powers/poweractions/DamageOverTimePowerAction.java b/src/engine/powers/poweractions/DamageOverTimePowerAction.java index 53d060d7..2c90e83f 100644 --- a/src/engine/powers/poweractions/DamageOverTimePowerAction.java +++ b/src/engine/powers/poweractions/DamageOverTimePowerAction.java @@ -16,6 +16,7 @@ import engine.objects.AbstractWorldObject; import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -28,11 +29,11 @@ public class DamageOverTimePowerAction extends AbstractPowerAction { private int numIterations; private EffectsBase effect; - public DamageOverTimePowerAction(ResultSet rs, HashMap effects) throws SQLException { + public DamageOverTimePowerAction(PowerAction rs, HashMap effects){ super(rs); - this.effectID = rs.getString("effectID"); - this.numIterations = rs.getInt("numIterations"); + this.effectID = rs.action_id; + this.numIterations = rs.effects.get(0).cycleDelay; this.effect = effects.get(this.effectID); } diff --git a/src/engine/powers/poweractions/DeferredPowerPowerAction.java b/src/engine/powers/poweractions/DeferredPowerPowerAction.java index 5d575f70..47838251 100644 --- a/src/engine/powers/poweractions/DeferredPowerPowerAction.java +++ b/src/engine/powers/poweractions/DeferredPowerPowerAction.java @@ -18,6 +18,7 @@ import engine.objects.PlayerCharacter; import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -31,11 +32,11 @@ public class DeferredPowerPowerAction extends AbstractPowerAction { private EffectsBase effect; // private EffectsBase deferedPower; - public DeferredPowerPowerAction(ResultSet rs, HashMap effects) throws SQLException { + public DeferredPowerPowerAction(PowerAction rs, HashMap effects){ super(rs); - this.effectID = rs.getString("effectID"); - this.deferedPowerID = rs.getString("deferredPowerID"); + this.effectID = rs.effects.get(0).effect_id; + this.deferedPowerID = rs.action_id; this.effect = effects.get(this.effectID); } diff --git a/src/engine/powers/poweractions/DirectDamagePowerAction.java b/src/engine/powers/poweractions/DirectDamagePowerAction.java index 4c670312..9de92a69 100644 --- a/src/engine/powers/poweractions/DirectDamagePowerAction.java +++ b/src/engine/powers/poweractions/DirectDamagePowerAction.java @@ -17,6 +17,7 @@ import engine.objects.AbstractWorldObject; import engine.powers.ActionsBase; import engine.powers.EffectsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -28,10 +29,10 @@ public class DirectDamagePowerAction extends AbstractPowerAction { private String effectID; private EffectsBase effect; - public DirectDamagePowerAction(ResultSet rs, HashMap effects) throws SQLException { + public DirectDamagePowerAction(PowerAction rs, HashMap effects){ super(rs); - this.effectID = rs.getString("effectID"); + this.effectID = rs.effects.get(0).effect_id; this.effect = effects.get(this.effectID); } diff --git a/src/engine/powers/poweractions/FearPowerAction.java b/src/engine/powers/poweractions/FearPowerAction.java index 254f59ee..10614d22 100644 --- a/src/engine/powers/poweractions/FearPowerAction.java +++ b/src/engine/powers/poweractions/FearPowerAction.java @@ -20,6 +20,7 @@ import engine.objects.Mob; import engine.objects.PlayerCharacter; import engine.powers.ActionsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -29,10 +30,10 @@ public class FearPowerAction extends AbstractPowerAction { private int levelCap; private int levelCapRamp; - public FearPowerAction(ResultSet rs) throws SQLException { + public FearPowerAction(PowerAction rs){ super(rs); - this.levelCap = rs.getInt("levelCap"); - this.levelCapRamp = rs.getInt("levelCapRamp"); + this.levelCap = rs.levelCap; + this.levelCapRamp = rs.levelCurve.ordinal(); } @Override diff --git a/src/engine/powers/poweractions/PeekPowerAction.java b/src/engine/powers/poweractions/PeekPowerAction.java index eef1cf20..326f6e5c 100644 --- a/src/engine/powers/poweractions/PeekPowerAction.java +++ b/src/engine/powers/poweractions/PeekPowerAction.java @@ -18,6 +18,7 @@ import engine.net.client.msg.LootWindowResponseMsg; import engine.objects.*; import engine.powers.ActionsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -26,7 +27,7 @@ import java.util.concurrent.ThreadLocalRandom; public class PeekPowerAction extends AbstractPowerAction { - public PeekPowerAction(ResultSet rs) throws SQLException { + public PeekPowerAction(PowerAction rs){ super(rs); } diff --git a/src/engine/powers/poweractions/RemoveEffectPowerAction.java b/src/engine/powers/poweractions/RemoveEffectPowerAction.java index b52840f8..52758b0c 100644 --- a/src/engine/powers/poweractions/RemoveEffectPowerAction.java +++ b/src/engine/powers/poweractions/RemoveEffectPowerAction.java @@ -15,6 +15,7 @@ import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; import engine.powers.ActionsBase; import engine.powers.PowersBase; +import engine.wpak.data.PowerAction; import java.sql.ResultSet; import java.sql.SQLException; @@ -26,12 +27,11 @@ public class RemoveEffectPowerAction extends AbstractPowerAction { public EffectSourceType sourceType; private boolean removeAll; - public RemoveEffectPowerAction(ResultSet rs) throws SQLException { + public RemoveEffectPowerAction(PowerAction rs){ super(rs); - String effectTypeToRemove = rs.getString("effectSourceToRemove").replace("-", "").trim(); + String effectTypeToRemove = rs.damageType.name(); sourceType = EffectSourceType.GetEffectSourceType(effectTypeToRemove); - int flags = rs.getInt("flags"); - this.removeAll = ((flags & 2) != 0) ? true : false; + this.removeAll = rs.removeAll; } diff --git a/src/engine/wpak/PowerActionParser.java b/src/engine/wpak/PowerActionParser.java index 0815dd3b..9666194a 100644 --- a/src/engine/wpak/PowerActionParser.java +++ b/src/engine/wpak/PowerActionParser.java @@ -31,6 +31,8 @@ public class PowerActionParser { private static final Pattern POWER_ACTION_REGEX = Pattern.compile("(?<=POWERACTIONBEGIN)(.+?)(?=POWERACTIONEND)", Pattern.DOTALL); private static final String powerActionPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/PowerActions.cfg"; + public static ArrayList power_actions= new ArrayList<>(); + public static void parseWpakFile() { // Read .wpak file from disk @@ -52,7 +54,7 @@ public class PowerActionParser { while (matcher.find()) { PowerAction powerAction = parsePowerActionEntry(matcher.group().trim()); - + power_actions.add(powerAction); } }