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.
132 lines
5.6 KiB
Python
132 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Runtime bridge: fold effect primitives into the battle sim per tick.
|
|
|
|
Both the Python paper sim (mvp_validation_sim.py) and the GDScript battle_sim.gd
|
|
call the mirrored logic here. Identity invariant: skills absent/empty -> no
|
|
change to any battle metric (all existing gates stay byte-identical).
|
|
|
|
A skill: {hero_id, interval, effects:[{type, value, duration, ...}]}
|
|
- interval <= 0 => passive (fires every tick via tick_effects only)
|
|
- interval > 0 => active (fires its effects every `interval` seconds)
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
import effects as E
|
|
|
|
|
|
def init_runtime(scenario: Dict[str, Any]) -> Dict[str, Any]:
|
|
skills = list(scenario.get("skills", []) or [])
|
|
return {
|
|
"skills": skills,
|
|
"skill_state": E.new_skill_state(),
|
|
"skill_timers": {str(s.get("hero_id", i)): 0.0 for i, s in enumerate(skills)},
|
|
}
|
|
|
|
|
|
def choose_skill_target(enemies: List[Dict[str, Any]], skill_state: Dict[str, Any],
|
|
target_mode: str = "") -> Optional[Dict[str, Any]]:
|
|
"""Taunt overrides; `lowest_hp` (Stage C talent) picks the lowest-HP living
|
|
enemy; otherwise first alive. Returns None if nothing alive."""
|
|
alive = [e for e in enemies if not e.get("dead")]
|
|
if not alive:
|
|
return None
|
|
taunt = str(skill_state.get("taunt_target", ""))
|
|
if taunt:
|
|
for e in alive:
|
|
if e["id"] == taunt or e["content_id"] == taunt:
|
|
return e
|
|
if target_mode == "lowest_hp":
|
|
return min(alive, key=lambda e: float(e["hp"]))
|
|
return alive[0]
|
|
|
|
|
|
def apply_damage_to_enemy(enemies, target, gross, skill_state) -> float:
|
|
"""Skill damage uses a simple flat reduction by armor (mirrors apply_damage's
|
|
armour factor but ignores weakness, since skills carry their own semantics).
|
|
Returns actual hp damage dealt."""
|
|
armor = float(target.get("armor", 1.0))
|
|
factor = 1.0 / (1.0 + max(0.0, armor) * 0.18)
|
|
dmg = max(0.0, float(gross) * factor)
|
|
# shield absorbs first
|
|
shield = float(target.get("shield", 0.0))
|
|
absorbed = min(shield, dmg)
|
|
target["shield"] = shield - absorbed
|
|
hp_dmg = dmg - absorbed
|
|
target["hp"] = max(0.0, float(target["hp"]) - hp_dmg)
|
|
if hp_dmg > 0.0 or absorbed > 0.0:
|
|
# lifesteal returns a fraction as an ally shield pool
|
|
ls = float(skill_state.get("lifesteal_pct", 0.0))
|
|
if ls > 0.0:
|
|
skill_state["ally_shield"] = float(skill_state.get("ally_shield", 0.0)) + dmg * ls
|
|
return hp_dmg
|
|
|
|
|
|
def tick(rt: Dict[str, Any], enemies: List[Dict[str, Any]], time: float,
|
|
tick_seconds: float, events: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
"""Run one tick of skill effects. Returns aggregate deltas for the sim:
|
|
{extra_damage, killed, effect_events}. Mutates enemies + skill_state.
|
|
`events` is the sim's event_log (appended for observability)."""
|
|
skills = rt.get("skills", [])
|
|
st = rt["skill_state"]
|
|
if not skills:
|
|
return {"extra_damage": 0.0, "killed": 0, "effect_events": 0}
|
|
|
|
out = {"extra_damage": 0.0, "killed": 0, "effect_events": 0}
|
|
# Passive poison tick always applies when any poison debuff is active.
|
|
passive = E.tick_effects(st, tick_seconds)
|
|
for eid, amount in passive["poison_damage"].items():
|
|
for e in enemies:
|
|
if e["id"] == eid and not e.get("dead"):
|
|
dealt = apply_damage_to_enemy(enemies, e, amount, st)
|
|
out["extra_damage"] += dealt
|
|
break
|
|
|
|
timers = rt["skill_timers"]
|
|
for i, sk in enumerate(skills):
|
|
interval = float(sk.get("interval", 0.0))
|
|
if interval <= 0.0:
|
|
continue # passive-only skill (effects applied at init if needed)
|
|
hid = str(sk.get("hero_id", i))
|
|
if time + 1e-9 < float(timers.get(hid, 0.0)):
|
|
continue
|
|
timers[hid] = time + interval
|
|
target = choose_skill_target(enemies, st, str(sk.get("target_mode", "")))
|
|
ctx = {"enemies": enemies, "target_id": target["id"] if target else "",
|
|
"tick_seconds": tick_seconds}
|
|
for eff in sk.get("effects", []):
|
|
res = E.apply_effect(st, eff, ctx)
|
|
out["effect_events"] += 1
|
|
# fold direct damage onto chosen target
|
|
if res.get("damage", 0.0) > 0.0 and not res.get("meta", {}).get("executed"):
|
|
if target:
|
|
out["extra_damage"] += apply_damage_to_enemy(enemies, target, res["damage"], st)
|
|
# chain targets already listed in meta; hit them too
|
|
for tid in res.get("meta", {}).get("chain_targets", []):
|
|
for e in enemies:
|
|
if e["id"] == tid and not e.get("dead") and e is not target:
|
|
out["extra_damage"] += apply_damage_to_enemy(
|
|
enemies, e, float(eff.get("value", 0.0)), st)
|
|
break
|
|
# execute kills
|
|
for kid in res.get("killed_ids", []):
|
|
for e in enemies:
|
|
if e["id"] == kid and not e.get("dead"):
|
|
out["extra_damage"] += float(e["hp"])
|
|
e["hp"] = 0.0
|
|
e["dead"] = True
|
|
out["killed"] += 1
|
|
break
|
|
events.append({"time": round(time, 4), "type": "skill_effect",
|
|
"hero_id": hid, "primitive": res.get("primitive", "")})
|
|
return out
|
|
|
|
|
|
def damage_mult(st: Dict[str, Any]) -> float:
|
|
return E.ally_damage_mult(st)
|
|
|
|
|
|
def extra_dps(st: Dict[str, Any]) -> float:
|
|
return E.extra_dps(st)
|