Browse Source

PowerActionEntry parsing work.

feature-config-parsing2
MagicBot 4 months ago
parent
commit
7ed94d171a
  1. 1
      src/engine/wpak/EffectsParser.java
  2. 445
      src/engine/wpak/PowersParser.java
  3. 3
      src/engine/wpak/data/PowerActionEntry.java

1
src/engine/wpak/EffectsParser.java

@ -43,6 +43,7 @@ public class EffectsParser {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
String fileContents = new String(fileData); String fileContents = new String(fileData);
// Iterate over effect entries from .wpak data // Iterate over effect entries from .wpak data

445
src/engine/wpak/PowersParser.java

@ -57,256 +57,251 @@ public class PowersParser {
PowerEntry powerEntry = new PowerEntry(); PowerEntry powerEntry = new PowerEntry();
try {
StringBuilder conditionString = new StringBuilder(); StringBuilder conditionString = new StringBuilder();
StringBuilder powerString = new StringBuilder(); StringBuilder powerString = new StringBuilder();
int endPos = 0; int endPos = 0;
// Separate out any conditions from the power data // Separate out any conditions from the power data
Matcher matcher = CONDITION_REGEX.matcher(powerData); Matcher matcher = CONDITION_REGEX.matcher(powerData);
while (matcher.find()) { while (matcher.find()) {
conditionString.append(matcher.group().trim()); conditionString.append(matcher.group().trim());
powerString.append(powerData, endPos, matcher.start()); powerString.append(powerData, endPos, matcher.start());
endPos = matcher.end(); endPos = matcher.end();
} }
powerString.append(powerData.substring(endPos));
powerString.append(powerData.substring(endPos)); // Cleanup dangling tags and lines that contain a # and leading/trailing blank lines
// Cleanup dangling tags and lines that contain a # and leading/trailing blank lines powerString = new StringBuilder(powerString.toString().replaceAll("CONDITIONBEGINCONDITIONEND", ""));
powerString = new StringBuilder(powerString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""));
powerString = new StringBuilder(powerString.toString().replaceAll("CONDITIONBEGINCONDITIONEND", "")); conditionString = new StringBuilder(conditionString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""));
powerString = new StringBuilder(powerString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", ""));
conditionString = new StringBuilder(conditionString.toString().replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", "")); // Parse header line in power data
// Parse header line in power data String[] lineData = powerString.toString().trim().split("\n");
ArrayList<String> powerHeader = new ArrayList<>();
String[] lineData = powerString.toString().trim().split("\n"); String headerString = lineData[0];
ArrayList<String> powerHeader = new ArrayList<>(); headerString = headerString.replace("\n", " ");
String headerString = lineData[0]; matcher = STRSPLIT_REGEX.matcher(headerString);
headerString = headerString.replace("\n", " ");
matcher = STRSPLIT_REGEX.matcher(headerString); while (matcher.find())
powerHeader.add(matcher.group().trim());
while (matcher.find()) java.util.Iterator<String> iterator = powerHeader.iterator();
powerHeader.add(matcher.group().trim());
java.util.Iterator<String> iterator = powerHeader.iterator(); powerEntry.power_id = iterator.next();
powerEntry.power = iterator.next().replaceAll("\"", "");
powerEntry.power_id = iterator.next(); PowerData power = new PowerData();
powerEntry.power = iterator.next().replaceAll("\"", ""); power.power_type = mbEnums.PowerType.valueOf(iterator.next());
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
PowerData power = new PowerData(); String nextValue = iterator.next();
power.power_type = mbEnums.PowerType.valueOf(iterator.next());
// Account for second definition
if (nextValue.equals("SPELL") || nextValue.equals("SKILL")) {
power = new PowerData();
power.power_type = mbEnums.PowerType.valueOf(nextValue);
power.icon = Integer.parseInt(iterator.next()); power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", ""); power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power); powerEntry.powers.add(power);
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(iterator.next());
String nextValue = iterator.next(); } else
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(nextValue);
// Account for second definition
powerEntry.range = Integer.parseInt(iterator.next());
if (nextValue.equals("SPELL") || nextValue.equals("SKILL")) { powerEntry.areaType = mbEnums.AreaType.valueOf(iterator.next());
power = new PowerData(); powerEntry.areaRange = Integer.parseInt(iterator.next());
power.power_type = mbEnums.PowerType.valueOf(nextValue); powerEntry.excludeType = mbEnums.ExcludeType.valueOf(iterator.next());
power.icon = Integer.parseInt(iterator.next()); powerEntry.costType = mbEnums.CostType.valueOf(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", ""); powerEntry.cost = Float.parseFloat(iterator.next());
powerEntry.powers.add(power); powerEntry.difficulty = Float.parseFloat(iterator.next());
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(iterator.next()); powerEntry.precision = Float.parseFloat(iterator.next());
} else powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", ""));
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(nextValue); powerEntry.release_time = Float.parseFloat(iterator.next());
powerEntry.recycle_time = Float.parseFloat(iterator.next());
powerEntry.range = Integer.parseInt(iterator.next()); powerEntry.hitRollYN = Integer.parseInt(iterator.next());
powerEntry.areaType = mbEnums.AreaType.valueOf(iterator.next()); powerEntry.castingMode = mbEnums.CastingModeType.valueOf(iterator.next());
powerEntry.areaRange = Integer.parseInt(iterator.next()); powerEntry.initAmin = Integer.parseInt(iterator.next());
powerEntry.excludeType = mbEnums.ExcludeType.valueOf(iterator.next()); powerEntry.releaseAnim = Integer.parseInt(iterator.next());
powerEntry.costType = mbEnums.CostType.valueOf(iterator.next()); powerEntry.targetSelect = mbEnums.TargetSelectType.valueOf(iterator.next());
powerEntry.cost = Float.parseFloat(iterator.next());
powerEntry.difficulty = Float.parseFloat(iterator.next()); // Process key value pairs after header
powerEntry.precision = Float.parseFloat(iterator.next());
powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", "")); iterator = Arrays.stream(lineData).iterator();
powerEntry.release_time = Float.parseFloat(iterator.next()); iterator.next(); // Ignore header
powerEntry.recycle_time = Float.parseFloat(iterator.next());
powerEntry.hitRollYN = Integer.parseInt(iterator.next()); while (iterator.hasNext()) {
powerEntry.castingMode = mbEnums.CastingModeType.valueOf(iterator.next());
powerEntry.initAmin = Integer.parseInt(iterator.next()); String lineValue = iterator.next();
powerEntry.releaseAnim = Integer.parseInt(iterator.next()); String[] lineValues = lineValue.split("=");
powerEntry.targetSelect = mbEnums.TargetSelectType.valueOf(iterator.next()); String key = lineValues[0].trim();
ActionEntry actionEntry;
// Process key value pairs after header String[] arguments;
Matcher matcher1;
iterator = Arrays.stream(lineData).iterator(); ArrayList<String> args;
iterator.next(); // Ignore header
switch (key) {
while (iterator.hasNext()) { case "ACTION":
actionEntry = new ActionEntry();
String lineValue = iterator.next(); arguments = lineValues[1].trim().split("\\s+");
String[] lineValues = lineValue.split("=");
String key = lineValues[0].trim(); if (powerEntry.power_id.equals("HNT-050"))
ActionEntry actionEntry; Logger.error("debug");
String[] arguments;
Matcher matcher1; actionEntry.effect_id = arguments[0];
ArrayList<String> args; actionEntry.minTrains = Integer.parseInt(arguments[1]);
actionEntry.maxTrains = Integer.parseInt(arguments[2]);
switch (key) { actionEntry.duration = Float.parseFloat(arguments[3]);
case "ACTION": actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments[4]);
actionEntry = new ActionEntry(); actionEntry.stackingCategory = arguments[5];
arguments = lineValues[1].trim().split("\\s+"); actionEntry.stackingPriority = Integer.parseInt(arguments[6]);
actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments[7]);
if (powerEntry.power_id.equals("HNT-050")) powerEntry.actionEntries.add(actionEntry);
Logger.error("debug"); break;
case "MaxLevel":
actionEntry.effect_id = arguments[0]; powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim());
actionEntry.minTrains = Integer.parseInt(arguments[1]); break;
actionEntry.maxTrains = Integer.parseInt(arguments[2]); case "HateValue":
actionEntry.duration = Float.parseFloat(arguments[3]); arguments = lineValues[1].trim().split("\\s+");
actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments[4]); powerEntry.hateValue = Integer.parseInt(arguments[0]);
actionEntry.stackingCategory = arguments[5];
actionEntry.stackingPriority = Integer.parseInt(arguments[6]); // Not all entries have a curve. Defaults to DefaultFlat;
actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments[7]);
powerEntry.actionEntries.add(actionEntry); if (arguments.length > 1)
break; powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]);
case "MaxLevel": break;
powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim()); case "LOOPANIMID":
break; powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim());
case "HateValue": break;
arguments = lineValues[1].trim().split("\\s+"); case "GRANTOVERRIDEVAR":
powerEntry.hateValue = Integer.parseInt(arguments[0]); powerEntry.grantOverrideVar = lineValues[1].trim();
break;
// Not all entries have a curve. Defaults to DefaultFlat; case "DESCRIPTION":
powerEntry.description.add(lineValues[1].trim());
if (arguments.length > 1) break;
powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]); case "CATEGORY":
break; powerEntry.category = lineValues[1].trim();
case "LOOPANIMID": break;
powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim()); case "CURVE":
break; arguments = lineValues[1].trim().split("\\s+");
case "GRANTOVERRIDEVAR": powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1]));
powerEntry.grantOverrideVar = lineValues[1].trim(); break;
break; case "EQPREREQ":
case "DESCRIPTION": EquipmentPreReq equipmentPreReq = new EquipmentPreReq();
powerEntry.description.add(lineValues[1].trim()); matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim());
break; args = new ArrayList<>();
case "CATEGORY":
powerEntry.category = lineValues[1].trim(); while (matcher1.find())
break; args.add(matcher1.group().trim());
case "CURVE":
arguments = lineValues[1].trim().split("\\s+"); equipmentPreReq.slot = mbEnums.EquipSlotType.valueOf(args.get(0));
powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1])); equipmentPreReq.skill = args.get(1).replaceAll("\"", "");
break; equipmentPreReq.level = Integer.parseInt(args.get(2));
case "EQPREREQ": powerEntry.equipmentPreReq = equipmentPreReq;
EquipmentPreReq equipmentPreReq = new EquipmentPreReq(); break;
matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim()); case "CANCASTWHILEMOVING":
args = new ArrayList<>(); powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim());
break;
while (matcher1.find()) case "CANCASTWHILEFLYING":
args.add(matcher1.group().trim()); powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim());
break;
equipmentPreReq.slot = mbEnums.EquipSlotType.valueOf(args.get(0)); case "BLADETRAILS":
equipmentPreReq.skill = args.get(1).replaceAll("\"", ""); powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim());
equipmentPreReq.level = Integer.parseInt(args.get(2)); break;
powerEntry.equipmentPreReq = equipmentPreReq; case "EFFECTPREREQ":
break; EffectDescription effectPreReq = new EffectDescription();
case "CANCASTWHILEMOVING": arguments = lineValues[1].trim().split("\\s+");
powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim()); effectPreReq.effect_id = arguments[9];
break; effectPreReq.level = Integer.parseInt(arguments[1]);
case "CANCASTWHILEFLYING": effectPreReq.message = arguments[2];
powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim()); powerEntry.effectPreReqs.add(effectPreReq);
break; break;
case "BLADETRAILS": case "MONSTERTYPERESTRICTS":
powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim()); arguments = lineValues[1].trim().split("\\s+");
break; for (String restriction : arguments)
case "EFFECTPREREQ": powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim()));
EffectDescription effectPreReq = new EffectDescription(); break;
arguments = lineValues[1].trim().split("\\s+"); case "MONSTERTYPEPREREQS":
effectPreReq.effect_id = arguments[9]; arguments = lineValues[1].trim().split("\\s+");
effectPreReq.level = Integer.parseInt(arguments[1]); for (String restriction : arguments)
effectPreReq.message = arguments[2]; powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim()));
powerEntry.effectPreReqs.add(effectPreReq); break;
break; case "SHOULDCHECKPATH":
case "MONSTERTYPERESTRICTS": powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim());
arguments = lineValues[1].trim().split("\\s+"); break;
for (String restriction : arguments) case "STICKY":
powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim())); powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim());
break; break;
case "MONSTERTYPEPREREQS": case "PULSEINFO":
arguments = lineValues[1].trim().split("\\s+"); arguments = lineValues[1].trim().split("\\s+");
for (String restriction : arguments) powerEntry.pulseCycle = Integer.parseInt(arguments[0]);
powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim())); powerEntry.pulseDuration = Integer.parseInt(arguments[1]);
break; break;
case "SHOULDCHECKPATH": case "MAXNUMMOBTARGETS":
powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim()); powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim());
break; break;
case "STICKY": case "MAXNUMPLAYERTARGETS":
powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim()); powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim());
break; break;
case "PULSEINFO": case "ISADMINPOWER":
arguments = lineValues[1].trim().split("\\s+"); powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim());
powerEntry.pulseCycle = Integer.parseInt(arguments[0]); break;
powerEntry.pulseDuration = Integer.parseInt(arguments[1]); case "ISPROJECTILE":
break; powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim());
case "MAXNUMMOBTARGETS": break;
powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim()); case "CASTERSPULSEPARTICLE":
break; powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim());
case "MAXNUMPLAYERTARGETS": break;
powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim()); case "TARGETEFFECTPREREQS_ORED":
break; EffectDescription preReq = new EffectDescription();
case "ISADMINPOWER": arguments = lineValues[1].trim().split("\\s+");
powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim()); preReq.effect_id = arguments[0];
break; preReq.level = Integer.parseInt(arguments[1]);
case "ISPROJECTILE": powerEntry.targetEffectPrereqs.add(preReq);
powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim()); break;
break; case "SOUNDS": // Values not parsed
case "CASTERSPULSEPARTICLE": case "APPLYDAMAGESELF":
powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim()); case "APPLYDAMAGECASTER":
break; case "APPLYDAMAGEOTHER":
case "TARGETEFFECTPREREQS_ORED": case "APPLYDAMAGETARGET":
EffectDescription preReq = new EffectDescription(); case "APPLYEFFECTSELF":
arguments = lineValues[1].trim().split("\\s+"); case "APPLYEFFECTOTHER":
preReq.effect_id = arguments[0]; case "APPLYEFFECTCASTER":
preReq.level = Integer.parseInt(arguments[1]); case "APPLYEFFECTTARGET":
powerEntry.targetEffectPrereqs.add(preReq); case "FIZZLEOTHER":
break; case "FIZZLESELF":
case "SOUNDS": // Values not parsed case "INITSTRING":
case "APPLYDAMAGESELF": case "SUCCESSOTHER":
case "APPLYDAMAGECASTER": case "SUCCESSSELF":
case "APPLYDAMAGEOTHER": case "WEAROFFEFFECTOTHER":
case "APPLYDAMAGETARGET": case "WEAROFFEFFECTSELF":
case "APPLYEFFECTSELF": break;
case "APPLYEFFECTOTHER": default:
case "APPLYEFFECTCASTER": Logger.error("Unhandled variable type:" + key + " for power: " + powerEntry.power_id);
case "APPLYEFFECTTARGET":
case "FIZZLEOTHER":
case "FIZZLESELF":
case "INITSTRING":
case "SUCCESSOTHER":
case "SUCCESSSELF":
case "WEAROFFEFFECTOTHER":
case "WEAROFFEFFECTSELF":
break;
default:
Logger.error("Unhandled variable type:" + key + " for power: " + powerEntry.power_id);
}
} }
}
// Parse power conditions // Parse power conditions
if (conditionString.toString().isEmpty() == false) { if (!conditionString.toString().isEmpty()) {
String[] conditions = conditionString.toString().split("\n"); String[] conditions = conditionString.toString().split("\n");
for (String condition : conditions) { for (String condition : conditions) {
String[] parameters = condition.trim().split("\\s+"); String[] parameters = condition.trim().split("\\s+");
powerEntry.conditions.put(parameters[0], Float.parseFloat(parameters[1])); powerEntry.conditions.put(parameters[0], Float.parseFloat(parameters[1]));
}
} }
} catch (Exception e) {
Logger.error(powerEntry.power_id + " " + e);
} }
return powerEntry; return powerEntry;

3
src/engine/wpak/data/PowerActionEntry.java

@ -34,7 +34,4 @@ public class PowerActionEntry {
public boolean applyEffectBlank = false; public boolean applyEffectBlank = false;
public boolean wearOffEffectBlank = false; public boolean wearOffEffectBlank = false;
} }

Loading…
Cancel
Save