Defer _refresh_side/_side_result_modal out of the Button.pressed signal so _clear_children no longer frees the emitting button mid-emission (SIGSEGV). Additive v7 profile book, explicit CH->WR adapter, Python/GD parity, real ScreenTouch and save-corruption gates.
113 lines
5.0 KiB
Python
113 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Load stage-B hero skills and turn them into runtime `skills` for the sim.
|
|
|
|
`hero_skills.json` stores each hero's 4 skills as archetype + effect-primitive
|
|
definitions with *coefficient* values (fractions of hero power). This loader
|
|
scales damage-like values by the hero's base DPS so skills land in the same
|
|
damage units as the battle sim, then maps slots to firing intervals.
|
|
|
|
Mirrored by p2_godot_sample/scripts/hero_skill_loader.gd (parity gated).
|
|
Identity: hero_ids empty -> no skills -> sim unchanged.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
SLOT_KEYS = ("a1", "a2", "passive", "ultimate")
|
|
SLOT_INTERVALS = {"a1": 2.0, "a2": 3.0, "passive": 100.0, "ultimate": 6.0}
|
|
DAMAGE_LIKE = {"damage", "chain", "shield", "heal", "summon", "poison"}
|
|
|
|
|
|
def build_skills(
|
|
hero_ids: List[str],
|
|
hero_skills_data: Dict[str, Any],
|
|
hero_stats: Dict[str, Any],
|
|
active_talents: Dict[str, Any] | None = None,
|
|
talent_specs: Dict[str, Any] | None = None,
|
|
active_edicts: Dict[str, Any] | None = None,
|
|
active_relics: Dict[str, Any] | None = None,
|
|
active_oaths: Dict[str, Any] | None = None,
|
|
hero_levels: Dict[str, Any] | None = None,
|
|
gild_levels: Dict[str, Any] | None = None,
|
|
) -> List[Dict[str, Any]]:
|
|
"""Return the runtime `skills` array for the given visible hero ids.
|
|
|
|
- coefficient `value` for damage-like primitives is multiplied by hero base_dps
|
|
- `duration`/`threshold`/`jumps` are left untouched (they are absolute)
|
|
- passive fires once at t=0 (interval 100s > any battle), actives repeat
|
|
- active_talents/talent_specs (Stage C): when supplied, each hero's active
|
|
`changes_behavior` talents rewrite skill effects (target_mode, chain jumps,
|
|
intervals, poison stacks, ...). Absent -> identity.
|
|
- hero_levels (S8): when supplied, adapted heroes H07-H09 take their base
|
|
DPS from the CH source adapter at that level. Absent -> initial_level=1.
|
|
All other heroes keep the frozen product literal (H01-H06 unchanged).
|
|
- gild_levels (S4): CH-source per-hero gild multiplier 1 + 0.5 * level.
|
|
Absent/empty -> identity; no WR hero value is rebalanced.
|
|
"""
|
|
import ch_hero_adapter as CHA
|
|
import talent_behavior as TB
|
|
skills: List[Dict[str, Any]] = []
|
|
heroes = hero_skills_data.get("heroes", {})
|
|
for hid0 in hero_ids:
|
|
hid = str(hid0)
|
|
slots = heroes.get(hid)
|
|
if slots is None:
|
|
continue
|
|
if CHA.applies_to(hid):
|
|
raw_level = (hero_levels or {}).get(hid)
|
|
dps = CHA.base_dps(hid, int(raw_level) if raw_level is not None else None)
|
|
else:
|
|
dps = float(hero_stats.get(hid, {}).get("base_dps", 8.0))
|
|
# S4: CH game_state.gd gild_multiplier(hero) = 1 + 0.5 * levels[hero].
|
|
# Empty/absent map is identity, so all existing fixtures stay unchanged.
|
|
if gild_levels:
|
|
import ch_relic_gild as CRG
|
|
dps = round(dps * CRG.gild_multiplier(gild_levels, hid), 4)
|
|
hero_skills = []
|
|
for slot in SLOT_KEYS:
|
|
sk = slots.get(slot)
|
|
if sk is None:
|
|
continue
|
|
effects = []
|
|
for e in sk.get("effects", []):
|
|
e2 = dict(e)
|
|
if e2.get("type") in DAMAGE_LIKE and isinstance(e2.get("value"), (int, float)):
|
|
e2["value"] = round(float(e2["value"]) * dps, 4)
|
|
effects.append(e2)
|
|
hero_skills.append({
|
|
"hero_id": f"{hid}:{slot}",
|
|
"interval": SLOT_INTERVALS[slot],
|
|
"effects": effects,
|
|
"archetype": sk.get("archetype", ""),
|
|
})
|
|
# Stage C: rewrite this hero's skills from active behavior talents.
|
|
if active_talents and talent_specs:
|
|
combat, _meta = TB.active_behaviors(hid, active_talents, talent_specs)
|
|
if combat:
|
|
hero_skills = TB.apply_behaviors(hero_skills, combat)
|
|
# Stage D: active combat edicts apply GLOBAL rules to every hero's skills
|
|
# (cooldown speed, DoT, energy, summon, lowest-hp targeting); meta edicts
|
|
# are economy/progression rules and are not faked into damage.
|
|
if active_edicts:
|
|
import edict_rules as ER
|
|
hero_skills = ER.apply(hero_skills, active_edicts, dps)
|
|
# Stage F: active combat relics add their distinct effects to the a1 slot
|
|
# (meta relics are recorded, not faked into combat).
|
|
if active_relics:
|
|
import relic_effects as RE
|
|
hero_skills = RE.apply(hero_skills, active_relics, dps)
|
|
# Stage G: rebuild-retained oaths apply directional combat rules.
|
|
if active_oaths:
|
|
import oath_rules as OR
|
|
hero_skills = OR.apply(hero_skills, active_oaths, dps)
|
|
skills.extend(hero_skills)
|
|
return skills
|
|
|
|
|
|
def archetype_summary(skills: List[Dict[str, Any]]) -> Dict[str, int]:
|
|
out: Dict[str, int] = {}
|
|
for s in skills:
|
|
a = s.get("archetype", "")
|
|
out[a] = out.get(a, 0) + 1
|
|
return out
|