Files
windroost/tools/fullgame/test_skill_runtime.py
T
wushenghua 16d3cbe911 feat: effect-primitive engine foundation (stage A of gameplay-depth goal)
Continued PRODUCTION/51. Built the ADR-008 effect-primitive system that turns
skills from damage numbers into real distinct combat effects:
- tools/fullgame/effects.py + GDScript effects.gd mirror: 16 primitives
  (damage/heal/shield/buff/debuff/stun/slow/poison/taunt/summon/cleanse/
  execute/chain/lifesteal/energy/reflect) with real battle semantics.
- test_effects.py PASS 9 checks (each primitive distinct + identity).
- check_effects_parity.py PASS 17 cases (python==gd).
- skill_runtime.py bridge: folds skill effects into per-tick battle state;
  test_skill_runtime.py PASS 7 checks proving >=4 skills give distinct outcomes.
- Identity invariant: absent skills -> zero change (all 64 gates green).

Next: wire skill_runtime into both battle sims (with parity + identity guard).
P2_CHECKS_PASS. prototype/ untracked.
2026-11-19 13:07:43 +08:00

125 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""Proof: different skills produce DIFFERENT battle outcomes (not all +DPS)."""
import sys
sys.path.insert(0, __import__("pathlib").Path(__file__).parent)
import skill_runtime as SR
def check(cond, msg):
if not cond:
raise AssertionError(msg)
def mk_enemies(hp=500.0):
return [{"id": "E1#1", "content_id": "E1", "hp": hp, "max_hp": hp,
"armor": 1.0, "shield": 0.0, "dead": False},
{"id": "E2#2", "content_id": "E2", "hp": hp, "max_hp": hp,
"armor": 1.0, "shield": 0.0, "dead": False}]
def run(skills, ticks=20, tick_s=0.5):
rt = SR.init_runtime({"skills": skills})
enemies = mk_enemies()
events = []
total_dmg = 0.0
for t in range(ticks):
time = t * tick_s
out = SR.tick(rt, enemies, time, tick_s, events)
total_dmg += out["extra_damage"]
return {"damage": total_dmg, "events": len(events),
"enemies": enemies, "state": rt["skill_state"]}
def test_identity_no_skills():
r = run([], ticks=10)
check(r["damage"] == 0.0 and r["events"] == 0, "no skills -> zero effect")
def test_damage_skill_deals_damage():
r = run([{"hero_id": "H1", "interval": 1.0,
"effects": [{"type": "damage", "value": 100}]}], ticks=20)
check(r["damage"] > 0, "damage skill deals damage")
check(r["events"] > 0, "damage skill logs events")
def test_execute_vs_damage_distinct():
# low-HP target, execute threshold 0.5 should kill instantly
rt = SR.init_runtime({"skills": [{"hero_id": "H1", "interval": 1.0,
"effects": [{"type": "execute", "threshold": 0.5}]}]})
enemies = [{"id": "E1#1", "content_id": "E1", "hp": 20.0, "max_hp": 100.0,
"armor": 1.0, "shield": 0.0, "dead": False}]
ev = []
SR.tick(rt, enemies, 0.0, 0.1, ev)
check(enemies[0]["dead"], "execute kills low-HP target")
# plain damage of 20 on same target does NOT kill a 20hp? it would; use small value
rt2 = SR.init_runtime({"skills": [{"hero_id": "H2", "interval": 1.0,
"effects": [{"type": "damage", "value": 5}]}]})
en2 = [{"id": "E1#1", "content_id": "E1", "hp": 20.0, "max_hp": 100.0,
"armor": 1.0, "shield": 0.0, "dead": False}]
SR.tick(rt2, en2, 0.0, 0.1, [])
check(not en2[0]["dead"], "small damage does not kill")
def test_poison_ticks_over_time():
r = run([{"hero_id": "H3", "interval": 0.0,
"effects": [{"type": "poison", "value": 20, "duration": 5.0}]}], ticks=10, tick_s=0.5)
# passive poison needs the debuff applied; simulate an init application
rt = SR.init_runtime({"skills": [{"hero_id": "H3", "interval": 99.0,
"effects": [{"type": "poison", "value": 20, "duration": 5.0}]}]})
enemies = mk_enemies()
ev = []
SR.tick(rt, enemies, 0.0, 0.5, ev) # applies poison via active fire
dmg2 = 0.0
for t in range(1, 10):
dmg2 += SR.tick(rt, enemies, t * 0.5, 0.5, ev)["extra_damage"]
check(dmg2 > 0, "poison keeps ticking after application")
def test_chain_hits_multiple_enemies():
rt = SR.init_runtime({"skills": [{"hero_id": "H4", "interval": 1.0,
"effects": [{"type": "chain", "value": 50, "jumps": 1}]}]})
enemies = mk_enemies()
ev = []
SR.tick(rt, enemies, 0.0, 0.1, ev)
dead_or_hurt = [e for e in enemies if e["hp"] < e["max_hp"]]
check(len(dead_or_hurt) >= 2, "chain hits primary + at least 1 extra enemy")
def test_buff_changes_damage_mult():
rt = SR.init_runtime({"skills": [{"hero_id": "H5", "interval": 1.0,
"effects": [{"type": "buff", "stat": "atk", "value": 0.5}]}]})
enemies = mk_enemies()
ev = []
before = SR.damage_mult(rt["skill_state"])
SR.tick(rt, enemies, 0.0, 0.1, ev)
after = SR.damage_mult(rt["skill_state"])
check(after > before, "buff raises ally damage multiplier")
def test_distinct_outcomes():
outcomes = {}
for prim, eff in [
("damage", {"type": "damage", "value": 100}),
("execute", {"type": "execute", "threshold": 0.5}),
("chain", {"type": "chain", "value": 50, "jumps": 1}),
("buff", {"type": "buff", "stat": "atk", "value": 0.5}),
("poison", {"type": "poison", "value": 10, "duration": 3.0}),
]:
r = run([{"hero_id": "H", "interval": 1.0, "effects": [eff]}], ticks=10)
outcomes[prim] = (round(r["damage"], 2), r["events"],
round(SR.damage_mult(r["state"]), 3))
check(len(set(outcomes.values())) >= 4,
f"distinct skills must yield >=4 distinct outcomes, got {outcomes}")
def main():
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for fn in fns:
fn()
print(f"SKILL_RUNTIME_PASS {len(fns)} checks")
return 0
if __name__ == "__main__":
raise SystemExit(main())