PowerActionEntry parsing work.

This commit is contained in:
2024-08-20 12:06:35 -04:00
parent afd73082f3
commit 7ed94d171a
3 changed files with 209 additions and 216 deletions
+1
View File
@@ -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
+208 -213
View File
@@ -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("CONDITIONBEGINCONDITIONEND", ""));
powerString = new StringBuilder(powerString.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?", "")); 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"); String[] lineData = powerString.toString().trim().split("\n");
ArrayList<String> powerHeader = new ArrayList<>(); ArrayList<String> powerHeader = new ArrayList<>();
String headerString = lineData[0]; String headerString = lineData[0];
headerString = headerString.replace("\n", " "); headerString = headerString.replace("\n", " ");
matcher = STRSPLIT_REGEX.matcher(headerString); matcher = STRSPLIT_REGEX.matcher(headerString);
while (matcher.find()) while (matcher.find())
powerHeader.add(matcher.group().trim()); powerHeader.add(matcher.group().trim());
java.util.Iterator<String> iterator = powerHeader.iterator(); java.util.Iterator<String> iterator = powerHeader.iterator();
powerEntry.power_id = iterator.next(); powerEntry.power_id = iterator.next();
powerEntry.power = iterator.next().replaceAll("\"", ""); powerEntry.power = iterator.next().replaceAll("\"", "");
PowerData power = new PowerData(); PowerData power = new PowerData();
power.power_type = mbEnums.PowerType.valueOf(iterator.next()); power.power_type = mbEnums.PowerType.valueOf(iterator.next());
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
String nextValue = 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());
} else
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(nextValue);
String nextValue = iterator.next(); powerEntry.range = Integer.parseInt(iterator.next());
powerEntry.areaType = mbEnums.AreaType.valueOf(iterator.next());
powerEntry.areaRange = Integer.parseInt(iterator.next());
powerEntry.excludeType = mbEnums.ExcludeType.valueOf(iterator.next());
powerEntry.costType = mbEnums.CostType.valueOf(iterator.next());
powerEntry.cost = Float.parseFloat(iterator.next());
powerEntry.difficulty = Float.parseFloat(iterator.next());
powerEntry.precision = Float.parseFloat(iterator.next());
powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", ""));
powerEntry.release_time = Float.parseFloat(iterator.next());
powerEntry.recycle_time = Float.parseFloat(iterator.next());
powerEntry.hitRollYN = Integer.parseInt(iterator.next());
powerEntry.castingMode = mbEnums.CastingModeType.valueOf(iterator.next());
powerEntry.initAmin = Integer.parseInt(iterator.next());
powerEntry.releaseAnim = Integer.parseInt(iterator.next());
powerEntry.targetSelect = mbEnums.TargetSelectType.valueOf(iterator.next());
// Account for second definition // Process key value pairs after header
if (nextValue.equals("SPELL") || nextValue.equals("SKILL")) { iterator = Arrays.stream(lineData).iterator();
power = new PowerData(); iterator.next(); // Ignore header
power.power_type = mbEnums.PowerType.valueOf(nextValue);
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(iterator.next());
} else
powerEntry.target_type = mbEnums.PowerTargetType.valueOf(nextValue);
powerEntry.range = Integer.parseInt(iterator.next()); while (iterator.hasNext()) {
powerEntry.areaType = mbEnums.AreaType.valueOf(iterator.next());
powerEntry.areaRange = Integer.parseInt(iterator.next());
powerEntry.excludeType = mbEnums.ExcludeType.valueOf(iterator.next());
powerEntry.costType = mbEnums.CostType.valueOf(iterator.next());
powerEntry.cost = Float.parseFloat(iterator.next());
powerEntry.difficulty = Float.parseFloat(iterator.next());
powerEntry.precision = Float.parseFloat(iterator.next());
powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", ""));
powerEntry.release_time = Float.parseFloat(iterator.next());
powerEntry.recycle_time = Float.parseFloat(iterator.next());
powerEntry.hitRollYN = Integer.parseInt(iterator.next());
powerEntry.castingMode = mbEnums.CastingModeType.valueOf(iterator.next());
powerEntry.initAmin = Integer.parseInt(iterator.next());
powerEntry.releaseAnim = Integer.parseInt(iterator.next());
powerEntry.targetSelect = mbEnums.TargetSelectType.valueOf(iterator.next());
// Process key value pairs after header String lineValue = iterator.next();
String[] lineValues = lineValue.split("=");
String key = lineValues[0].trim();
ActionEntry actionEntry;
String[] arguments;
Matcher matcher1;
ArrayList<String> args;
iterator = Arrays.stream(lineData).iterator(); switch (key) {
iterator.next(); // Ignore header case "ACTION":
actionEntry = new ActionEntry();
arguments = lineValues[1].trim().split("\\s+");
while (iterator.hasNext()) { if (powerEntry.power_id.equals("HNT-050"))
Logger.error("debug");
String lineValue = iterator.next(); actionEntry.effect_id = arguments[0];
String[] lineValues = lineValue.split("="); actionEntry.minTrains = Integer.parseInt(arguments[1]);
String key = lineValues[0].trim(); actionEntry.maxTrains = Integer.parseInt(arguments[2]);
ActionEntry actionEntry; actionEntry.duration = Float.parseFloat(arguments[3]);
String[] arguments; actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments[4]);
Matcher matcher1; actionEntry.stackingCategory = arguments[5];
ArrayList<String> args; actionEntry.stackingPriority = Integer.parseInt(arguments[6]);
actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments[7]);
powerEntry.actionEntries.add(actionEntry);
break;
case "MaxLevel":
powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim());
break;
case "HateValue":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.hateValue = Integer.parseInt(arguments[0]);
switch (key) { // Not all entries have a curve. Defaults to DefaultFlat;
case "ACTION":
actionEntry = new ActionEntry();
arguments = lineValues[1].trim().split("\\s+");
if (powerEntry.power_id.equals("HNT-050")) if (arguments.length > 1)
Logger.error("debug"); powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]);
break;
case "LOOPANIMID":
powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim());
break;
case "GRANTOVERRIDEVAR":
powerEntry.grantOverrideVar = lineValues[1].trim();
break;
case "DESCRIPTION":
powerEntry.description.add(lineValues[1].trim());
break;
case "CATEGORY":
powerEntry.category = lineValues[1].trim();
break;
case "CURVE":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1]));
break;
case "EQPREREQ":
EquipmentPreReq equipmentPreReq = new EquipmentPreReq();
matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim());
args = new ArrayList<>();
actionEntry.effect_id = arguments[0]; while (matcher1.find())
actionEntry.minTrains = Integer.parseInt(arguments[1]); args.add(matcher1.group().trim());
actionEntry.maxTrains = Integer.parseInt(arguments[2]);
actionEntry.duration = Float.parseFloat(arguments[3]);
actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments[4]);
actionEntry.stackingCategory = arguments[5];
actionEntry.stackingPriority = Integer.parseInt(arguments[6]);
actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments[7]);
powerEntry.actionEntries.add(actionEntry);
break;
case "MaxLevel":
powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim());
break;
case "HateValue":
arguments = lineValues[1].trim().split("\\s+");
powerEntry.hateValue = Integer.parseInt(arguments[0]);
// Not all entries have a curve. Defaults to DefaultFlat; equipmentPreReq.slot = mbEnums.EquipSlotType.valueOf(args.get(0));
equipmentPreReq.skill = args.get(1).replaceAll("\"", "");
if (arguments.length > 1) equipmentPreReq.level = Integer.parseInt(args.get(2));
powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]); powerEntry.equipmentPreReq = equipmentPreReq;
break; break;
case "LOOPANIMID": case "CANCASTWHILEMOVING":
powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim()); powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim());
break; break;
case "GRANTOVERRIDEVAR": case "CANCASTWHILEFLYING":
powerEntry.grantOverrideVar = lineValues[1].trim(); powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim());
break; break;
case "DESCRIPTION": case "BLADETRAILS":
powerEntry.description.add(lineValues[1].trim()); powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim());
break; break;
case "CATEGORY": case "EFFECTPREREQ":
powerEntry.category = lineValues[1].trim(); EffectDescription effectPreReq = new EffectDescription();
break; arguments = lineValues[1].trim().split("\\s+");
case "CURVE": effectPreReq.effect_id = arguments[9];
arguments = lineValues[1].trim().split("\\s+"); effectPreReq.level = Integer.parseInt(arguments[1]);
powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1])); effectPreReq.message = arguments[2];
break; powerEntry.effectPreReqs.add(effectPreReq);
case "EQPREREQ": break;
EquipmentPreReq equipmentPreReq = new EquipmentPreReq(); case "MONSTERTYPERESTRICTS":
matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim()); arguments = lineValues[1].trim().split("\\s+");
args = new ArrayList<>(); for (String restriction : arguments)
powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim()));
while (matcher1.find()) break;
args.add(matcher1.group().trim()); case "MONSTERTYPEPREREQS":
arguments = lineValues[1].trim().split("\\s+");
equipmentPreReq.slot = mbEnums.EquipSlotType.valueOf(args.get(0)); for (String restriction : arguments)
equipmentPreReq.skill = args.get(1).replaceAll("\"", ""); powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim()));
equipmentPreReq.level = Integer.parseInt(args.get(2)); break;
powerEntry.equipmentPreReq = equipmentPreReq; case "SHOULDCHECKPATH":
break; powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim());
case "CANCASTWHILEMOVING": break;
powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim()); case "STICKY":
break; powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim());
case "CANCASTWHILEFLYING": break;
powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim()); case "PULSEINFO":
break; arguments = lineValues[1].trim().split("\\s+");
case "BLADETRAILS": powerEntry.pulseCycle = Integer.parseInt(arguments[0]);
powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim()); powerEntry.pulseDuration = Integer.parseInt(arguments[1]);
break; break;
case "EFFECTPREREQ": case "MAXNUMMOBTARGETS":
EffectDescription effectPreReq = new EffectDescription(); powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim());
arguments = lineValues[1].trim().split("\\s+"); break;
effectPreReq.effect_id = arguments[9]; case "MAXNUMPLAYERTARGETS":
effectPreReq.level = Integer.parseInt(arguments[1]); powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim());
effectPreReq.message = arguments[2]; break;
powerEntry.effectPreReqs.add(effectPreReq); case "ISADMINPOWER":
break; powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim());
case "MONSTERTYPERESTRICTS": break;
arguments = lineValues[1].trim().split("\\s+"); case "ISPROJECTILE":
for (String restriction : arguments) powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim());
powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim())); break;
break; case "CASTERSPULSEPARTICLE":
case "MONSTERTYPEPREREQS": powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim());
arguments = lineValues[1].trim().split("\\s+"); break;
for (String restriction : arguments) case "TARGETEFFECTPREREQS_ORED":
powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim())); EffectDescription preReq = new EffectDescription();
break; arguments = lineValues[1].trim().split("\\s+");
case "SHOULDCHECKPATH": preReq.effect_id = arguments[0];
powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim()); preReq.level = Integer.parseInt(arguments[1]);
break; powerEntry.targetEffectPrereqs.add(preReq);
case "STICKY": break;
powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim()); case "SOUNDS": // Values not parsed
break; case "APPLYDAMAGESELF":
case "PULSEINFO": case "APPLYDAMAGECASTER":
arguments = lineValues[1].trim().split("\\s+"); case "APPLYDAMAGEOTHER":
powerEntry.pulseCycle = Integer.parseInt(arguments[0]); case "APPLYDAMAGETARGET":
powerEntry.pulseDuration = Integer.parseInt(arguments[1]); case "APPLYEFFECTSELF":
break; case "APPLYEFFECTOTHER":
case "MAXNUMMOBTARGETS": case "APPLYEFFECTCASTER":
powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim()); case "APPLYEFFECTTARGET":
break; case "FIZZLEOTHER":
case "MAXNUMPLAYERTARGETS": case "FIZZLESELF":
powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim()); case "INITSTRING":
break; case "SUCCESSOTHER":
case "ISADMINPOWER": case "SUCCESSSELF":
powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim()); case "WEAROFFEFFECTOTHER":
break; case "WEAROFFEFFECTSELF":
case "ISPROJECTILE": break;
powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim()); default:
break; Logger.error("Unhandled variable type:" + key + " for power: " + powerEntry.power_id);
case "CASTERSPULSEPARTICLE":
powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim());
break;
case "TARGETEFFECTPREREQS_ORED":
EffectDescription preReq = new EffectDescription();
arguments = lineValues[1].trim().split("\\s+");
preReq.effect_id = arguments[0];
preReq.level = Integer.parseInt(arguments[1]);
powerEntry.targetEffectPrereqs.add(preReq);
break;
case "SOUNDS": // Values not parsed
case "APPLYDAMAGESELF":
case "APPLYDAMAGECASTER":
case "APPLYDAMAGEOTHER":
case "APPLYDAMAGETARGET":
case "APPLYEFFECTSELF":
case "APPLYEFFECTOTHER":
case "APPLYEFFECTCASTER":
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;
@@ -34,7 +34,4 @@ public class PowerActionEntry {
public boolean applyEffectBlank = false; public boolean applyEffectBlank = false;
public boolean wearOffEffectBlank = false; public boolean wearOffEffectBlank = false;
} }