diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index 6522f325..9c653c70 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -125,7 +125,7 @@ public class EffectsParser { matcher = CONDITIONS_REGEX.matcher(effectData); while (matcher.find()) { - List conditions = new ArrayList<>(Arrays.asList(matcher.group().trim().split("\n"))); + String[] conditions = matcher.group().trim().split("\n"); for (String condition : conditions) { List parameters = Arrays.asList(condition.trim().split("\\s+")); diff --git a/src/engine/wpak/PowerActionParser.java b/src/engine/wpak/PowerActionParser.java index 9d276c74..6b669532 100644 --- a/src/engine/wpak/PowerActionParser.java +++ b/src/engine/wpak/PowerActionParser.java @@ -22,6 +22,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -66,14 +67,13 @@ public class PowerActionParser { powerActionData = powerActionData.replaceAll("(?m)^(\\s*#.*|\\s*)\r?\n?", "").trim(); - String[] lineData = powerActionData.split("\n"); + List lineData = Arrays.asList(powerActionData.split("\n")); // Parse effect entry header - Iterator entryIterator = Arrays.stream(lineData).iterator(); - + Iterator entryIterator = lineData.iterator(); String headerLine = entryIterator.next(); - ArrayList headerData = new ArrayList<>(); + List headerData = new ArrayList<>(); Matcher matcher = STRSPLIT_REGEX.matcher(headerLine.trim()); @@ -206,90 +206,90 @@ public class PowerActionParser { while (entryIterator.hasNext()) { String lineValue = entryIterator.next(); - String[] lineValues = lineValue.split("="); - String key = lineValues[0].trim(); - String[] arguments; + List lineValues = Arrays.asList(lineValue.split("=")); + String key = lineValues.get(0).trim(); + List arguments; switch (key) { case "BODYPARTS": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String bodyPart : arguments) powerActionEntry.bodyparts.add(Integer.parseInt(bodyPart)); break; case "FEMALEBODYPARTS": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String bodyPart : arguments) powerActionEntry.femaleBodyParts.add(Integer.parseInt(bodyPart)); break; case "SCALEFACTOR": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String scaleFactor : arguments) powerActionEntry.scaleFactor.add(Float.parseFloat(scaleFactor)); break; case "ISRESISTABLE": - powerActionEntry.isResistible = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.isResistible = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "ISAGGRESSIVE": - powerActionEntry.isAggressive = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.isAggressive = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "BLADETRAILS": - powerActionEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.bladeTrails = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "SHOULDSHOWWEAPONS": - powerActionEntry.shouldShowWeapons = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.shouldShowWeapons = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "SHOULDSHOWARMOR": - powerActionEntry.shouldShowArmor = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.shouldShowArmor = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "APPLYEFFECTBLANK": - powerActionEntry.applyEffectBlank = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.applyEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "WEAROFFEFFECTBLANK": - powerActionEntry.wearOffEffectBlank = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.wearOffEffectBlank = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "ATTACKANIMS": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); for (String animation : arguments) powerActionEntry.attackAnimations.add(Integer.parseInt(animation)); break; case "REMOVEALL": - powerActionEntry.removeAll = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.removeAll = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "EFFECTID": effectDescription = new EffectDescription(); - effectDescription.effect_id = lineValues[1].trim(); + effectDescription.effect_id = lineValues.get(1).trim(); powerActionEntry.effects.add(effectDescription); break; case "LEVELCAP": - arguments = lineValues[1].trim().split("\\s+"); - powerActionEntry.levelCap = Integer.parseInt(arguments[0]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + powerActionEntry.levelCap = Integer.parseInt(arguments.get(0)); - if (arguments.length > 1) // Not all level caps have a curve - powerActionEntry.levelCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]); + if (arguments.size() > 1) // Not all level caps have a curve + powerActionEntry.levelCurve = mbEnums.CompoundCurveType.valueOf(arguments.get(1)); break; case "CLEARAGGRO": - powerActionEntry.clearAggro = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.clearAggro = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "TARGETBECOMESPET": - powerActionEntry.targetBecomesPet = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.targetBecomesPet = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "DESTROYOLDPET": - powerActionEntry.destroyOldPet = Boolean.parseBoolean(lineValues[1].trim()); + powerActionEntry.destroyOldPet = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "DAMAGETYPE": - powerActionEntry.damageType = mbEnums.DamageType.valueOf(lineValues[1].trim().toUpperCase()); + powerActionEntry.damageType = mbEnums.DamageType.valueOf(lineValues.get(1).trim().toUpperCase()); break; case "ROOTFSMID": - powerActionEntry.rootFsmID = mbEnums.MobBehaviourType.valueOf(lineValues[1].trim()); + powerActionEntry.rootFsmID = mbEnums.MobBehaviourType.valueOf(lineValues.get(1).trim()); break; case "SPLASHDAMAGE": - arguments = lineValues[1].trim().split("\\s+"); - powerActionEntry.splashDamageMin = Integer.parseInt(arguments[0]); - powerActionEntry.splashDamageMax = Integer.parseInt(arguments[1]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + powerActionEntry.splashDamageMin = Integer.parseInt(arguments.get(0)); + powerActionEntry.splashDamageMax = Integer.parseInt(arguments.get(1)); break; case "APPLYEFFECTOTHER": case "APPLYEFFECTSELF": diff --git a/src/engine/wpak/PowersParser.java b/src/engine/wpak/PowersParser.java index c5b13401..25586501 100644 --- a/src/engine/wpak/PowersParser.java +++ b/src/engine/wpak/PowersParser.java @@ -18,6 +18,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -84,10 +85,10 @@ public class PowersParser { // Parse header line in power data - String[] lineData = powerString.toString().trim().split("\n"); - ArrayList powerHeader = new ArrayList<>(); + List lineData = Arrays.asList(powerString.toString().trim().split("\n")); + List powerHeader = new ArrayList<>(); - String headerString = lineData[0]; + String headerString = lineData.get(0); headerString = headerString.replace("\n", " "); matcher = STRSPLIT_REGEX.matcher(headerString); @@ -128,6 +129,7 @@ public class PowersParser { powerEntry.cost = Float.parseFloat(iterator.next()); powerEntry.difficulty = Float.parseFloat(iterator.next()); powerEntry.precision = Float.parseFloat(iterator.next()); + // Cleanup init_time in client data which is 0.35.1 or some such powerEntry.init_time = Float.parseFloat(iterator.next().replaceAll("(\\.0)+$", "")); powerEntry.release_time = Float.parseFloat(iterator.next()); powerEntry.recycle_time = Float.parseFloat(iterator.next()); @@ -139,65 +141,65 @@ public class PowersParser { // Process key value pairs after header - iterator = Arrays.stream(lineData).iterator(); + iterator = lineData.iterator(); iterator.next(); // Ignore header while (iterator.hasNext()) { String lineValue = iterator.next(); - String[] lineValues = lineValue.split("="); - String key = lineValues[0].trim(); + List lineValues = Arrays.asList(lineValue.split("=")); + String key = lineValues.get(0).trim(); ActionEntry actionEntry; - String[] arguments; + List arguments; Matcher matcher1; ArrayList args; switch (key) { case "ACTION": actionEntry = new ActionEntry(); - arguments = lineValues[1].trim().split("\\s+"); - - actionEntry.effect_id = arguments[0]; - actionEntry.minTrains = Integer.parseInt(arguments[1]); - 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]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + + actionEntry.effect_id = arguments.get(0); + actionEntry.minTrains = Integer.parseInt(arguments.get(1)); + actionEntry.maxTrains = Integer.parseInt(arguments.get(2)); + actionEntry.duration = Float.parseFloat(arguments.get(3)); + actionEntry.curve = mbEnums.CompoundCurveType.valueOf(arguments.get(4)); + actionEntry.stackingCategory = arguments.get(5); + actionEntry.stackingPriority = Integer.parseInt(arguments.get(6)); + actionEntry.categoryToPower = mbEnums.CategoryToPowerType.valueOf(arguments.get(7)); powerEntry.actionEntries.add(actionEntry); break; case "MaxLevel": - powerEntry.maxLevel = Integer.parseInt(lineValues[1].trim()); + powerEntry.maxLevel = Integer.parseInt(lineValues.get(1).trim()); break; case "HateValue": - arguments = lineValues[1].trim().split("\\s+"); - powerEntry.hateValue = Integer.parseInt(arguments[0]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + powerEntry.hateValue = Integer.parseInt(arguments.get(0)); // Not all entries have a curve. Defaults to DefaultFlat; - if (arguments.length > 1) - powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments[1]); + if (arguments.size() > 1) + powerEntry.hateCurve = mbEnums.CompoundCurveType.valueOf(arguments.get(1)); break; case "LOOPANIMID": - powerEntry.loopAnimID = Integer.parseInt(lineValues[1].trim()); + powerEntry.loopAnimID = Integer.parseInt(lineValues.get(1).trim()); break; case "GRANTOVERRIDEVAR": - powerEntry.grantOverrideVar = lineValues[1].trim(); + powerEntry.grantOverrideVar = lineValues.get(1).trim(); break; case "DESCRIPTION": - powerEntry.description.add(lineValues[1].trim()); + powerEntry.description.add(lineValues.get(1).trim()); break; case "CATEGORY": - powerEntry.category = lineValues[1].trim(); + powerEntry.category = lineValues.get(1).trim(); break; case "CURVE": - arguments = lineValues[1].trim().split("\\s+"); - powerEntry.curves.put(arguments[0], mbEnums.CompoundCurveType.valueOf(arguments[1])); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + powerEntry.curves.put(arguments.get(0), mbEnums.CompoundCurveType.valueOf(arguments.get(1))); break; case "EQPREREQ": EquipmentPreReq equipmentPreReq = new EquipmentPreReq(); - matcher1 = STRSPLIT_REGEX.matcher(lineValues[1].trim()); + matcher1 = STRSPLIT_REGEX.matcher(lineValues.get(1).trim()); args = new ArrayList<>(); while (matcher1.find()) @@ -209,63 +211,65 @@ public class PowersParser { powerEntry.equipmentPreReq = equipmentPreReq; break; case "CANCASTWHILEMOVING": - powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.canCastWhileMoving = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "CANCASTWHILEFLYING": - powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.canCastWhileFlying = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "BLADETRAILS": - powerEntry.bladeTrails = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.bladeTrails = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "EFFECTPREREQ": EffectDescription effectPreReq = new EffectDescription(); - arguments = lineValues[1].trim().split("\\s+"); - effectPreReq.effect_id = arguments[9]; - effectPreReq.level = Integer.parseInt(arguments[1]); - effectPreReq.message = arguments[2]; + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + effectPreReq.effect_id = arguments.get(9); + effectPreReq.level = Integer.parseInt(arguments.get(1)); + effectPreReq.message = arguments.get(2); powerEntry.effectPreReqs.add(effectPreReq); break; case "MONSTERTYPERESTRICTS": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + for (String restriction : arguments) powerEntry.monsterRestricts.add(mbEnums.MonsterType.valueOf(restriction.trim())); break; case "MONSTERTYPEPREREQS": - arguments = lineValues[1].trim().split("\\s+"); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + for (String restriction : arguments) powerEntry.monsterPrereqs.add(mbEnums.MonsterType.valueOf(restriction.trim())); break; case "SHOULDCHECKPATH": - powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.shouldCheckPath = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "STICKY": - powerEntry.sticky = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.sticky = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "PULSEINFO": - arguments = lineValues[1].trim().split("\\s+"); - powerEntry.pulseCycle = Integer.parseInt(arguments[0]); - powerEntry.pulseDuration = Integer.parseInt(arguments[1]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + powerEntry.pulseCycle = Integer.parseInt(arguments.get(0)); + powerEntry.pulseDuration = Integer.parseInt(arguments.get(1)); break; case "MAXNUMMOBTARGETS": - powerEntry.maxMobTargets = Integer.parseInt(lineValues[1].trim()); + powerEntry.maxMobTargets = Integer.parseInt(lineValues.get(1).trim()); break; case "MAXNUMPLAYERTARGETS": - powerEntry.maxPlayerTargets = Integer.parseInt(lineValues[1].trim()); + powerEntry.maxPlayerTargets = Integer.parseInt(lineValues.get(1).trim()); break; case "ISADMINPOWER": - powerEntry.isAdminPower = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.isAdminPower = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "ISPROJECTILE": - powerEntry.isProjectile = Boolean.parseBoolean(lineValues[1].trim()); + powerEntry.isProjectile = Boolean.parseBoolean(lineValues.get(1).trim()); break; case "CASTERSPULSEPARTICLE": - powerEntry.casterPulseParticle = Integer.parseInt(lineValues[1].trim()); + powerEntry.casterPulseParticle = Integer.parseInt(lineValues.get(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]); + arguments = Arrays.asList(lineValues.get(1).trim().split("\\s+")); + preReq.effect_id = arguments.get(0); + preReq.level = Integer.parseInt(arguments.get(1)); powerEntry.targetEffectPrereqs.add(preReq); break; case "SOUNDS": // Values not parsed @@ -293,14 +297,14 @@ public class PowersParser { // Parse power conditions if (!conditionString.toString().isEmpty()) { + String[] conditions = conditionString.toString().split("\n"); for (String condition : conditions) { - String[] parameters = condition.trim().split("\\s+"); - powerEntry.conditions.put(parameters[0], Float.parseFloat(parameters[1])); + List parameters = Arrays.asList(condition.trim().split("\\s+")); + powerEntry.conditions.put(parameters.get(0), Float.parseFloat(parameters.get(1))); } } - return powerEntry; }