Files
Server/src/engine/parsers/wpak/PowActionCostParser.java
T

59 lines
2.4 KiB
Java
Raw Normal View History

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.parsers.wpak;
import engine.mbEnums;
import engine.parsers.objects.wpak.PowActionCostTemplate;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.HashMap;
// Loads PowActionCostInfo.cfg (client loader EffectCostMap_LoadPowActionCostInfo 0x6E00C0).
public class PowActionCostParser {
2026-10-22 11:38:07 -04:00
private static final String fileName = "Config/PowActionCostInfo.cfg";
public static HashMap<String, PowActionCostTemplate> parsePowActionCostFile() {
HashMap<String, PowActionCostTemplate> costs = new HashMap<>();
ArrayList<WpakLine> lines;
PowActionCostTemplate cost;
int failedCount = 0;
try {
lines = WpakFileReader.readLines(fileName);
} catch (Exception e) {
Logger.error(fileName + ": " + e.getMessage());
return null;
}
for (WpakLine line : lines) {
try {
// A repeated id adds its pairs to the existing entry, as the client does
cost = costs.computeIfAbsent(line.token(0), id -> new PowActionCostTemplate());
cost.id = line.token(0);
for (int i = 1; i < line.size(); i += 2)
cost.costs.put(line.enumToken(mbEnums.ResourceType.class, i), line.intToken(i + 1));
} catch (WpakFormatException e) {
Logger.error(e.getMessage());
failedCount++;
}
}
Logger.info("Loaded " + costs.size() + " power action resource costs from " + lines.size() + " lines");
if (failedCount > 0)
return null;
return costs;
}
}