Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de8896ff4e | |||
| e579912733 | |||
| c7b4404c36 | |||
| f1de7d413a | |||
| cc6f5f5f25 | |||
| 19bf75ade8 | |||
| 73eacc3779 | |||
| 69f3504ee9 | |||
| bd89b5e975 | |||
| 186eea3099 | |||
| 5e0badef17 | |||
| ea24d493fd | |||
| d12d040def | |||
| 491a9dbae9 | |||
| 1e0372c40d | |||
| d2f6344846 |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package engine.ConfigParsing.EffectsData;
|
package engine.ConfigParsing.EffectEntry;
|
||||||
|
|
||||||
public class Condition {
|
public class Condition {
|
||||||
public String type;
|
public String type;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package engine.ConfigParsing.EffectEntry;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class EffectEntry {
|
||||||
|
public String id;
|
||||||
|
public String name;
|
||||||
|
public int icon;
|
||||||
|
public HashSet<String> sources = new HashSet<>();
|
||||||
|
public HashSet<String> mods;
|
||||||
|
public HashSet<String> conditions;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package engine.ConfigParsing.EffectEntry;
|
||||||
|
|
||||||
|
import engine.mbEnums;
|
||||||
|
|
||||||
|
public class Mod {
|
||||||
|
public mbEnums.ModType type;
|
||||||
|
public int min;
|
||||||
|
public int max;
|
||||||
|
public float scale;
|
||||||
|
public String slopeType;
|
||||||
|
public String target;
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package engine.ConfigParsing.EffectsData;
|
|
||||||
|
|
||||||
import engine.mbEnums;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class EffectData {
|
|
||||||
public String id;
|
|
||||||
public String name;
|
|
||||||
public int icon;
|
|
||||||
public ArrayList<mbEnums.EffectSourceType> sources;
|
|
||||||
public ArrayList<Mod> mods;
|
|
||||||
public ArrayList<String> conditions;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package engine.ConfigParsing.EffectsData;
|
|
||||||
|
|
||||||
import engine.mbEnums;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Mod {
|
|
||||||
public mbEnums.ModType type;
|
|
||||||
public ArrayList<String> values;
|
|
||||||
}
|
|
||||||
@@ -6,14 +6,10 @@
|
|||||||
// Magicbane Emulator Project © 2013 - 2024
|
// Magicbane Emulator Project © 2013 - 2024
|
||||||
// www.magicbane.com
|
// www.magicbane.com
|
||||||
|
|
||||||
|
|
||||||
package engine.ConfigParsing;
|
package engine.ConfigParsing;
|
||||||
|
|
||||||
import engine.ConfigParsing.EffectsData.Condition;
|
import engine.ConfigParsing.EffectEntry.EffectEntry;
|
||||||
import engine.ConfigParsing.EffectsData.EffectData;
|
|
||||||
import engine.ConfigParsing.EffectsData.Mod;
|
|
||||||
import engine.gameManager.ConfigManager;
|
import engine.gameManager.ConfigManager;
|
||||||
import engine.mbEnums;
|
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -21,180 +17,72 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class EffectsParser {
|
public class EffectsParser {
|
||||||
|
|
||||||
public static String EffectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg";
|
public static String EffectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg";
|
||||||
public static HashMap<String, EffectData> effect_data = new HashMap<>();
|
public static HashMap<String, EffectEntry> effect_data = new HashMap<>();
|
||||||
|
private static final Pattern EFFECT_REGEX = Pattern.compile("(?<=EFFECTBEGIN)(.+?)(?=EFFECTEND)", Pattern.DOTALL);
|
||||||
|
private static final Pattern SOURCE_REGEX = Pattern.compile("(?<=SOURCEBEGIN)(.+?)(?=SOURCEEND)", Pattern.DOTALL);
|
||||||
|
private static final Pattern MODS_REGEX = Pattern.compile("(?<=MODSBEGIN)(.+?)(?=MODSEEND)", Pattern.DOTALL);
|
||||||
|
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\".+?\")\\s*");
|
||||||
public static void init() throws IOException {
|
public static void init() throws IOException {
|
||||||
|
|
||||||
ArrayList<ArrayList<String>> compiledData = new ArrayList<>();
|
byte[] fileData = Files.readAllBytes(Paths.get(EffectsPath));
|
||||||
List<String> fileData = Files.readAllLines(Paths.get(EffectsPath));
|
String fileContents = new String(fileData);
|
||||||
ArrayList<String> modData = new ArrayList<>();
|
Matcher matcher = EFFECT_REGEX.matcher(fileContents);
|
||||||
|
|
||||||
for (String line : fileData) {
|
// Iterate effect entries from .wpak config data
|
||||||
|
|
||||||
if (line.contains("EFFECTBEGIN")) {
|
while (matcher.find()) {
|
||||||
modData = new ArrayList<>();
|
EffectEntry effectEntry = parseEffectEntry(matcher.group());
|
||||||
continue;
|
|
||||||
|
if (effectEntry != null)
|
||||||
|
effect_data.put(effectEntry.id, effectEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.contains("EFFECTEND"))
|
private static EffectEntry parseEffectEntry(String effectData) {
|
||||||
compiledData.add(modData);
|
EffectEntry effectEntry = new EffectEntry();
|
||||||
else
|
|
||||||
modData.add(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateBlocks(compiledData);
|
// Remove all lines that contain a # and leading/trailing blanks
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateBlocks(ArrayList<ArrayList<String>> compiledData) {
|
effectData = effectData.replaceAll("(?m)^.*#.*\r?\n?", "");
|
||||||
|
effectData = effectData.trim();
|
||||||
|
|
||||||
for (ArrayList<String> compiledLines : compiledData) {
|
// Parse effect entry description
|
||||||
|
|
||||||
EffectData effectData = new EffectData();
|
String firstLine = "";
|
||||||
effectData.id = compiledLines.get(1).replace(" ", "").split(" ")[0];
|
|
||||||
effectData.sources = new ArrayList<>();
|
|
||||||
effectData.mods = new ArrayList<>();
|
|
||||||
effectData.conditions = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String rawData = compiledLines.get(1).replace(" ", "");
|
firstLine = effectData.substring(0, effectData.indexOf('\n'));
|
||||||
if(rawData.contains("\"")){
|
|
||||||
int startIndex = rawData.indexOf('"') + 1;
|
|
||||||
int endIndex = rawData.lastIndexOf('"');
|
|
||||||
char[] nameValue = rawData.toCharArray();
|
|
||||||
String name = "";
|
|
||||||
for(int i = startIndex; i < endIndex; i++){
|
|
||||||
name += nameValue[i];
|
|
||||||
}
|
|
||||||
effectData.name = name;
|
|
||||||
}
|
|
||||||
int iconID;
|
|
||||||
try {
|
|
||||||
iconID = Integer.parseInt(compiledLines.get(1).replace(" ", "").split(" ")[2]);
|
|
||||||
} catch(Exception e){
|
|
||||||
iconID = 0;
|
|
||||||
}
|
|
||||||
effectData.icon = iconID;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error(e);
|
Logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 0;
|
ArrayList<String> effectDescription = new ArrayList<>();
|
||||||
|
|
||||||
//log all sources
|
Matcher matcher = STRSPLIT_REGEX.matcher(firstLine);
|
||||||
|
|
||||||
for (String line : compiledLines) {
|
while (matcher.find())
|
||||||
String rawValue;
|
effectDescription.add(matcher.group(1));
|
||||||
if (line.contains("SOURCEBEGIN")) {
|
|
||||||
rawValue = compiledLines.get(index + 1).replace(" ", "");
|
|
||||||
switch (rawValue) {
|
|
||||||
case "Crush":
|
|
||||||
rawValue = "Crushing";
|
|
||||||
break;
|
|
||||||
case "Slash":
|
|
||||||
rawValue = "Slashing";
|
|
||||||
break;
|
|
||||||
case "Pierce":
|
|
||||||
rawValue = "Piercing";
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
effectEntry.id = effectDescription.get(0);
|
||||||
effectData.sources.add(mbEnums.EffectSourceType.valueOf(rawValue));
|
effectEntry.name = effectDescription.get(1);
|
||||||
}
|
effectEntry.icon = Integer.parseInt(effectDescription.get(2));
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//log all mods
|
// Parse source entries
|
||||||
|
|
||||||
index = 0;
|
matcher = SOURCE_REGEX.matcher(effectData);
|
||||||
|
|
||||||
for (String line : compiledLines) {
|
while (matcher.find())
|
||||||
|
effectEntry.sources.add(matcher.group().trim());
|
||||||
|
|
||||||
if (line.contains("MODSBEGIN")) {
|
// Parse modifier entries
|
||||||
|
|
||||||
int extra = 1;
|
return effectEntry;
|
||||||
Mod mod = new Mod();
|
|
||||||
|
|
||||||
while (!compiledLines.get(index + extra).contains("MODSEND")) {
|
|
||||||
//data.mods.add(lines[index + extra].Replace(" ", ""));
|
|
||||||
String rawValue = compiledLines.get(index + extra).replace(" ", "").split(" ")[0];
|
|
||||||
try {
|
|
||||||
mod.type = mbEnums.ModType.valueOf(rawValue);
|
|
||||||
}catch(Exception e){
|
|
||||||
mod.type = mbEnums.ModType.None;
|
|
||||||
}
|
|
||||||
GenerateModValues(mod, compiledLines.get(index + extra).replace(" ", "").replace(" ", "").split(" "));
|
|
||||||
extra++;
|
|
||||||
}
|
|
||||||
effectData.mods.add(mod);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//log all conditions
|
|
||||||
|
|
||||||
index = 0;
|
|
||||||
for (String line : compiledLines) {
|
|
||||||
|
|
||||||
if (line.contains("CONDITIONBEGIN")) {
|
|
||||||
|
|
||||||
int extra = 1;
|
|
||||||
|
|
||||||
while (!compiledLines.get(index + extra).contains("CONDITIONEND")) {
|
|
||||||
|
|
||||||
if (!compiledLines.get(index + extra).contains("#")) {
|
|
||||||
//data.conditions.add(lines[index + extra].Replace(" ", ""));
|
|
||||||
Condition condition = new Condition();
|
|
||||||
condition.type = compiledLines.get(index + extra).replace(" ", "").split(" ")[0];
|
|
||||||
condition.value = compiledLines.get(index + extra).replace(" ", "").split(" ")[1];
|
|
||||||
}
|
|
||||||
extra++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
effect_data.put(effectData.id, effectData);
|
|
||||||
}
|
|
||||||
Logger.info("Effects.cfg Parsing Completed");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void GenerateModValues(Mod inMod, String[] data) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int maxValue = 5;
|
|
||||||
|
|
||||||
if(inMod.type != null && inMod.type.name().equals("Health")){
|
|
||||||
maxValue = 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.length < maxValue)
|
|
||||||
maxValue = data.length;
|
|
||||||
|
|
||||||
inMod.values = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 1; i < data.length; i++)
|
|
||||||
if (!data[i].isEmpty()) {
|
|
||||||
if (i >= maxValue)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (i == maxValue - 1)
|
|
||||||
try {
|
|
||||||
String entry = "";
|
|
||||||
for (int j = i; j < data.length; j ++){
|
|
||||||
entry += data[j] + " ";
|
|
||||||
}
|
|
||||||
entry = entry.trim();
|
|
||||||
inMod.values.add(entry.trim());
|
|
||||||
} catch (Exception e) {
|
|
||||||
inMod.values.add(data[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
inMod.values.add(data[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user