- add ch_runtime_content.py/.gd: patched pointers require real level/zone; unmappable families (C004/C050/C053/C054) raise instead of guessing - remove field_map.counts silent product-literal fallback in ch_authority.py - label frozen launch fixture source; add disposition map and G5 gate - keep UI, battle HUD, locale, OPEN items and gameplay literals untouched G3 12/12, G4 9 families/160 pointers/open 8, G5 92 dispositions PASS
200 lines
7.7 KiB
Python
200 lines
7.7 KiB
Python
#!/usr/bin/env python3
|
|
"""A5 authority-first runtime accessors for the confirmed CH patch families.
|
|
|
|
This module is the only sanctioned bridge from product rows to the A4 authority
|
|
sidecar (``data/ch_authority_binding.json`` + ``data/ch_numeric_authority/``).
|
|
|
|
Rules (PMO A5 remit):
|
|
|
|
* A patched pointer is served by the authority ``$ref`` ONLY when the caller
|
|
supplies real dynamic context (``level`` / ``zone``). Missing context raises;
|
|
no literal is guessed and no product value is silently substituted.
|
|
* A family whose CH field cannot be mapped unambiguously from the Windroost row
|
|
raises :class:`BlockedMappingError`. It is never resolved with a guessed id,
|
|
level, zone, coefficient or structure.
|
|
* Rows sourced from a legacy fixture are returned untouched but are tagged via
|
|
:func:`tag_source` / :func:`source_of`; they are compatibility data, not the
|
|
authority runtime path.
|
|
* The 8 R4 OPEN items remain OPEN and are not referenced here.
|
|
|
|
Mirrored by ``p2_godot_sample/scripts/ch_runtime_content.gd`` (G5 parity gate).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Optional
|
|
|
|
import ch_authority as A
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
CONTENT = ROOT / "data" / "full_game_content.json"
|
|
DISPOSITION = ROOT / "data" / "ch_consumer_disposition.json"
|
|
|
|
LEGACY_FIXTURE_SOURCE = "legacy_fixture:mvp_launch_content.json"
|
|
PRODUCT_SOURCE = "full_game_content.json"
|
|
|
|
|
|
class BlockedMappingError(RuntimeError):
|
|
"""The CH field for this consumer has no unambiguous authority mapping."""
|
|
|
|
|
|
def _content() -> dict:
|
|
return json.loads(CONTENT.read_text(encoding="utf-8"))
|
|
|
|
|
|
def patched_pointers() -> Dict[str, set]:
|
|
"""Map family label -> set of JSON pointers pathed by the A4 binding."""
|
|
binding = json.loads(A.BINDING.read_text(encoding="utf-8"))
|
|
return {f["label"]: set(f["pointers"]) for f in binding["applied_families"]}
|
|
|
|
|
|
def source_of(row: Dict[str, Any], default: str = PRODUCT_SOURCE) -> str:
|
|
return str(row.get("source", default))
|
|
|
|
|
|
def tag_source(row: Dict[str, Any], source: str) -> Dict[str, Any]:
|
|
"""Return a shallow copy of a legacy row carrying an explicit source label."""
|
|
out = dict(row)
|
|
out["source"] = source
|
|
return out
|
|
|
|
|
|
def _require(name: str, value: Any) -> Any:
|
|
if value is None:
|
|
raise ValueError(f"A5 {name} context required; no CH value guessed")
|
|
return value
|
|
|
|
|
|
def _row_index(kind: str, row: Dict[str, Any]) -> Optional[int]:
|
|
"""Locate a product row index by stable id; None for non-product rows."""
|
|
if source_of(row) != PRODUCT_SOURCE:
|
|
return None
|
|
rows = _content().get(kind, [])
|
|
rid = str(row.get("id", ""))
|
|
for i, candidate in enumerate(rows):
|
|
if str(candidate.get("id", "")) == rid:
|
|
return i
|
|
return None
|
|
|
|
|
|
def hero_base_dps(row: Dict[str, Any], *, level: Optional[int] = None,
|
|
source: Optional[str] = None) -> float:
|
|
"""H01/H04 (patched) base DPS from the authority; level is mandatory.
|
|
|
|
Unpatched heroes and legacy-fixture rows keep their literal value and are
|
|
returned with an explicit ``source`` tag through :func:`tag_source`.
|
|
"""
|
|
src = source or source_of(row)
|
|
idx = _row_index("heroes", row)
|
|
patched = f"/heroes/{idx}/base_dps"
|
|
if src == PRODUCT_SOURCE and patched in patched_pointers()["hero base_dps placeholder"]:
|
|
_require("hero level", level)
|
|
return float(A.resolve("ch_numeric_authority.hero_dps.base_dps_at_level",
|
|
hero_id=idx + 1, level=level))
|
|
return float(row.get("base_dps", 0.0))
|
|
|
|
|
|
def enemy_base_hp(row: Dict[str, Any], *, zone: Optional[int] = None,
|
|
source: Optional[str] = None) -> float:
|
|
src = source or source_of(row)
|
|
idx = _row_index("enemies", row)
|
|
if src == PRODUCT_SOURCE and f"/enemies/{idx}/base_hp" in patched_pointers()["enemy base_hp placeholder"]:
|
|
_require("enemy zone", zone)
|
|
return float(A.resolve("ch_numeric_authority.monster_boss.hp_at_zone", zone=zone))
|
|
return float(row.get("base_hp", 0.0))
|
|
|
|
|
|
def boss_base_hp(row: Dict[str, Any], *, zone: Optional[int] = None,
|
|
source: Optional[str] = None) -> float:
|
|
src = source or source_of(row)
|
|
idx = _row_index("bosses", row)
|
|
if src == PRODUCT_SOURCE and f"/bosses/{idx}/base_hp" in patched_pointers()["boss base_hp placeholder"]:
|
|
_require("boss zone", zone)
|
|
return float(A.resolve("ch_numeric_authority.monster_boss.boss_hp_at_zone", zone=zone))
|
|
return float(row.get("base_hp", 0.0))
|
|
|
|
|
|
def node_gold(row: Dict[str, Any], *, zone: Optional[int] = None,
|
|
source: Optional[str] = None) -> int:
|
|
src = source or source_of(row)
|
|
idx = _row_index("nodes", row)
|
|
if src == PRODUCT_SOURCE and f"/nodes/{idx}/gold" in patched_pointers()["node gold placeholder"]:
|
|
_require("node zone", zone)
|
|
return int(A.resolve("ch_numeric_authority.monster_boss.gold_at_zone", zone=zone))
|
|
return int(row.get("gold", 0))
|
|
|
|
|
|
def stat_value(row: Dict[str, Any], *, kind: Optional[str] = None) -> float:
|
|
"""BLOCKED: C050 has no id/level/family context in a gear/oath/edict row."""
|
|
raise BlockedMappingError(
|
|
f"C050 stat_value for {kind or source_of(row)}: CH ancient/outsider "
|
|
"bonus needs id+level+levelAmountFormula; none is present in the row")
|
|
|
|
|
|
def counts() -> dict:
|
|
"""BLOCKED: the authority field_map has no ``counts`` key.
|
|
|
|
A4's resolver used a product-literal fallback here; A5 removes that silent
|
|
fallback and requires an explicit authority key before serving counts.
|
|
"""
|
|
authority_counts = A.payload(A.AUTHORITY / "field_map.json").get("counts")
|
|
if not authority_counts:
|
|
raise BlockedMappingError(
|
|
"C004 $ref ch_numeric_authority.field_map.counts has no authority "
|
|
"key; product counts cannot be served as authority")
|
|
return {k: int(v) for k, v in authority_counts.items()}
|
|
|
|
|
|
def relic_rows() -> list:
|
|
"""BLOCKED: C053 authority carries global gild constants, no per-relic map."""
|
|
raise BlockedMappingError(
|
|
"C053 authority relic_gild holds global slots/costs/rng constants; "
|
|
"mapping L01..L60 rows to CH gilds is undefined")
|
|
|
|
|
|
def partner_rows() -> list:
|
|
"""BLOCKED: C054 authority carries global merc constants, no per-partner map."""
|
|
raise BlockedMappingError(
|
|
"C054 authority merc_auto holds global hire/autoclick constants; "
|
|
"mapping P01..P05 rows to CH mercs is undefined")
|
|
|
|
|
|
BLOCKED_FAMILIES = {
|
|
"stat_value": "C050 requires CH ancient/outsider id+level+family absent from product rows",
|
|
"counts": "C004 $ref has no authority counts key",
|
|
"relics": "C053 global gild constants only; no per-relic mapping",
|
|
"partners": "C054 global merc constants only; no per-partner mapping",
|
|
}
|
|
|
|
|
|
def validate() -> list:
|
|
"""Fail-fast smoke checks independent of product data files."""
|
|
problems = []
|
|
for name, fn in (("stat_value", lambda: stat_value({}, kind="gear")),
|
|
("counts", counts), ("relics", relic_rows), ("partners", partner_rows)):
|
|
try:
|
|
fn()
|
|
problems.append(f"{name} did not raise BlockedMappingError")
|
|
except BlockedMappingError:
|
|
pass
|
|
try:
|
|
hero_base_dps({"id": "H01", "source": PRODUCT_SOURCE})
|
|
problems.append("hero_base_dps did not require level")
|
|
except ValueError:
|
|
pass
|
|
try:
|
|
node_gold({"id": "R1-C01-N01", "source": PRODUCT_SOURCE})
|
|
problems.append("node_gold did not require zone")
|
|
except ValueError:
|
|
pass
|
|
return problems
|
|
|
|
|
|
if __name__ == "__main__":
|
|
problems = validate()
|
|
for p in problems:
|
|
print(f"FAIL {p}")
|
|
print(f"CH runtime adapter: blocked={len(BLOCKED_FAMILIES)} problems={len(problems)}")
|
|
raise SystemExit(1 if problems else 0)
|