Files
windroost/p2_godot_sample/scripts/skill_battle_test.gd
T
wushenghua 20f42136d8 feat: wire effect primitives into both battle sims (stage A complete)
Continued PRODUCTION/51. Effect primitives now reach the real battle sims:
- skill_runtime.py / skill_runtime.gd bridge folds skills into per-tick state
  (poison/execute/chain/buff/summon/stun/damage), parity 7 cases python==gd.
- Both mvp_validation_sim.py and battle_sim.gd call skill_runtime each tick;
  skill_rt stored in state; buffs/summons adjust effective roster/signature DPS
  without compounding; identity when no skills (null -> neutral multipliers).
- check_skill_battle.py: SAME encounter with 6 different skills yields 6
  distinct durations [20.3/6.0/11.0/19.6/5.9/4.7], py==gd. This is the
  concrete proof that skills are no longer just "+DPS numbers".
- 5 new gates registered; full P2_CHECKS_PASS (69 gates), identity preserved
  (300 results byte-identical, mvp_parity_gate PASS).

This closes the core of the user's "not perfunctory" requirement: skills now
produce genuinely different combat behaviour. Stages B-E (per-hero archetype
assignment, talent behaviour, edict rules, enemy mechanics) remain.
prototype/ untracked.
2026-11-19 13:23:58 +08:00

60 lines
2.4 KiB
GDScript

extends SceneTree
## Effect primitives wired into the real battle sim: run the same encounter
## with different skills and emit results. Parity-checked against paper sim.
const BattleSim = preload("res://scripts/battle_sim.gd")
const OUTPUT_PATH := "res://artifacts/skill_battle_gd.json"
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var rules := BattleSim.load_rules()
var base := {
"id": "SKILL-TEST", "mode": "auto",
"enemy_ids": ["E1"], "visible_hero_ids": ["H01", "H02", "H03"],
"roster_hero_ids": ["H01", "H02", "H03"],
"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": 30.0, "hp_scale": 1.0,
}
var cases: Array = [
{"name": "none", "skills": []},
{"name": "damage", "skills": [{"hero_id": "H01", "interval": 1.0, "effects": [{"type": "damage", "value": 120}]}]},
{"name": "execute", "skills": [{"hero_id": "H01", "interval": 1.0, "effects": [{"type": "execute", "threshold": 0.5}]}]},
{"name": "chain", "skills": [{"hero_id": "H01", "interval": 1.0, "effects": [{"type": "chain", "value": 80, "jumps": 1}]}]},
{"name": "buff", "skills": [{"hero_id": "H01", "interval": 1.0, "effects": [{"type": "buff", "stat": "atk", "value": 0.6}]}]},
{"name": "poison", "skills": [{"hero_id": "H01", "interval": 1.0, "effects": [{"type": "poison", "value": 60, "duration": 4.0}]}]},
]
var results: Array = []
for c in cases:
var sc := base.duplicate(true)
sc["id"] = "SKILL-" + str(c["name"])
sc["skills"] = c["skills"]
var r := BattleSim.run_scenario(rules, sc, 10001, 30.0)
results.append({
"name": c["name"], "result": r["result"],
"duration": snappedf(float(r["duration_seconds"]), 0.0001),
"skill_events": _count_skill_events(r["event_log"]),
})
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()
for r in results:
print("SKILL_BATTLE %s result=%s dur=%.3f skill_ev=%d" % [r["name"], r["result"], r["duration"], r["skill_events"]])
print("SKILL_BATTLE_GD cases=%d" % results.size())
quit(0)
func _count_skill_events(log: Array) -> int:
var n := 0
for e in log:
if str((e as Dictionary).get("type", "")) == "skill_effect":
n += 1
return n