Browse Source

Effects.cfg parser

feature-config-parsing
FatBoy-DOTC 5 months ago
parent
commit
e12a8a3c7c
  1. 6
      src/engine/ConfigParsing/EffectsData/Condition.java
  2. 12
      src/engine/ConfigParsing/EffectsData/EffectData.java
  3. 8
      src/engine/ConfigParsing/EffectsData/Mod.java
  4. 145
      src/engine/ConfigParsing/EffectsParser.java
  5. 5
      src/engine/server/world/WorldServer.java

6
src/engine/ConfigParsing/EffectsData/Condition.java

@ -0,0 +1,6 @@
package engine.ConfigParsing.EffectsData;
public class Condition {
public String type;
public String value;
}

12
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<String> sources;
public ArrayList<Mod> mods;
public ArrayList<String> conditions;
}

8
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<String> values;
}

145
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<ArrayList<String>> compiledData = new ArrayList<>();
String[] lines = readLines(EffectsPath);
ArrayList<String> 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<String> 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<ArrayList<String>> compiledData)
{
for (ArrayList<String> 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]);
}
}
}
}

5
src/engine/server/world/WorldServer.java

@ -9,6 +9,7 @@
package engine.server.world; package engine.server.world;
import engine.ConfigParsing.EffectsParser;
import engine.InterestManagement.RealmMap; import engine.InterestManagement.RealmMap;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse; import engine.db.archive.DataWarehouse;
@ -76,7 +77,7 @@ public class WorldServer {
super(); super();
} }
public static void main(String[] args) { public static void main(String[] args) throws IOException {
WorldServer worldServer; WorldServer worldServer;
@ -93,6 +94,8 @@ public class WorldServer {
return; return;
} }
EffectsParser.init();
try { try {
worldServer = new WorldServer(); worldServer = new WorldServer();

Loading…
Cancel
Save