Files
windroost/p2_godot_sample/scripts/hero_skill_loader.gd
T
wushenghua dff581fdd3 S4: source-bound CH relic/gild book with lifecycle-safe market touch
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.
2026-11-29 08:24:27 +08:00

114 lines
4.3 KiB
GDScript

class_name HeroSkillLoader
extends RefCounted
## GDScript mirror of tools/fullgame/hero_skill_loader.py. Turns stage-B hero
## skills (coefficients) into runtime `skills` scaled by hero base DPS.
## Parity gated against the Python loader.
const SLOT_KEYS := ["a1", "a2", "passive", "ultimate"]
const SLOT_INTERVALS := {"a1": 2.0, "a2": 3.0, "passive": 100.0, "ultimate": 6.0}
const DAMAGE_LIKE := ["damage", "chain", "shield", "heal", "summon", "poison"]
const SKILLS_PATH := "res://data/hero_skills.json"
const CONTENT_PATH := "res://data/full_game_content.json"
const TalentBehavior = preload("res://scripts/talent_behavior.gd")
const EdictRules = preload("res://scripts/edict_rules.gd")
const RelicEffects = preload("res://scripts/relic_effects.gd")
const OathRules = preload("res://scripts/oath_rules.gd")
const ChHeroAdapter = preload("res://scripts/ch_hero_adapter.gd")
const ChRelicGild = preload("res://scripts/ch_relic_gild.gd")
static func _read(path: String) -> Dictionary:
var f := FileAccess.open(path, FileAccess.READ)
if f == null:
push_error("hero_skill_loader: cannot open " + path)
return {}
var parsed = JSON.parse_string(f.get_as_text())
f.close()
return parsed if parsed is Dictionary else {}
static func load_skill_data() -> Dictionary:
return _read(SKILLS_PATH)
static func load_hero_stats() -> Dictionary:
var pack := _read(CONTENT_PATH)
var out := {}
for h in pack.get("heroes", []):
var hd: Dictionary = h
out[str(hd.get("id", ""))] = hd
return out
static func build_skills(hero_ids: Array, skill_data: Dictionary, hero_stats: Dictionary,
active_talents: Dictionary = {}, talent_specs: Dictionary = {},
active_edicts: Dictionary = {}, active_relics: Dictionary = {},
active_oaths: Dictionary = {}, hero_levels: Dictionary = {},
gild_levels: Dictionary = {}) -> Array:
var skills: Array = []
var heroes: Dictionary = skill_data.get("heroes", {})
for hid0 in hero_ids:
var hid := str(hid0)
if not heroes.has(hid):
continue
var slots: Dictionary = heroes[hid]
var hs: Dictionary = hero_stats.get(hid, {})
var dps := float(hs.get("base_dps", 8.0))
# S8: H07-H09 take CH-source base DPS at the real hero level; every other
# hero keeps the frozen literal so H01-H06 behaviour is unchanged.
if ChHeroAdapter.applies_to(hid):
var lv := -1
if hero_levels.has(hid):
lv = int(hero_levels[hid])
dps = ChHeroAdapter.base_dps(hid, lv)
# S4: CH gild_multiplier(hero) = 1 + 0.5 * gild_levels[hero]. Empty map
# is identity, so every existing parity/fixture path is unchanged.
if not gild_levels.is_empty():
dps = snappedf(dps * ChRelicGild.multiplier_for_levels(gild_levels, hid), 0.0001)
var hero_skills: Array = []
for slot in SLOT_KEYS:
if not slots.has(slot):
continue
var sk: Dictionary = slots[slot]
var effects: Array = []
for e in sk.get("effects", []):
var e2: Dictionary = (e as Dictionary).duplicate()
var t := str(e2.get("type", ""))
if DAMAGE_LIKE.has(t) and e2.has("value") and e2["value"] is float:
e2["value"] = snappedf(float(e2["value"]) * dps, 0.0001)
effects.append(e2)
hero_skills.append({
"hero_id": hid + ":" + str(slot),
"interval": float(SLOT_INTERVALS[slot]),
"effects": effects,
"archetype": str(sk.get("archetype", "")),
})
# Stage C: rewrite this hero's skills from active behavior talents.
if not active_talents.is_empty() and not talent_specs.is_empty():
var ab := TalentBehavior.active_behaviors(hid, active_talents, talent_specs)
var combat: Array = ab["combat"]
if not combat.is_empty():
hero_skills = TalentBehavior.apply_behaviors(hero_skills, combat)
# Stage D: combat edicts apply GLOBAL rules to all of this hero's skills.
if not active_edicts.is_empty():
hero_skills = EdictRules.apply(hero_skills, active_edicts, dps)
# Stage F: active combat relics add distinct effects to the a1 slot.
if not active_relics.is_empty():
hero_skills = RelicEffects.apply(hero_skills, active_relics, dps)
# Stage G: rebuild-retained oaths apply directional combat rules.
if not active_oaths.is_empty():
hero_skills = OathRules.apply(hero_skills, active_oaths, dps)
for hsk in hero_skills:
skills.append(hsk)
return skills
static func load_talent_specs() -> Dictionary:
var pack := _read(CONTENT_PATH)
var out := {}
for t in pack.get("talents", []):
var row: Dictionary = t
out[str(row.get("id", ""))] = row
return out