Public Repository for the Magicbane Shadowbane Emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.7 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2024
// www.magicbane.com
package engine.wpak;
import engine.gameManager.ConfigManager;
8 months ago
import org.pmw.tinylog.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PowersParser {
8 months ago
public static String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Powers.cfg";
private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL);
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
public static void parseWpakFile() throws IOException {
// Read .wpak file from disk
byte[] fileData = Files.readAllBytes(Paths.get(powersPath));
String fileContents = new String(fileData);
// Iterate over power entries from .wpak data
Matcher matcher = POWER_REGEX.matcher(fileContents);
while (matcher.find()) {
8 months ago
PowerEntry powerEntry = parsePowerEntry(matcher.group().trim());
}
}
private static <Iterator> PowerEntry parsePowerEntry(String powerData) {
8 months ago
PowerEntry powerEntry = new PowerEntry();
8 months ago
try {
String[] powerEntries = powerData.trim().split("\n");
ArrayList<String> powerHeader = new ArrayList<>();
// Parse header
String headerString = powerEntries[0];
headerString = headerString.replace("\n", " ");
Matcher matcher = STRSPLIT_REGEX.matcher(headerString);
while (matcher.find())
powerHeader.add(matcher.group().trim());
java.util.Iterator<String> iterator = powerHeader.iterator();
8 months ago
powerEntry.power_id = iterator.next();
powerEntry.power = iterator.next().replaceAll("\"", "");
8 months ago
PowerData power = new PowerData();
power.power_type = iterator.next();
;
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
powerEntry.target_type = iterator.next();
// Account for second definition
if (powerEntry.target_type.equals("SPELL") ||
powerEntry.target_type.equals("SKILL")) {
power = new PowerData();
power.power_type = powerEntry.target_type;
power.icon = Integer.parseInt(iterator.next());
power.powerBase = iterator.next().replaceAll("\"", "");
powerEntry.powers.add(power);
powerEntry.target_type = iterator.next();
}
powerEntry.range = Integer.parseInt(iterator.next());
powerEntry.areaType = iterator.next();
powerEntry.areaRange = Integer.parseInt(iterator.next());
powerEntry.excludeType = iterator.next();
powerEntry.costType = iterator.next();
powerEntry.cost = Float.parseFloat(iterator.next());
8 months ago
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 = iterator.next();
powerEntry.initAmin = Integer.parseInt(iterator.next());
powerEntry.releaseAnim = Integer.parseInt(iterator.next());
powerEntry.targetSelect = iterator.next();
8 months ago
for (int x = 2; x < powerEntries.length; x++) {
// Parse key/pair values
// via switch
}
8 months ago
} catch (Exception e) {
Logger.error(powerEntry.power_id);
}
return powerEntry;
}
}