forked from MagicBane/Server
Adds Race(RuneTemplate, Race): start/max attributes from rune_attr_adj/
rune_max_attr_adj (min is always 0), health/mana/stamina bonus from
rune_health/mana/stamina, startingPoints = 30 - rune_creation_cost, token =
SBStringHash(rune_sub_type), name from obj_name, description from rune_dsc,
hair/beard styles from rune_hair/rune_beard (style 0 when rune_hair is empty),
and baseClasses = the creation class runes whose item_race_req names the race
sub type. minHeight/strHeightMod come from the static_rune_race row; colors,
skills, powers and effects still load from the DB by rune id. A
static_rune_race comparator checks every field against a JSON-built Race.
Offline parity (scripts/p23.py, 26 rows + racebaseclass/hairstyle/beardstyle
vs the RACE runes): the 22 creation races match in every attribute, bonus,
startingPoints, token and base class. Differences:
- name: "Aelfborn, Male" -> "Aelfborn" on every row
- hair 0 dropped by the JSON on Aracoix M/F and Shade M/F (kept by the
empty-hair rule); beard 0 dropped on Shade M/F, Minotaur, Vampire F
- Minotaur hair 6958 -> 6598, Vampire M beard 5020170 -> 5020300
- 2018 Archon: startingPoints 0 -> 30, token 0 -> SBStringHash("Celestial"),
health 0 -> 20, stamina 0 -> 90
- 2019 Half-Giant-Old Man: str/dex/con/spi start and max, startingPoints
20 -> 15, health/mana/stamina 0 -> 10/5/70, baseClasses {} -> {Fighter}
- 2020/2021 CSR: stats 60/120 -> 40/100, startingPoints 0 -> 30, token 0 ->
SBStringHash("CSR"), health/mana/stamina 0 -> 40/40/10000
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
6.4 KiB
Java
157 lines
6.4 KiB
Java
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
// Magicbane Emulator Project © 2013 - 2026
|
|
// https://www.magicbane.com
|
|
|
|
package engine.parsers.cache;
|
|
|
|
import engine.gameManager.ConfigManager;
|
|
import engine.mbEnums;
|
|
import engine.objects.BaseClass;
|
|
import engine.objects.Race;
|
|
import engine.parsers.objects.RuneTemplate;
|
|
import org.pmw.tinylog.Logger;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Objects;
|
|
import java.util.function.Consumer;
|
|
|
|
// Dev-only check that compares DB-built objects with the cache JSON before a loader is switched.
|
|
// Enabled by the optional env var MB_PARITY_CHECK; not in the ConfigManager enum, which requires every entry.
|
|
|
|
public class ParityCheck {
|
|
|
|
private static final String FLAG_NAME = "MB_PARITY_CHECK";
|
|
private static final LinkedHashMap<String, Consumer<ParityCheck>> comparators = new LinkedHashMap<>();
|
|
|
|
private final String table;
|
|
private int comparedCount = 0;
|
|
private int differenceCount = 0;
|
|
private int missingCount = 0;
|
|
|
|
static {
|
|
register("static_rune_race", ParityCheck::compareRaces);
|
|
}
|
|
|
|
private ParityCheck(String table) {
|
|
this.table = table;
|
|
}
|
|
|
|
public static boolean isEnabled() {
|
|
return ConfigManager.configMap.getOrDefault(FLAG_NAME, "false").equalsIgnoreCase("true");
|
|
}
|
|
|
|
public static void register(String table, Consumer<ParityCheck> comparator) {
|
|
comparators.put(table, comparator);
|
|
}
|
|
|
|
public static void run() {
|
|
|
|
ParityCheck check;
|
|
|
|
for (String table : comparators.keySet()) {
|
|
check = new ParityCheck(table);
|
|
|
|
try {
|
|
comparators.get(table).accept(check);
|
|
} catch (Exception e) {
|
|
Logger.error("Parity: " + table + ": comparator failed: " + e);
|
|
}
|
|
|
|
Logger.info("Parity: " + table + ": " + check.comparedCount + " compared, "
|
|
+ check.differenceCount + " differences, " + check.missingCount + " missing in json");
|
|
}
|
|
}
|
|
|
|
// Returns false when the row has no JSON counterpart, so the comparator can skip its fields.
|
|
|
|
public boolean compareRow(int id, Object jsonObject) {
|
|
|
|
comparedCount++;
|
|
|
|
if (jsonObject == null) {
|
|
missingCount++;
|
|
Logger.warn("Parity: " + table + "/" + id + ": missing in json");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void compareField(int id, String field, Object dbValue, Object jsonValue) {
|
|
|
|
if (Objects.equals(dbValue, jsonValue))
|
|
return;
|
|
|
|
differenceCount++;
|
|
Logger.warn("Parity: " + table + "/" + id + "/" + field + ": db=" + dbValue + " json=" + jsonValue);
|
|
}
|
|
|
|
private static void compareRaces(ParityCheck check) {
|
|
|
|
Race race;
|
|
Race jsonRace;
|
|
RuneTemplate rune;
|
|
int id;
|
|
|
|
for (mbEnums.RaceType raceType : mbEnums.RaceType.values()) {
|
|
id = raceType.getRuneID();
|
|
race = Race.getRace(id);
|
|
|
|
if (race == null) {
|
|
Logger.warn("Parity: static_rune_race/" + id + ": not loaded from the db");
|
|
continue;
|
|
}
|
|
|
|
rune = RuneTemplate._runes.get(id);
|
|
|
|
if (rune != null && rune.rune_type != mbEnums.RuneType.RACE)
|
|
rune = null;
|
|
|
|
if (!check.compareRow(id, rune))
|
|
continue;
|
|
|
|
jsonRace = new Race(rune, race);
|
|
|
|
check.compareField(id, "name", race.getName(), jsonRace.getName());
|
|
check.compareField(id, "strStart", race.getStrStart(), jsonRace.getStrStart());
|
|
check.compareField(id, "strMin", race.getStrMin(), jsonRace.getStrMin());
|
|
check.compareField(id, "strMax", race.getStrMax(), jsonRace.getStrMax());
|
|
check.compareField(id, "dexStart", race.getDexStart(), jsonRace.getDexStart());
|
|
check.compareField(id, "dexMin", race.getDexMin(), jsonRace.getDexMin());
|
|
check.compareField(id, "dexMax", race.getDexMax(), jsonRace.getDexMax());
|
|
check.compareField(id, "conStart", race.getConStart(), jsonRace.getConStart());
|
|
check.compareField(id, "conMin", race.getConMin(), jsonRace.getConMin());
|
|
check.compareField(id, "conMax", race.getConMax(), jsonRace.getConMax());
|
|
check.compareField(id, "intStart", race.getIntStart(), jsonRace.getIntStart());
|
|
check.compareField(id, "intMin", race.getIntMin(), jsonRace.getIntMin());
|
|
check.compareField(id, "intMax", race.getIntMax(), jsonRace.getIntMax());
|
|
check.compareField(id, "spiStart", race.getSpiStart(), jsonRace.getSpiStart());
|
|
check.compareField(id, "spiMin", race.getSpiMin(), jsonRace.getSpiMin());
|
|
check.compareField(id, "spiMax", race.getSpiMax(), jsonRace.getSpiMax());
|
|
check.compareField(id, "token", race.getToken(), jsonRace.getToken());
|
|
check.compareField(id, "healthBonus", race.getHealthBonus(), jsonRace.getHealthBonus());
|
|
check.compareField(id, "manaBonus", race.getManaBonus(), jsonRace.getManaBonus());
|
|
check.compareField(id, "staminaBonus", race.getStaminaBonus(), jsonRace.getStaminaBonus());
|
|
check.compareField(id, "startingPoints", race.getStartingPoints(), jsonRace.getStartingPoints());
|
|
check.compareField(id, "hairStyles", race.getHairStyles(), jsonRace.getHairStyles());
|
|
check.compareField(id, "beardStyles", race.getBeardStyles(), jsonRace.getBeardStyles());
|
|
check.compareField(id, "baseClasses", getObjectIds(race.getValidBaseClasses()), getObjectIds(jsonRace.getValidBaseClasses()));
|
|
}
|
|
}
|
|
|
|
private static HashSet<Integer> getObjectIds(Iterable<BaseClass> baseClasses) {
|
|
|
|
HashSet<Integer> ids = new HashSet<>();
|
|
|
|
for (BaseClass baseClass : baseClasses)
|
|
ids.add(baseClass.getObjectUUID());
|
|
|
|
return ids;
|
|
}
|
|
}
|