110 lines
4.0 KiB
GDScript
110 lines
4.0 KiB
GDScript
class_name ChAuthority
|
|
extends RefCounted
|
|
|
|
## A4 numeric authority consumer (GDScript mirror of tools/fullgame/ch_authority.py).
|
|
## Reads the A3 authority bundle copied verbatim into data/ch_numeric_authority/.
|
|
## PMO ruling: confirmed fields MUST read the sidecar; a missing sidecar or key
|
|
## is a hard error (push_error + NaN), never a silent literal fallback.
|
|
## The 8 R4 OPEN items are recorded but never resolved or guessed.
|
|
|
|
const AUTHORITY_DIR := "res://data/ch_numeric_authority"
|
|
const BINDING_PATH := "res://data/ch_authority_binding.json"
|
|
const EXPECTED_REVISION := "46cc8ad46ac886918ee1b2c1b0e946e1f5e17c04"
|
|
const OPEN_IDS := ["C009", "C013", "C016", "C025", "C029", "C037", "C045", "C049"]
|
|
|
|
|
|
static func load_json(path: String) -> Variant:
|
|
var f := FileAccess.open(path, FileAccess.READ)
|
|
if f == null:
|
|
push_error("CH_AUTHORITY sidecar missing: %s (no silent fallback)" % path)
|
|
return null
|
|
var parsed: Variant = JSON.parse_string(f.get_as_text())
|
|
f.close()
|
|
if typeof(parsed) != TYPE_DICTIONARY:
|
|
push_error("CH_AUTHORITY sidecar invalid: %s" % path)
|
|
return null
|
|
return parsed
|
|
|
|
|
|
static func req(d: Dictionary, key: String, context: String) -> Variant:
|
|
if not d.has(key):
|
|
push_error("CH_AUTHORITY sidecar key missing: %s.%s (no silent fallback)" % [context, key])
|
|
return NAN
|
|
return d[key]
|
|
|
|
|
|
static func domain(name: String) -> Dictionary:
|
|
var doc: Variant = load_json("%s/%s.json" % [AUTHORITY_DIR, name])
|
|
if doc == null:
|
|
return {}
|
|
var d: Dictionary = doc
|
|
return d.get("values", {}) as Dictionary
|
|
|
|
|
|
static func binding() -> Dictionary:
|
|
return load_json(BINDING_PATH) as Dictionary
|
|
|
|
|
|
static func source_bound() -> bool:
|
|
var m: Variant = load_json("%s/manifest.json" % AUTHORITY_DIR)
|
|
if m == null:
|
|
return false
|
|
var src: Dictionary = (m as Dictionary).get("source", {}) as Dictionary
|
|
return str(src.get("revision", "")) == EXPECTED_REVISION
|
|
|
|
|
|
static func hp_at_zone(zone: int) -> float:
|
|
var mb := domain("monster_boss")
|
|
var early := float(str(req(mb, "early", "monster_boss")))
|
|
var at140 := float(str(req(mb, "at_140_multiplier", "monster_boss")))
|
|
var rate := float(str(req(mb, "rate", "monster_boss")))
|
|
var power: float
|
|
if zone <= 140:
|
|
power = pow(early, zone - 1) * 10.0 + 10.0 * (zone - 1)
|
|
elif zone <= 500:
|
|
power = pow(early, 139.0) * at140 * pow(rate, zone - 140) + 1390.0
|
|
else:
|
|
return NAN # beyond the authoritative single-segment range
|
|
return ceil(power)
|
|
|
|
|
|
static func boss_hp_at_zone(zone: int) -> float:
|
|
var mb := domain("monster_boss")
|
|
var per500 := float(str(req(mb, "boss_hp_per_500", "monster_boss")))
|
|
var mult: float = maxf(5.0, (1.0 + (zone / 500) * per500) * 10.0)
|
|
return ceil(hp_at_zone(zone) * mult)
|
|
|
|
|
|
static func gold_at_zone(zone: int) -> float:
|
|
var mb := domain("monster_boss")
|
|
var cap := float(str(req(mb, "gold_post75_cap", "monster_boss")))
|
|
var growth := float(str(req(mb, "gold_growth", "monster_boss")))
|
|
var from := int(str(req(mb, "gold_post75_from", "monster_boss")))
|
|
var first: int = mini(zone, 140)
|
|
var old: float = ceil((pow(1.6, first - 1) * 10.0 + 10.0 * (first - 1)) * pow(1.15, maxi(zone - 140, 0)))
|
|
var bonus: float = minf(cap, pow(growth, clampi(zone - from, 0, 45)))
|
|
return ceil(old * bonus / 15.0)
|
|
|
|
|
|
static func base_dps_at_level(hero_id: int, level: int) -> float:
|
|
if hero_id == 1 or level == 0:
|
|
return 0.0
|
|
var attacks: Array = domain("hero_dps").get("base_attacks", []) as Array
|
|
if hero_id - 1 >= attacks.size():
|
|
push_error("CH_AUTHORITY base_attacks missing hero %d (no silent fallback)" % hero_id)
|
|
return NAN
|
|
return float(str(attacks[hero_id - 1])) * float(level)
|
|
|
|
|
|
static func outsider_bonus(id: int, level: int) -> float:
|
|
var e := domain("edicts")
|
|
if id == 1 or id == 4:
|
|
return (pow(1.5, level) - 1.0) * 100.0
|
|
if id == 2:
|
|
return (1.0 - pow(float(str(req(e, "ancient_discount", "edicts"))), level)) * 100.0
|
|
if id == 3:
|
|
return float(level) * float(str(req(e, "id3_cost_per_level", "edicts"))) * 100.0
|
|
if id == 5:
|
|
return float(level * level) * 1000.0
|
|
return [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.5, 25.0, 50.0, 75.0, 100.0][id] * level
|