Files
Server/src/engine/parsers/wpak/SkillParser.java
T
MagicBotandClaude Opus 5.5 098f5d2c38 Read wpak cfgs from one folder per archive
Files now load from mb.data/wpak/<archive>/<file>, matching MBDATA's
data/wpak layout and the client's Config/Config.wpak naming, so more
archives can sit beside Config/ later. All nine current files are in
wpak/Config/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 11:38:07 -04:00

81 lines
2.8 KiB
Java

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.parsers.wpak;
import engine.mbEnums;
import engine.parsers.objects.wpak.SkillTemplate;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.HashMap;
// Loads Skills.cfg (client loader ArcSkill_LoadSkillsCfg 0x584430).
public class SkillParser {
private static final String fileName = "Config/Skills.cfg";
public static HashMap<String, SkillTemplate> parseSkillsFile() {
HashMap<String, SkillTemplate> skills = new HashMap<>();
ArrayList<WpakLine> lines;
SkillTemplate skill;
int failedCount = 0;
try {
lines = WpakFileReader.readLines(fileName);
} catch (Exception e) {
Logger.error(fileName + ": " + e.getMessage());
return null;
}
for (WpakLine line : lines) {
try {
skill = parseSkillLine(line);
if (skills.containsKey(skill.skill_uid))
Logger.warn(line.location() + ": duplicate skill " + skill.skill_uid + "; the later entry wins");
skills.put(skill.skill_uid, skill);
} catch (WpakFormatException e) {
Logger.error(e.getMessage());
failedCount++;
}
}
Logger.info("Loaded " + skills.size() + " of " + lines.size() + " skills");
if (failedCount > 0)
return null;
return skills;
}
// Attribute/weight pairs run until the "=" token; the description follows it
private static SkillTemplate parseSkillLine(WpakLine line) {
SkillTemplate skill = new SkillTemplate();
int index = 3;
skill.skill_uid = line.token(0);
skill.skill_name = line.token(1);
skill.icon_number = line.intToken(2);
while (line.has(index) && !line.token(index).equals("=")) {
skill.attr_weights.put(line.enumToken(mbEnums.AttributeType.class, index), line.intToken(index + 1));
index += 2;
}
skill.description = line.has(index + 1) ? line.token(index + 1) : "";
return skill;
}
}