Browse Source

Power Action Constructor (not finished)

feature-config-usage
FatBoy-DOTC 2 months ago
parent
commit
0fd6dfb648
  1. 129
      src/engine/gameManager/PowersManager.java
  2. 145
      src/engine/powers/poweractions/AbstractPowerAction.java
  3. 7
      src/engine/powers/poweractions/ApplyEffectPowerAction.java
  4. 9
      src/engine/powers/poweractions/ApplyEffectsPowerAction.java
  5. 7
      src/engine/powers/poweractions/CharmPowerAction.java
  6. 3
      src/engine/powers/poweractions/ConfusionPowerAction.java
  7. 7
      src/engine/powers/poweractions/DamageOverTimePowerAction.java
  8. 7
      src/engine/powers/poweractions/DeferredPowerPowerAction.java
  9. 5
      src/engine/powers/poweractions/DirectDamagePowerAction.java
  10. 7
      src/engine/powers/poweractions/FearPowerAction.java
  11. 3
      src/engine/powers/poweractions/PeekPowerAction.java
  12. 8
      src/engine/powers/poweractions/RemoveEffectPowerAction.java
  13. 4
      src/engine/wpak/PowerActionParser.java

129
src/engine/gameManager/PowersManager.java

@ -27,12 +27,14 @@ import engine.net.client.ClientConnection; @@ -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 { @@ -127,6 +129,124 @@ public enum PowersManager {
}
public static void InitializePowerActions(){
// Add PowerActions
//AbstractPowerAction.getAllPowerActions(PowersManager.powerActionsByIDString, PowersManager.powerActionsByID, PowersManager.effectsBaseByIDString);
HashMap<String, EffectsBase> 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 { @@ -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<PowersBase> pbList = dbSkillReqHandler.getAllPowersBase();

145
src/engine/powers/poweractions/AbstractPowerAction.java

@ -18,6 +18,7 @@ import engine.objects.Item; @@ -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 { @@ -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 { @@ -64,139 +64,6 @@ public abstract class AbstractPowerAction {
this.isAggressive = false;
}
public static void getAllPowerActions(HashMap<String, AbstractPowerAction> powerActions, HashMap<Integer, AbstractPowerAction> powerActionsByID, HashMap<String, EffectsBase> 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);
}

7
src/engine/powers/poweractions/ApplyEffectPowerAction.java

@ -25,6 +25,7 @@ import engine.powers.ActionsBase; @@ -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 { @@ -38,11 +39,11 @@ public class ApplyEffectPowerAction extends AbstractPowerAction {
private String effectParentID;
private EffectsBase effectParent;
public ApplyEffectPowerAction(ResultSet rs, HashMap<String, EffectsBase> effects) throws SQLException {
public ApplyEffectPowerAction(PowerAction rs, HashMap<String, EffectsBase> 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);
}

9
src/engine/powers/poweractions/ApplyEffectsPowerAction.java

@ -17,6 +17,7 @@ import engine.objects.Item; @@ -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 { @@ -32,11 +33,11 @@ public class ApplyEffectsPowerAction extends AbstractPowerAction {
private EffectsBase effect2;
private EffectsBase effectParent;
public ApplyEffectsPowerAction(ResultSet rs, HashMap<String, EffectsBase> effects) throws SQLException {
public ApplyEffectsPowerAction(PowerAction rs, HashMap<String, EffectsBase> 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);

7
src/engine/powers/poweractions/CharmPowerAction.java

@ -18,6 +18,7 @@ import engine.objects.Mob; @@ -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 { @@ -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

3
src/engine/powers/poweractions/ConfusionPowerAction.java

@ -14,6 +14,7 @@ import engine.objects.AbstractCharacter; @@ -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; @@ -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);
}

7
src/engine/powers/poweractions/DamageOverTimePowerAction.java

@ -16,6 +16,7 @@ import engine.objects.AbstractWorldObject; @@ -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 { @@ -28,11 +29,11 @@ public class DamageOverTimePowerAction extends AbstractPowerAction {
private int numIterations;
private EffectsBase effect;
public DamageOverTimePowerAction(ResultSet rs, HashMap<String, EffectsBase> effects) throws SQLException {
public DamageOverTimePowerAction(PowerAction rs, HashMap<String, EffectsBase> 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);
}

7
src/engine/powers/poweractions/DeferredPowerPowerAction.java

@ -18,6 +18,7 @@ import engine.objects.PlayerCharacter; @@ -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 { @@ -31,11 +32,11 @@ public class DeferredPowerPowerAction extends AbstractPowerAction {
private EffectsBase effect;
// private EffectsBase deferedPower;
public DeferredPowerPowerAction(ResultSet rs, HashMap<String, EffectsBase> effects) throws SQLException {
public DeferredPowerPowerAction(PowerAction rs, HashMap<String, EffectsBase> 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);
}

5
src/engine/powers/poweractions/DirectDamagePowerAction.java

@ -17,6 +17,7 @@ import engine.objects.AbstractWorldObject; @@ -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 { @@ -28,10 +29,10 @@ public class DirectDamagePowerAction extends AbstractPowerAction {
private String effectID;
private EffectsBase effect;
public DirectDamagePowerAction(ResultSet rs, HashMap<String, EffectsBase> effects) throws SQLException {
public DirectDamagePowerAction(PowerAction rs, HashMap<String, EffectsBase> effects){
super(rs);
this.effectID = rs.getString("effectID");
this.effectID = rs.effects.get(0).effect_id;
this.effect = effects.get(this.effectID);
}

7
src/engine/powers/poweractions/FearPowerAction.java

@ -20,6 +20,7 @@ import engine.objects.Mob; @@ -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 { @@ -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

3
src/engine/powers/poweractions/PeekPowerAction.java

@ -18,6 +18,7 @@ import engine.net.client.msg.LootWindowResponseMsg; @@ -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; @@ -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);
}

8
src/engine/powers/poweractions/RemoveEffectPowerAction.java

@ -15,6 +15,7 @@ import engine.objects.AbstractCharacter; @@ -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 { @@ -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;
}

4
src/engine/wpak/PowerActionParser.java

@ -31,6 +31,8 @@ public class PowerActionParser { @@ -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<PowerAction> power_actions= new ArrayList<>();
public static void parseWpakFile() {
// Read .wpak file from disk
@ -52,7 +54,7 @@ public class PowerActionParser { @@ -52,7 +54,7 @@ public class PowerActionParser {
while (matcher.find()) {
PowerAction powerAction = parsePowerActionEntry(matcher.group().trim());
power_actions.add(powerAction);
}
}

Loading…
Cancel
Save