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

97 lines
3.8 KiB
GDScript

class_name TalentBehavior
extends RefCounted
## GDScript mirror of tools/fullgame/talent_behavior.py (Stage C). Maps talent
## behavior text to real skill-effect modifications. Parity gated.
const BEHAVIOR_MODS := {
"目标改为最低血量": {"target_mode": "lowest_hp"},
"穿透一个额外目标": {"pierce_extra": true},
"加一次弹射": {"chain_jumps": 1},
"溅射范围扩大": {"chain_jumps": 1},
"破甲叠层+1": {"armor_stack": 1.6},
"易伤窗口延长": {"debuff_duration": 1.6},
"持续时间延长": {"all_duration": 1.6},
"持续伤害叠层": {"poison_stack": 1.6},
"连击窗口延长": {"extra_hit": true},
"冷却缩短": {"interval": 0.75},
"点击暴击充能": {"energy": 0.2},
}
const META_BEHAVIORS := ["自动化档位+1", "解锁/转换/上限/替代规则"]
static func active_behaviors(hero_id: String, active_talents: Dictionary, talent_specs: Dictionary) -> Dictionary:
var combat: Array = []
var meta: Array = []
for tid in active_talents.keys():
if not bool(active_talents[tid]):
continue
var spec = talent_specs.get(str(tid))
if spec == null or str((spec as Dictionary).get("hero", "")) != hero_id:
continue
if not bool((spec as Dictionary).get("changes_behavior", false)):
continue
var b := str((spec as Dictionary).get("behavior", ""))
if META_BEHAVIORS.has(b):
meta.append(b)
elif BEHAVIOR_MODS.has(b):
combat.append(b)
return {"combat": combat, "meta": meta}
static func apply_behaviors(skills: Array, behaviors: Array) -> Array:
var out: Array = []
for sk0 in skills:
var sk: Dictionary = (sk0 as Dictionary).duplicate(true)
for b in behaviors:
var mod: Dictionary = BEHAVIOR_MODS.get(str(b), {})
if mod.is_empty():
continue
if mod.has("target_mode"):
sk["target_mode"] = mod["target_mode"]
if bool(mod.get("pierce_extra", false)):
var merged: Array = []
for e in sk["effects"]:
merged.append(e)
if str((e as Dictionary).get("type", "")) == "damage":
merged.append({"type": "chain", "value": float((e as Dictionary).get("value", 0.0)), "jumps": 1})
sk["effects"] = merged
if int(mod.get("chain_jumps", 0)) != 0:
for e in sk["effects"]:
var en: Dictionary = e
if str(en.get("type", "")) == "chain":
en["jumps"] = int(en.get("jumps", 2)) + int(mod["chain_jumps"])
if float(mod.get("armor_stack", 0.0)) > 0.0:
for e in sk["effects"]:
var en: Dictionary = e
if str(en.get("type", "")) == "debuff" and str(en.get("stat", "")) == "armor":
en["value"] = snappedf(float(en["value"]) * float(mod["armor_stack"]), 0.0001)
if float(mod.get("debuff_duration", 0.0)) > 0.0:
for e in sk["effects"]:
var en: Dictionary = e
if str(en.get("type", "")) == "debuff" and en.has("duration"):
en["duration"] = snappedf(float(en["duration"]) * float(mod["debuff_duration"]), 0.0001)
if float(mod.get("all_duration", 0.0)) > 0.0:
for e in sk["effects"]:
var en: Dictionary = e
if en.has("duration"):
en["duration"] = snappedf(float(en["duration"]) * float(mod["all_duration"]), 0.0001)
if float(mod.get("poison_stack", 0.0)) > 0.0:
for e in sk["effects"]:
var en: Dictionary = e
if str(en.get("type", "")) == "poison":
en["value"] = snappedf(float(en["value"]) * float(mod["poison_stack"]), 0.0001)
if bool(mod.get("extra_hit", false)):
var dmg: Array = []
for e in sk["effects"]:
if str((e as Dictionary).get("type", "")) == "damage":
dmg.append(e)
if not dmg.is_empty():
(sk["effects"] as Array).append((dmg[0] as Dictionary).duplicate())
if mod.has("interval"):
sk["interval"] = snappedf(float(sk["interval"]) * float(mod["interval"]), 0.0001)
if mod.has("energy"):
(sk["effects"] as Array).append({"type": "energy", "value": float(mod["energy"])})
out.append(sk)
return out