Files
windroost/p2_godot_sample/scripts/effects_parity_test.gd
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

52 lines
1.8 KiB
GDScript

extends SceneTree
## Emits Effects (GDScript) outputs for parity comparison with effects.py.
const Effects = preload("res://scripts/effects.gd")
const OUTPUT_PATH := "res://artifacts/effects_parity_gd.json"
func _init() -> void:
_run.call_deferred()
func _mk_enemies() -> Array:
return [
{"id": "E1#1", "content_id": "E1", "hp": 100.0, "max_hp": 100.0, "dead": false},
{"id": "E2#2", "content_id": "E2", "hp": 30.0, "max_hp": 100.0, "dead": false},
{"id": "E3#3", "content_id": "E3", "hp": 80.0, "max_hp": 100.0, "dead": false},
]
func _run() -> void:
var results: Array = []
# For every primitive, apply once then capture full state + apply output.
for prim in Effects.PRIMITIVES:
var s := Effects.new_skill_state()
var effect := {"type": prim, "value": 5.0, "duration": 1.0, "stat": "atk",
"threshold": 0.35, "jumps": 2}
var ctx := {"enemies": _mk_enemies(), "target_id": "E2#2", "tick_seconds": 0.1}
var out := Effects.apply_effect(s, effect, ctx)
var tick := Effects.tick_effects(s, 0.1)
results.append({
"primitive": prim, "apply": out, "tick": tick, "state": s,
"ally_damage_mult": Effects.ally_damage_mult(s),
"ally_incoming_mult": Effects.ally_incoming_mult(s),
"extra_dps": Effects.extra_dps(s),
})
# Identity case
var s0 := Effects.new_skill_state()
results.append({"primitive": "__identity__", "state": s0,
"ally_damage_mult": Effects.ally_damage_mult(s0),
"ally_incoming_mult": Effects.ally_incoming_mult(s0),
"extra_dps": Effects.extra_dps(s0), "tick": Effects.tick_effects(s0, 0.1)})
var dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(dir)
var f := FileAccess.open(OUTPUT_PATH, FileAccess.WRITE)
if f != null:
f.store_string(JSON.stringify({"results": results}, "\t", true))
f.close()
print("EFFECTS_PARITY_GD cases=%d" % results.size())
quit(0)