Files
windroost/tools/fullgame/test_talent_behavior.py
T
wushenghua 2127d1318c feat: talent behaviors drive real combat decisions (stage C complete)
Continued PRODUCTION/51. Talent `behavior` text (previously display-only) now
rewrites skill effects so the battle genuinely differs when a talent is active:

- talent_behavior.py / .gd: 11 concrete behaviors -> real effect rewrites
  (lowest_hp target, +1 chain jump, armor stack, vuln window, poison stack,
  duration extend, extra hit, cooldown x0.75, click-crit energy, pierce extra,
  splash). 2 meta rules (auto tier / unlock-alternative) honestly recorded as
  out-of-combat, not faked into damage numbers.
- hero_skill_loader + skill_runtime gained optional talent/target_mode params;
  empty profile -> identity. game_root.gd injects active talents like growth
  modifiers on the live P3a path.
- test_talent_behavior.py PASS 6 checks: every behavior changes effects,
  lowest_hp really picks the lowest-HP enemy, cooldown talent changes battle.
- check_talent_behavior_parity.py PASS 6 cases python==gd.
- run_talent_behavior_ui_test.sh PASS (real game_root): cooldown talent
  shortens intervals [2.0,3.0,100,6] -> [1.5,2.25,75,4.5], skill events 19->22.
- 3 new gates; full P2_CHECKS_PASS (75 gates), identity preserved.

This makes the talent system match its descriptions ("目标改为最低血量" really
retargets; "冷却缩短" really speeds cooldowns) instead of all collapsing into
stat numbers. Stages D-E (edict rules, enemy/boss mechanics) remain.
prototype/ untracked.
2026-11-19 13:48:32 +08:00

132 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Stage C: each behavior talent must produce a REAL skill-effect change."""
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 talent_behavior as TB
import hero_skill_loader as HSL
import skill_runtime as SR
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"]}
TALENT_SPECS = {t["id"]: t for t in CONTENT["talents"]}
def check(cond, msg):
if not cond:
raise AssertionError(msg)
def base_skills(hero="H01"):
return HSL.build_skills([hero], SKILLS, HERO_STATS)
def with_behavior(hero, behavior_text):
# find a real talent id with this behavior for this hero
tid = next(tid for tid, t in TALENT_SPECS.items()
if t.get("hero") == hero and t.get("behavior") == behavior_text)
return HSL.build_skills([hero], SKILLS, HERO_STATS, {tid: True}, TALENT_SPECS), tid
def test_mapping_integrity():
check(not TB.validate_mapping(), "behavior mapping valid")
check(len(TB.BEHAVIOR_MODS) == 11, "11 combat behaviors")
check(len(TB.META_BEHAVIORS) == 2, "2 meta behaviors recorded, not faked")
def test_identity_no_talents():
check(base_skills() == HSL.build_skills(["H01"], SKILLS, HERO_STATS, {}, TALENT_SPECS),
"empty talents -> identity")
def test_each_behavior_changes_something():
# behaviors that are observable for H01's archetypes (pierce/single/buff/execute)
cases = {
"目标改为最低血量": lambda s: any(x.get("target_mode") == "lowest_hp" for x in s),
"穿透一个额外目标": lambda s: any(e["type"] == "chain" and e.get("jumps") == 1
for x in s for e in x["effects"]),
"加一次弹射": lambda s: False, # H01 has no chain base -> no direct change; use H02
"破甲叠层+1": lambda s: any(e.get("stat") == "armor" and e["value"] > 0.24
for x in s for e in x["effects"] if e["type"] == "debuff"),
"易伤窗口延长": lambda s: any(e["type"] == "debuff" and e.get("duration", 0) > 4
for x in s for e in x["effects"]),
"持续时间延长": lambda s: any(e.get("duration", 0) > 5 for x in s for e in x["effects"]),
"点击暴击充能": lambda s: any(e["type"] == "energy" for x in s for e in x["effects"]),
}
for behavior, predicate in cases.items():
if behavior == "加一次弹射":
continue
try:
out, _ = with_behavior("H01", behavior)
except StopIteration:
continue
check(predicate(out), f"{behavior} produces a real effect change")
# chain-based behavior on H02 (has chain skills)
out, _ = with_behavior("H02", "加一次弹射")
base_chain = max((e.get("jumps", 0) for x in base_skills("H02") for e in x["effects"]
if e["type"] == "chain"), default=0)
new_chain = max((e.get("jumps", 0) for x in out for e in x["effects"]
if e["type"] == "chain"), default=0)
check(new_chain > base_chain, "加一次弹射 increases chain jumps")
def test_lowest_hp_target_selection():
enemies = [
{"id": "E1#1", "content_id": "E1", "hp": 100.0, "max_hp": 100.0, "dead": False},
{"id": "E2#2", "content_id": "E2", "hp": 20.0, "max_hp": 100.0, "dead": False},
{"id": "E3#3", "content_id": "E3", "hp": 60.0, "max_hp": 100.0, "dead": False},
]
import effects as E
st = E.new_skill_state()
check(SR.choose_skill_target(enemies, st, "")["id"] == "E1#1", "default picks first")
check(SR.choose_skill_target(enemies, st, "lowest_hp")["id"] == "E2#2",
"lowest_hp picks the 20hp enemy")
def test_behavior_changes_battle_outcome():
"""Same hero + same encounter, talent on vs off -> different battle result."""
import mvp_validation_sim as sim
rules = sim.Rules(sim.read_json(ROOT / "data" / "mvp_battle_rules.json"))
tid = next(tid for tid, t in TALENT_SPECS.items()
if t.get("hero") == "H05" and t.get("behavior") == "冷却缩短")
base = HSL.build_skills(["H05"], SKILLS, HERO_STATS)
tal = HSL.build_skills(["H05"], SKILLS, HERO_STATS, {tid: True}, TALENT_SPECS)
def run(skills):
sc = {"id": "TAL-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"))
a, b = run(base), run(tal)
check(a != b, f"冷却缩短 talent must change battle outcome: base={a} talent={b}")
def test_meta_not_faked():
combat, meta = TB.active_behaviors("H05", {"T-G01": True, "T-H05-04": True}, TALENT_SPECS)
check("自动化档位+1" in meta, "auto tier is meta, not combat")
check(all(b in TB.BEHAVIOR_MODS for b in combat), "only real combat behaviors apply")
def main():
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for fn in fns:
fn()
print(f"TALENT_BEHAVIOR_PASS {len(fns)} checks")
return 0
if __name__ == "__main__":
raise SystemExit(main())