diff --git a/src/engine/ConfigParsing/EffectsData/Condition.java b/src/engine/ConfigParsing/EffectsData/Condition.java new file mode 100644 index 00000000..17ae0cd7 --- /dev/null +++ b/src/engine/ConfigParsing/EffectsData/Condition.java @@ -0,0 +1,6 @@ +package engine.ConfigParsing.EffectsData; + +public class Condition { + public String type; + public String value; +} diff --git a/src/engine/ConfigParsing/EffectsData/EffectData.java b/src/engine/ConfigParsing/EffectsData/EffectData.java new file mode 100644 index 00000000..08604211 --- /dev/null +++ b/src/engine/ConfigParsing/EffectsData/EffectData.java @@ -0,0 +1,12 @@ +package engine.ConfigParsing.EffectsData; + +import java.util.ArrayList; + +public class EffectData { + public String id; + public String name; + public int icon; + public ArrayList sources; + public ArrayList mods; + public ArrayList conditions; +} diff --git a/src/engine/ConfigParsing/EffectsData/Mod.java b/src/engine/ConfigParsing/EffectsData/Mod.java new file mode 100644 index 00000000..faeea81d --- /dev/null +++ b/src/engine/ConfigParsing/EffectsData/Mod.java @@ -0,0 +1,8 @@ +package engine.ConfigParsing.EffectsData; + +import java.util.ArrayList; + +public class Mod { + public String type; + public ArrayList values; +} diff --git a/src/engine/ConfigParsing/EffectsParser.java b/src/engine/ConfigParsing/EffectsParser.java new file mode 100644 index 00000000..9771e191 --- /dev/null +++ b/src/engine/ConfigParsing/EffectsParser.java @@ -0,0 +1,145 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2024 +// www.magicbane.com + + +package engine.ConfigParsing; +import engine.ConfigParsing.EffectsData.Condition; +import engine.ConfigParsing.EffectsData.EffectData; +import engine.ConfigParsing.EffectsData.Mod; +import engine.gameManager.ConfigManager; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class EffectsParser { + public static String EffectsPath = ConfigManager.DEFAULT_DATA_DIR + "/Effects.cfg"; + public static void init() throws IOException { + ArrayList> compiledData = new ArrayList<>(); + String[] lines = readLines(EffectsPath); + ArrayList data = new ArrayList<>(); + for(String line : lines) + { + if (line.contains("EFFECTBEGIN")) + { + data = new ArrayList<>(); + } else if(!line.contains("EFFECTEND")) + { + data.add(line); + } + else if (line.contains("EFFECTEND")) + { + compiledData.add(data); + } + } + CreateBlocks(compiledData); + } + public static String[] readLines(String filename) throws IOException { + FileReader fileReader = new FileReader(filename); + BufferedReader bufferedReader = new BufferedReader(fileReader); + List lines = new ArrayList<>(); + String line; + while ((line = bufferedReader.readLine()) != null) { + lines.add(line); + } + bufferedReader.close(); + return lines.toArray(new String[0]); + } + public static void CreateBlocks(ArrayList> compiledData) + { + for (ArrayList lines : compiledData) + { + EffectData data = new EffectData(); + data.id = lines.get(1).replace(" ", "").split(" ")[0]; + try + { + data.name = lines.get(1).replace(" ", "").split(" ")[1]; + } + catch(Exception e) + { + + } + try + { + data.icon = Integer.parseInt(lines.get(1).replace(" ", "").split(" ")[2]); + } + catch(Exception e) + { + + } + //log all sources + data.sources = new ArrayList<>(); + int index = 0; + for(String line : lines) { + if (line.contains("SOURCEBEGIN")) + { + data.sources.add(lines.get(index).replace(" ", "")); + } + index++; + } + + //log all mods + data.mods = new ArrayList<>(); + index = 0; + + + for (String line : lines) + { + if (line.contains("MODSBEGIN")) + { + int extra = 1; + Mod mod = new Mod(); + while(!lines.get(index + extra).contains("MODSEND")) + { + //data.mods.add(lines[index + extra].Replace(" ", "")); + mod.type = lines.get(index + extra).replace(" ", "").split(" ")[0]; + GenerateModValues(mod, lines.get(index + extra).replace(" ", "").replace(" ", "").split(" ")); + extra++; + } + data.mods.add(mod); + } + index++; + } + + //log all conditions + data.conditions = new ArrayList<>(); + index = 0; + for (String line : lines) + { + if (line.contains("CONDITIONBEGIN")) + { + int extra = 1; + while (!lines.get(index + extra).contains("CONDITIONEND")) + { + if (!lines.get(index + extra).contains("#")) + { + //data.conditions.add(lines[index + extra].Replace(" ", "")); + Condition condition = new Condition(); + condition.type = lines.get(index + extra).replace(" ", "").split(" ")[0]; + condition.value = lines.get(index + extra).replace(" ", "").split(" ")[1]; + } + extra++; + } + } + index++; + } + } + } + public static void GenerateModValues(Mod inMod, String[] data) + { + inMod.values = new ArrayList<>(); + for(int i = 1; i < data.length; i++) + { + if(data[i].length() != 0) + { + inMod.values.add(data[i]); + } + } + } +} \ No newline at end of file diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 85b1e335..3c73cefa 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -9,6 +9,7 @@ package engine.server.world; +import engine.ConfigParsing.EffectsParser; import engine.InterestManagement.RealmMap; import engine.InterestManagement.WorldGrid; import engine.db.archive.DataWarehouse; @@ -76,7 +77,7 @@ public class WorldServer { super(); } - public static void main(String[] args) { + public static void main(String[] args) throws IOException { WorldServer worldServer; @@ -93,6 +94,8 @@ public class WorldServer { return; } + EffectsParser.init(); + try { worldServer = new WorldServer();