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

102 lines
3.4 KiB
GDScript

extends SceneTree
## Real-runtime Stage C proof: activating a hero's behavior talent in the live
## game shell changes the resulting battle (skills are rebuilt with the talent).
const OUTPUT_PATH := "res://artifacts/talent_behavior_ui_test.json"
const NODE := "R1-C01-N01"
const TALENT_ID := "T-H05-03" # H05 slot3: 冷却缩短
var _problems: Array = []
var _records: Array = []
func _init() -> void:
_run.call_deferred()
func _fail(msg: String) -> void:
_problems.append(msg)
func _run_battle(shell: GameRoot, talents: Dictionary) -> Dictionary:
var profile := shell.get_profile()
profile["gold"] = 0
profile["crystal"] = 0
profile["hero_levels"] = {}
profile["unlocked_heroes"] = ["H05"]
profile["completed_nodes"] = []
profile["claimed_rewards"] = []
profile["talents"] = talents.duplicate()
shell.start_node(NODE)
await process_frame
await process_frame
var battle := shell.get_battle()
if battle == null:
_fail("no battle instance")
return {}
battle.set_process(false)
var guard := 0
while not battle.finished and guard < 600:
battle.advance_ticks(1)
guard += 1
var skill_ev := 0
var ratio_sum := 0.0
for e in battle.state.get("event_log", []):
if str((e as Dictionary).get("type", "")) == "skill_effect":
skill_ev += 1
# Inspect the injected skill intervals to prove the talent rewrote them.
var intervals: Array = []
for s in battle.state.get("skill_rt", {}).get("skills", []):
intervals.append(float((s as Dictionary).get("interval", 0.0)))
return {"result": str(battle.state.get("result", "")),
"duration": snappedf(float(battle.state.get("duration_seconds", 0.0)), 0.0001),
"skill_events": skill_ev, "intervals": intervals}
func _run() -> void:
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root.add_child(shell)
await process_frame
await process_frame
var off := await _run_battle(shell, {})
var on := await _run_battle(shell, {TALENT_ID: true})
_records.append({"mode": "off", "data": off})
_records.append({"mode": "on", "data": on})
if off.is_empty() or on.is_empty():
_fail("missing battle result")
else:
var off_sig := "%s|%.4f|%d" % [off["result"], off["duration"], off["skill_events"]]
var on_sig := "%s|%.4f|%d" % [on["result"], on["duration"], on["skill_events"]]
if off_sig == on_sig:
_fail("cooldown talent must change battle: off=%s on=%s" % [off_sig, on_sig])
# And the injected intervals must actually be shorter with the talent.
if not off["intervals"].is_empty() and not on["intervals"].is_empty():
var off_max: float = 0.0
var on_max: float = 0.0
for x in off["intervals"]:
off_max = maxf(off_max, float(x))
for x in on["intervals"]:
on_max = maxf(on_max, float(x))
if on_max >= off_max:
_fail("cooldown talent must shorten skill intervals: off=%f on=%f" % [off_max, on_max])
var payload := {"records": _records, "problems": _problems}
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(payload, "\t", true))
f.close()
for rec in _records:
print("TALENT_UI %s %s" % [rec["mode"], JSON.stringify(rec["data"])])
if _problems.is_empty():
print("TALENT_UI_PASS behavior talent changes real runtime battle")
else:
print("TALENT_UI_FAIL %d problem(s)" % _problems.size())
for p in _problems:
print(" " + p)
quit(0 if _problems.is_empty() else 1)