Source-bound to clicker_heroes_rebuild_ancient_limit_build25 @ 46cc8ad: level_reward=floor(levels/2000), primal guarantee 100..1000 + 110/120/130, SoulWallet.ascended wallet semantics and Amenhotep required_level=150. Adds schema v5 soul fields with additive v1-v4 migration, exactly-once claim, a second reward line in the prestige preview, and focused domain and real-ScreenTouch runners.
267 lines
12 KiB
GDScript
267 lines
12 KiB
GDScript
class_name Prestige
|
|
extends RefCounted
|
|
|
|
## GDScript mirror of tools/fullgame/prestige.py (L2 two-tier prestige).
|
|
## Must produce identical numbers to the Python engine (parity tested).
|
|
|
|
const WorldContent = preload("res://scripts/world_content.gd")
|
|
|
|
const NEW_SKY_REGIONS_REQUIRED := 5
|
|
const NEW_SKY_RIFT_REQUIRED := 50
|
|
const EDICT_BASE_COST := 5
|
|
const EDICT_COST_STEP := 3
|
|
const PACE_SEC_PER_NODE := 1.9
|
|
|
|
## CH-derived ascension constants. Every value is quoted from the authoritative
|
|
## CH source at revision 46cc8ad (see PRODUCTION/S1 ascension source map):
|
|
## progression_state.gd:27 single / 2000.0 -> CH_LEVELS_PER_SOUL
|
|
## progression_state.gd:47 level < 100 / %5 -> CH_PRIMAL_START / STEP
|
|
## progression_state.gd:50 <=1000,%100 / bonus -> CH_PRIMAL_END / BONUS_ZONES
|
|
## game_state.gd:1303 int(levels[20]) < 150 -> CH_ASCENSION_LEVEL
|
|
## data/ch_numeric_authority/prestige.json -> same pins
|
|
## WR stores bounded ints; native BigValue/unbounded equivalence is NOT claimed.
|
|
const CH_LEVELS_PER_SOUL := 2000
|
|
const CH_PRIMAL_START := 100
|
|
const CH_PRIMAL_END := 1000
|
|
const CH_PRIMAL_STEP := 5
|
|
const CH_PRIMAL_BONUS_ZONES := [110, 120, 130]
|
|
const CH_ASCENSION_LEVEL := 150
|
|
|
|
|
|
static func new_sky_unlock(profile: Dictionary) -> Dictionary:
|
|
var regions := int(profile.get("completed_regions", 0))
|
|
var rift := int(profile.get("rift_layer", 0))
|
|
return {
|
|
"unlocked": regions >= NEW_SKY_REGIONS_REQUIRED or rift >= NEW_SKY_RIFT_REQUIRED,
|
|
"completed_regions": regions, "regions_required": NEW_SKY_REGIONS_REQUIRED,
|
|
"rift_layer": rift, "rift_required": NEW_SKY_RIFT_REQUIRED,
|
|
}
|
|
|
|
|
|
static func rebuild_unlock(profile: Dictionary) -> Dictionary:
|
|
var done: Array = profile.get("completed_nodes", [])
|
|
return {"unlocked": done.has("R1-C01-N10")}
|
|
|
|
|
|
static func edict_cost(edict_id: String) -> int:
|
|
var digits := ""
|
|
for c in edict_id:
|
|
if c.is_valid_int():
|
|
digits += c
|
|
var n := int(digits) if not digits.is_empty() else 1
|
|
return EDICT_BASE_COST + EDICT_COST_STEP * (n - 1)
|
|
|
|
|
|
static func _known_edict_ids() -> Array:
|
|
var out: Array = []
|
|
for e in WorldContent.content().get("edicts", []):
|
|
out.append(str((e as Dictionary).get("id", "")))
|
|
return out
|
|
|
|
|
|
static func buy_edict(profile: Dictionary, edict_id: String) -> Dictionary:
|
|
var cost := edict_cost(edict_id)
|
|
var owned: Dictionary = profile.get("edicts", {})
|
|
if bool(owned.get(edict_id, false)):
|
|
return {"ok": false, "reason": "already_owned", "cost": cost}
|
|
if int(profile.get("sky_marks", 0)) < cost:
|
|
return {"ok": false, "reason": "insufficient_marks", "cost": cost}
|
|
profile["sky_marks"] = int(profile.get("sky_marks", 0)) - cost
|
|
owned[edict_id] = true
|
|
profile["edicts"] = owned
|
|
return {"ok": true, "edict": edict_id, "cost": cost,
|
|
"marks_left": int(profile["sky_marks"])}
|
|
|
|
|
|
static func return_time_estimate(profile: Dictionary, sec_per_node: float = PACE_SEC_PER_NODE) -> Dictionary:
|
|
var highest := int(profile.get("highest_node", 0))
|
|
var seconds := int(round(float(highest) * maxf(0.0, sec_per_node)))
|
|
return {"highest_node": highest, "nodes_to_replay": highest,
|
|
"seconds": seconds, "sec_per_node": sec_per_node}
|
|
|
|
|
|
static func rebuild_preview(profile: Dictionary) -> Dictionary:
|
|
var highest := int(profile.get("highest_node", 0))
|
|
var chapters := int(profile.get("completed_chapters", 0))
|
|
var region_boss := int(profile.get("region_boss_first_clears", 0))
|
|
var essence := int(floor(pow(float(highest) / 10.0, 0.85))) + chapters * 2 + region_boss
|
|
return {"essence": essence, "highest_node": highest,
|
|
"completed_chapters": chapters, "region_boss_first": region_boss}
|
|
|
|
|
|
static func new_sky_preview(profile: Dictionary) -> Dictionary:
|
|
var total_essence := int(profile.get("total_essence_earned", 0))
|
|
var regions := int(profile.get("completed_regions", 0))
|
|
var final_boss := int(profile.get("final_boss_first_clears", 0))
|
|
var marks := int(floor(5.0 * log(float(total_essence + 1)) / log(10.0))) + regions * 2 + final_boss
|
|
return {"sky_marks": marks, "total_essence": total_essence,
|
|
"completed_regions": regions, "final_boss_first": final_boss}
|
|
|
|
|
|
## ---------------------------------------------------------------------------
|
|
## CH ascension / hero-soul slice (source-bound; no invented field mapping).
|
|
## ---------------------------------------------------------------------------
|
|
|
|
## CH ClickerProgression.level_reward() (progression_state.gd:25-28). The source
|
|
## forces float32 division before floor; mirror it with PackedFloat32Array so
|
|
## boundary values match exactly instead of relying on 64-bit floats.
|
|
static func ch_level_reward(total_levels: int) -> int:
|
|
var single: float = PackedFloat32Array([float(total_levels)])[0]
|
|
var quotient: float = PackedFloat32Array([single / float(CH_LEVELS_PER_SOUL)])[0]
|
|
return int(floor(quotient))
|
|
|
|
|
|
## CH ClickerProgression.is_primal() (progression_state.gd:42-54). Mutates the
|
|
## caller's primal_state dict (primal_seed / primal_uses / last_primal_zone /
|
|
## last_primal_result) exactly as the source's persistent fields do. The 100..1000
|
|
## hundred-zone guarantee and the 110/120/130 bonus zones are the CH values.
|
|
static func ch_is_primal(primal_state: Dictionary, level: int, finished: int,
|
|
chance_bonus: float = 0.0, ignore_frontier: bool = false) -> bool:
|
|
var last_zone := int(primal_state.get("last_primal_zone", 0))
|
|
if level <= finished or level < last_zone or (not ignore_frontier and level > finished + 1):
|
|
return false
|
|
if level == last_zone:
|
|
return bool(primal_state.get("last_primal_result", false))
|
|
if level < CH_PRIMAL_START or level % CH_PRIMAL_STEP != 0:
|
|
return false
|
|
primal_state["last_primal_zone"] = level
|
|
var forced: bool = (level <= CH_PRIMAL_END and level % 100 == 0) or CH_PRIMAL_BONUS_ZONES.has(level)
|
|
primal_state["last_primal_result"] = forced
|
|
if not forced:
|
|
# CH LCG: seed = (seed * 16807) % 2147483647; chance is 25% minus 2%
|
|
# per 500 zones, clamped to [5,100], plus the caller's chance bonus.
|
|
var seed := (int(primal_state.get("primal_seed", 1)) * 16807) % 2147483647
|
|
primal_state["primal_seed"] = seed
|
|
primal_state["primal_uses"] = int(primal_state.get("primal_uses", 0)) + 1
|
|
var chance := clampf(25.0 - 2.0 * int(level / 500) + chance_bonus, 5.0, 100.0)
|
|
primal_state["last_primal_result"] = (seed % 100) < int(chance)
|
|
return bool(primal_state["last_primal_result"])
|
|
|
|
|
|
## CH ClickerProgression.base_primal_reward() (progression_state.gd:56-59).
|
|
static func ch_base_primal_reward(level: int, solomon_percent: float = 0.0) -> int:
|
|
if level == CH_PRIMAL_START:
|
|
return 1
|
|
if level <= CH_PRIMAL_START or level % CH_PRIMAL_STEP != 0:
|
|
return 0
|
|
var inner: float = (float(int((level - 100) / 5) + 4) / 5.0)
|
|
return int(floor(pow(inner, 1.3) * (1.0 + solomon_percent * 0.01)))
|
|
|
|
|
|
## CH SoulWallet.ascended() (hero_soul_wallet.gd:19-22). The source adds the
|
|
## reward first and the old hero balance second, rounding on each call. With
|
|
## whole ints both rounds are no-ops; the ordering is preserved because the old
|
|
## hero balance is promoted into total_hero_souls on ascension.
|
|
static func ch_wallet_ascended(hero_souls: int, total_souls: int, reward: int) -> Dictionary:
|
|
if hero_souls < 0 or total_souls < 0 or reward < 0:
|
|
return {}
|
|
var first_hero := reward
|
|
var first_total := total_souls + reward
|
|
return {"hero": first_hero + hero_souls, "total": first_total + hero_souls}
|
|
|
|
|
|
## CH game_state.gd::ascension_preview() (lines 1294-1313) reward/wallet core.
|
|
## CH gates ascension on levels[20] >= 150 (Amenhotep). WR has no CH hero-id
|
|
## mapping and A5 forbids inventing one, so the gate is surfaced as
|
|
## `required_level` provenance and WR reachability uses the existing rebuild
|
|
## unlock. No hero-level value is fabricated.
|
|
static func ascension_preview(profile: Dictionary) -> Dictionary:
|
|
var levels: Dictionary = profile.get("hero_levels", {})
|
|
var total_levels := 0
|
|
for value in levels.values():
|
|
total_levels += maxi(0, int(value))
|
|
var level_reward := ch_level_reward(total_levels)
|
|
var primal_souls := maxi(0, int(profile.get("primal_souls", 0)))
|
|
var reward := level_reward + primal_souls
|
|
var hero_souls := maxi(0, int(profile.get("hero_souls", 0)))
|
|
var total_souls := maxi(0, int(profile.get("total_hero_souls", 0)))
|
|
var wallet := ch_wallet_ascended(hero_souls, total_souls, reward)
|
|
var can_ascend := bool(rebuild_unlock(profile).get("unlocked"))
|
|
return {
|
|
"reward": reward,
|
|
"level_reward": level_reward,
|
|
"primal_souls": primal_souls,
|
|
"total_levels": total_levels,
|
|
"required_level": CH_ASCENSION_LEVEL,
|
|
"next_balance": int(wallet.get("hero", hero_souls)),
|
|
"next_total": int(wallet.get("total", total_souls)),
|
|
"can_ascend": can_ascend,
|
|
"blocker": "" if can_ascend else "rebuild_locked",
|
|
}
|
|
|
|
|
|
## Apply the CH soul wallet once per ascension. The claim key is stored in
|
|
## claimed_rewards (which REBUILD_RETAIN now keeps), so a repeated confirm with
|
|
## the same rebuild counter cannot pay the wallet twice.
|
|
static func apply_ascension_souls(profile: Dictionary) -> Dictionary:
|
|
var preview := ascension_preview(profile)
|
|
var claim_key := "ascension:%d" % maxi(0, int(profile.get("rebuild_count", 0)))
|
|
var claimed: Array = profile.get("claimed_rewards", [])
|
|
if claimed.has(claim_key):
|
|
return {"ok": false, "reason": "already_claimed", "reward": 0}
|
|
if not bool(preview.get("can_ascend")):
|
|
return {"ok": false, "reason": str(preview.get("blocker", "locked")), "reward": 0}
|
|
claimed.append(claim_key)
|
|
profile["claimed_rewards"] = claimed
|
|
profile["hero_souls"] = int(preview["next_balance"])
|
|
profile["total_hero_souls"] = int(preview["next_total"])
|
|
profile["souls_from_ascensions"] = maxi(0, int(profile.get("souls_from_ascensions", 0))) + int(preview["reward"])
|
|
profile["primal_souls"] = 0
|
|
profile["ascensions"] = maxi(0, int(profile.get("ascensions", 0))) + 1
|
|
var receipt := {"kind": "ascension", "reward": int(preview["reward"]),
|
|
"total_levels": int(preview["total_levels"]), "balance": int(preview["next_balance"])}
|
|
profile["last_ascension"] = receipt
|
|
var history: Array = profile.get("soul_history", [])
|
|
history.append(receipt)
|
|
profile["soul_history"] = history.slice(-100)
|
|
return {"ok": true, "reward": int(preview["reward"]), "preview": preview}
|
|
|
|
|
|
const REBUILD_RESET := ["gold", "hero_levels", "talents", "gear", "equipped", "completed_nodes",
|
|
"current_node", "highest_node", "completed_chapters", "region_boss_first_clears"]
|
|
const REBUILD_RETAIN := ["crystal", "star_levels", "awakenings", "relics", "star_fragments",
|
|
"war_merit", "emblems", "oaths", "essence", "total_essence_earned",
|
|
"unlocked_heroes", "partners", "records", "seen_intro", "edicts",
|
|
# CH ascension wallet + claim history survive the rebuild (source-bound).
|
|
"hero_souls", "total_hero_souls", "primal_souls", "souls_from_ascensions",
|
|
"ascensions", "last_ascension", "soul_history", "claimed_rewards"]
|
|
const NEW_SKY_RESET := ["gold", "hero_levels", "talents", "gear", "completed_nodes",
|
|
"current_node", "highest_node", "completed_chapters", "region_boss_first_clears",
|
|
"essence", "oaths", "completed_regions", "region_boss_first_clears", "rift_layer"]
|
|
const NEW_SKY_RETAIN := ["sky_marks", "edicts", "unlocked_heroes", "star_levels", "awakenings",
|
|
"relics", "star_fragments", "war_merit", "records", "partners",
|
|
"crystal", "total_essence_earned", "seen_intro"]
|
|
|
|
|
|
static func _apply(profile: Dictionary, reset: Array, retain: Array) -> Dictionary:
|
|
var out: Dictionary = {}
|
|
for key in retain:
|
|
if profile.has(key):
|
|
out[key] = profile[key]
|
|
for key in reset:
|
|
out.erase(key)
|
|
return out
|
|
|
|
|
|
static func apply_rebuild(profile: Dictionary) -> Dictionary:
|
|
# CH ascension wallet is settled before the run reset, exactly like
|
|
# game_state.gd::_make_ascension_data() settles the wallet before clearing
|
|
# levels/gold. Both currencies land in one atomic profile write.
|
|
var ascension := apply_ascension_souls(profile)
|
|
var preview := rebuild_preview(profile)
|
|
var out := _apply(profile, REBUILD_RESET, REBUILD_RETAIN)
|
|
out["essence"] = int(profile.get("essence", 0)) + preview["essence"]
|
|
out["total_essence_earned"] = int(profile.get("total_essence_earned", 0)) + preview["essence"]
|
|
out["rebuild_count"] = int(profile.get("rebuild_count", 0)) + 1
|
|
out["ascension_ok"] = bool(ascension.get("ok"))
|
|
out["soul_reward"] = int(ascension.get("reward", 0))
|
|
return out
|
|
|
|
|
|
static func apply_new_sky(profile: Dictionary) -> Dictionary:
|
|
var preview := new_sky_preview(profile)
|
|
var out := _apply(profile, NEW_SKY_RESET, NEW_SKY_RETAIN)
|
|
out["sky_marks"] = int(profile.get("sky_marks", 0)) + preview["sky_marks"]
|
|
out["new_sky_count"] = int(profile.get("new_sky_count", 0)) + 1
|
|
return out
|