Files
windroost/tools/fullgame/test_edict_rules.py
T
wushenghua 8062880b7d feat: edict descriptions become real global combat rules (stage D complete)
Continued PRODUCTION/51. Edicts were flat +3% numbers; their descriptions
(连战加速/持续伤害/能量/召唤/...) now drive actual global rules:

- edict_rules.py / .gd: 6 combat edicts rewrite EVERY visible hero's skills
  (疾风 cooldown x0.85, 守望 weakness, 烈焰 poison DoT, 影行 lowest-hp+crit,
  星辉 energy, 根脉 summon); 3 meta edicts (商路 econ / 远征 branches / 裂隙
  challenge affixes) honestly kept as out-of-combat rules, not faked into DPS.
- hero_skill_loader gained active_edicts param (identity preserved); game_root
  injects edicts alongside talents/growth on the live P3a path.
- test_edict_rules.py PASS 6 checks (each combat edict changes behaviour,
  rules mostly distinct, global across heroes, meta untouched, real battle
  outcome differs); check_edict_rules_parity.py PASS 7 cases python==gd.
- run_edict_rules_ui_test.sh PASS (real game_root): D01 shortens intervals
  [2,3,100,6]->[1.7,2.55,85,5.1]; D03 adds 18 poison events, skill events 19->36.
- 3 new gates; full P2_CHECKS_PASS (78 gates), identity preserved.

Edicts now differ mechanically from talents (global rule vs per-hero rewrite)
and from skills (rule hook vs archetype). Stage E (enemy/boss mechanics) remains.
prototype/ untracked.
2026-11-19 13:56:09 +08:00

110 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""Stage D: each combat edict must apply a distinct GLOBAL rule; meta edicts
must not be faked into damage numbers."""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "tools"))
sys.path.insert(0, str(Path(__file__).parent))
import edict_rules as ER
import hero_skill_loader as HSL
SKILLS = json.loads((ROOT / "data" / "hero_skills.json").read_text(encoding="utf-8"))
CONTENT = json.loads((ROOT / "data" / "full_game_content.json").read_text(encoding="utf-8"))
HERO_STATS = {h["id"]: h for h in CONTENT["heroes"]}
def check(cond, msg):
if not cond:
raise AssertionError(msg)
def sig(skills):
"""Behaviour signature of a skill list (intervals + effect types + target)."""
return [(s.get("interval"), s.get("target_mode", ""),
tuple(e["type"] for e in s["effects"])) for s in skills]
def with_edict(hero, eid):
base = HSL.build_skills([hero], SKILLS, HERO_STATS)
e_skills = HSL.build_skills([hero], SKILLS, HERO_STATS, active_edicts={eid: True})
return base, e_skills
def test_edict_integrity():
check(not ER.validate(), "9 edicts, 6 combat + 3 meta")
c = ER.classify({e: True for e in ER.EDICT_RULES})
check(len(c["combat"]) == 6 and len(c["meta"]) == 3, "classify 6/3")
pack = {e["id"] for e in CONTENT["edicts"]}
check(pack == set(ER.EDICT_RULES), "every pack edict has a rule definition")
def test_meta_not_faked():
base = HSL.build_skills(["H01"], SKILLS, HERO_STATS)
for eid in ("D07", "D08", "D09"):
out = HSL.build_skills(["H01"], SKILLS, HERO_STATS, active_edicts={eid: True})
check(sig(out) == sig(base), f"{eid} meta edict does not alter combat skills")
def test_each_combat_edict_changes_skills():
for eid in ("D01", "D02", "D03", "D04", "D05", "D06"):
base, e_skills = with_edict("H01", eid)
check(sig(base) != sig(e_skills), f"{eid} combat edict changes skill behaviour")
def test_distinct_edict_rules():
sigs = {}
for eid in ("D01", "D02", "D03", "D04", "D05", "D06"):
_, e = with_edict("H01", eid)
sigs[eid] = repr(sig(e))
check(len(set(sigs.values())) >= 5,
f"6 edicts should mostly differ: {[(k, v[:60]) for k, v in sigs.items()]}")
def test_global_across_heroes():
# An edict must affect every hero, not just one.
for hero in ("H01", "H05", "H02"):
base, e = with_edict(hero, "D03") # 烈焰: adds poison to all skills
for a, b in zip(base, e):
atypes = [x["type"] for x in a["effects"]]
btypes = [x["type"] for x in b["effects"]]
check(btypes.count("poison") > atypes.count("poison"),
f"D03 adds poison for {hero}")
def test_edict_changes_battle_outcome():
import mvp_validation_sim as sim
rules = sim.Rules(sim.read_json(ROOT / "data" / "mvp_battle_rules.json"))
def run(skills):
sc = {"id": "EDICT-TEST", "mode": "auto", "enemy_ids": ["E1"],
"visible_hero_ids": ["H05"], "roster_hero_ids": ["H05"],
"enemy_specs": {"E1": {"hp": 900.0, "armor": 1.0, "shield": 0.0,
"weak_tag": "click", "rebuild_at": [], "rebuild_amount": 0.0}},
"input_events": [], "timeout_seconds": 40.0, "hp_scale": 1.0,
"skills": skills}
r = sim.run_scenario(rules, sc, 10001, 40.0)
return (r["result"], round(r["duration_seconds"], 2),
sum(1 for e in r["event_log"] if e.get("type") == "skill_effect"))
base = HSL.build_skills(["H05"], SKILLS, HERO_STATS)
swift = HSL.build_skills(["H05"], SKILLS, HERO_STATS, active_edicts={"D01": True})
flame = HSL.build_skills(["H05"], SKILLS, HERO_STATS, active_edicts={"D03": True})
a, b, c = run(base), run(swift), run(flame)
check(a != b, f"疾风 edict changes battle: base={a} swift={b}")
check(a != c, f"烈焰 edict changes battle: base={a} flame={c}")
def main():
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for fn in fns:
fn()
print(f"EDICT_RULES_PASS {len(fns)} checks")
return 0
if __name__ == "__main__":
raise SystemExit(main())