Files
windroost/tools/fullgame/validate_content.py
T
wushenghua 3e8346da94 content: port full-game generator, QA and enemy/hero contracts
Source-bound generator/validator/QA plus WR328 enemy weak-tag and WR330 hero
unlock checkers. UI text is a 3-way merge: source event short keys and content
keys added, all HEAD S3/S4/S5/S6 keys retained. No runtime/shell code ported.
2026-11-29 10:10:38 +08:00

162 lines
6.5 KiB
Python

#!/usr/bin/env python3
"""Validate the full-game content pack (L0 gate).
Checks:
- counts match design ceilings (CONTENT_PLAN)
- IDs unique per family and match the ID grammar
- every reference resolves (node -> enemy/boss/reward; talent -> hero; event -> chapter)
- every node has a type from the design's 10 types
- every chapter has 10 nodes, every region 12 chapters
- no raw callables / NaN / non-serializable values
Usage: python3 tools/fullgame/validate_content.py [path]
"""
from __future__ import annotations
import json
import math
import re
import sys
from pathlib import Path
from typing import Any, Dict, List, Set
ROOT = Path(__file__).resolve().parents[2]
DEFAULT = ROOT / "data" / "full_game_content.json"
# WR-151: verify every main-line battle row carries the canonical CH multiplier.
# Same helper/mode as generate_content.py; ch_curve.py is the only formula source.
from generate_content import CH_CURVE_MODE, node_curve_index
from ch_curve import node_hp as ch_node_hp
EXPECTED = {"heroes":54,"talents":245,"enemies":120,"bosses":20,"nodes":600,
"events":60,"gear":120,"relics":60,"oaths":26,"edicts":9,"records":167,
"partners":5,"market":6}
def ids(rows: List[Dict[str, Any]]) -> Set[str]:
return {str(r["id"]) for r in rows}
def main() -> int:
path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT
if not path.exists():
print(f"FULL_CONTENT_FAIL missing {path}")
return 1
pack = json.loads(path.read_text(encoding="utf-8"))
problems: List[str] = []
# counts
counts = pack.get("counts", {})
for family, expected in EXPECTED.items():
rows = pack.get(family, [])
if len(rows) != expected:
problems.append(f"{family}: {len(rows)} rows, expected {expected}")
if counts.get(family) != len(rows):
problems.append(f"{family}: counts table says {counts.get(family)}, rows {len(rows)}")
families = {f: pack.get(f, []) for f in EXPECTED}
# unique IDs
for family, rows in families.items():
all_ids = [str(r.get("id","")) for r in rows]
if len(all_ids) != len(set(all_ids)):
problems.append(f"{family}: duplicate IDs")
if any(not i for i in all_ids):
problems.append(f"{family}: empty ID")
hero_ids = ids(families["heroes"])
enemy_ids = ids(families["enemies"])
boss_ids = ids(families["bosses"])
event_ids = ids(families["events"])
node_ids = ids(families["nodes"])
# Every generated hero must unlock from an authored world node. Runtime
# settlement code matches this ID exactly, so an R6+ unlock would be
# permanently unreachable while the authored world only contains R1-R5.
for hero in families["heroes"]:
unlock = str(hero.get("unlock", ""))
if unlock not in node_ids:
problems.append(f"hero {hero.get('id', '<unknown>')} -> unknown unlock node {unlock}")
# references
for t in families["talents"]:
if "hero" in t and t["hero"] not in hero_ids and not str(t["id"]).startswith("T-G"):
problems.append(f"talent {t['id']} -> unknown hero {t['hero']}")
for n in families["nodes"]:
for wave in n.get("waves", []):
for e in wave:
if e not in enemy_ids and e not in boss_ids:
problems.append(f"node {n['id']} -> unknown enemy/boss {e}")
if n.get("boss") and n["boss"] not in boss_ids:
problems.append(f"node {n['id']} -> unknown boss {n['boss']}")
for ev in families["events"]:
ck = ev["chapter"]
if not any(n["chapter"] == ck for n in families["nodes"]):
problems.append(f"event {ev['id']} -> unknown chapter {ck}")
# structure: 5 regions x 12 chapters x 10 nodes
from collections import Counter
per_chapter = Counter(n["chapter"] for n in families["nodes"])
for ck, c in per_chapter.items():
if c != 10:
problems.append(f"chapter {ck}: {c} nodes, expected 10")
if len(per_chapter) != 60:
problems.append(f"chapters: {len(per_chapter)}, expected 60")
per_region = Counter(n["region"] for n in families["nodes"])
if sorted(per_region.keys()) != ["R1","R2","R3","R4","R5"]:
problems.append(f"regions: {sorted(per_region.keys())}")
# allowed node types
allowed_types = {"normal","event","shop","elite","trial","supply","boss"}
for n in families["nodes"]:
if n["type"] not in allowed_types:
problems.append(f"node {n['id']}: unknown type {n['type']}")
# WR-151: CH hp_scale parity on main-line battle nodes (normal/elite/boss).
hp_scale_covered = 0
for n in families["nodes"]:
idx = node_curve_index(int(str(n["region"])[1:]),
int(str(n["chapter"]).split("-C")[1]),
int(n["index"]))
expected = ch_node_hp(idx, 600, CH_CURVE_MODE)
if n["type"] in ("normal", "elite", "boss"):
hp_scale_covered += 1
if "hp_scale" not in n:
problems.append(f"node {n['id']}: missing hp_scale")
continue
got = float(n["hp_scale"])
if abs(got - expected) > max(1e-9, abs(expected) * 1e-12):
problems.append(f"node {n['id']}: hp_scale {got} != ch_curve {expected}")
if not n.get("waves"):
problems.append(f"node {n['id']}: battle node has empty waves")
elif "hp_scale" in n:
# event/shop/supply (empty waves) and trial must stay untouched.
problems.append(f"node {n['id']}: unexpected hp_scale on {n['type']}")
if hp_scale_covered != 360:
problems.append(f"hp_scale coverage {hp_scale_covered}, expected 360")
# no non-finite numbers anywhere
def walk(o: Any, where: str) -> None:
if isinstance(o, float) and not math.isfinite(o):
problems.append(f"non-finite number at {where}")
elif isinstance(o, dict):
for k, v in o.items(): walk(v, f"{where}.{k}")
elif isinstance(o, list):
for i, v in enumerate(o): walk(v, f"{where}[{i}]")
walk(pack, "pack")
if problems:
print(f"FULL_CONTENT_FAIL {len(problems)} problem(s)")
for p in problems[:40]:
print(" " + p)
if len(problems) > 40:
print(f" ... {len(problems)-40} more")
return 1
print(f"FULL_CONTENT_PASS {len(families)} families, "
f"{len(families['nodes'])} nodes, all references resolve, "
f"CH hp_scale {hp_scale_covered}/360 ({CH_CURVE_MODE})")
return 0
if __name__ == "__main__":
raise SystemExit(main())