Files
windroost/p2_godot_sample/scripts/ch_systems_adapter.gd
T
wushenghua f35835d224 fix(ch-systems): make guild actions reachable at 360px en_US
- wrap side summary/empty-hint labels so long en_US strings no longer widen the column and push Hire/Buy/Send outside the viewport
- use concise localized tab captions (Guild / Bounties)
- reject off-viewport targets in the real ScreenTouch probe
- re-verified: strict import, domain, 36-case touch matrix, save corruption, parity
2026-11-29 08:45:20 +08:00

241 lines
9.9 KiB
GDScript

class_name ChSystemsAdapter
extends RefCounted
## Explicit Windroost adapter for four CH books:
## mercenary_book.gd / autoclicker_book.gd / achievement_book.gd / clickable_book.gd
##
## Every constant below is copied from clicker_heroes_rebuild_ancient_limit_build25
## @ 46cc8ad and mirrored in data/ch_systems_adapter.json. Payment and consumer
## mappings that WR cannot express natively are labelled WR-original in that
## sidecar and in PRODUCTION/S5-S6-CH-SYSTEMS-CONTRACT.md. This is NOT a claim of
## native CH equivalence and does not claim any human or device evidence.
const MODULUS: int = 2147483647
# mercenary_book.gd + data/ch_numeric_authority/merc_auto.json
const HIRE_COST: int = 40
const REROLL_COST: int = 10
const RECRUIT_MS: int = 28800000
const REVIVAL_LEVEL_CAP: int = 54
const REVIVAL_BASE: float = 1.5
const REVIVAL_FLAT: float = 10.0
const REVIVAL_MULTIPLIER: int = 10
# MERCENARY_CONFIG oracle vector (duration id 1, gold reward type 2)
const QUEST_DURATION_ID: int = 1
const QUEST_DURATION_SEC: int = 300
const QUEST_DURATION_BONUS: float = 3.200000047683716
const GOLD_REWARD_TYPE: int = 2
const GOLD_BASE_VALUE: float = 24.0
# autoclicker_book.gd
const AUTOCLICKER_BASE_PRICE: int = 1000
const AUTOCLICKER_STEP: int = 500
const RATE_LINEAR: float = 10.0
const RATE_EXP_BASE: float = 1.5
const SERVICE_TICK_SEC: float = 0.1
# clickable_book.gd + data/ch_numeric_authority/achievements.json
const CLICKABLE_SPAWN_INTERVAL_SEC: float = 60.0
const CLICKABLE_TICKS_PER_SEC: float = 30.0
const CLICKABLE_ABSENCE_CAP_SEC: float = 600.0
const RUBY_GATE: float = 15770583.0 / 33554432.0
const TIER25: float = 5368709.0 / 536870912.0
const TIER20: float = 5368709.0 / 134217728.0
# data/achievements.json id 43 (verified against authority click_bonus map)
const CLICK_BONUS_ACHIEVEMENT_ID: int = 43
const CLICK_BONUS_CHECK: String = "numWorldResets"
const CLICK_BONUS_THRESHOLD: int = 1
const CLICK_BONUS_AMOUNT: int = 10
static func f32(value: float) -> float:
return PackedFloat32Array([value])[0]
## CH mercenary_book.gd::rand_state / rand_float -- one shared LCG shape.
static func rng_step(state: Dictionary) -> int:
state["seed"] = (int(state.get("seed", 1)) * 16807) % MODULUS
state["uses"] = (int(state.get("uses", 0)) + 1) & 4294967295
return int(state["seed"])
static func rng_float(state: Dictionary) -> float:
return f32(f32(float(rng_step(state))) / f32(float(MODULUS)))
static func valid_rng(state: Variant) -> bool:
if not state is Dictionary:
return false
var d: Dictionary = state
var seed: Variant = d.get("seed", -1)
var uses: Variant = d.get("uses", -1)
if not (seed is int or seed is float) or not (uses is int or uses is float):
return false
return int(seed) >= 1 and int(seed) <= MODULUS - 1 and int(uses) >= 0 and int(uses) <= 4294967295
static func fresh_rng(seed: int) -> Dictionary:
return {"seed": posmod(seed, MODULUS - 1) + 1, "uses": 0}
## CH mercenary_book.gd::quest() + quantity() + rounded_quantity() for the single
## gold-only duration-1 quest. Level feeds the CH quantity multiplier; rounding
## consumes one mercenary RNG draw, matching the source's fractional rule.
static func quest_quantity(level: int, rng: Dictionary) -> int:
var qty := f32(f32(f32(GOLD_BASE_VALUE * float(QUEST_DURATION_SEC)) / 86400.0) * QUEST_DURATION_BONUS)
var value := f32(float(maxi(1, level)) * qty)
var whole := maxi(0, int(floor(value)))
var fraction := f32(value - float(whole))
return whole + (1 if rng_float(rng) < fraction else 0)
static func make_quest(start_ms: int, level: int, rng: Dictionary) -> Dictionary:
return {
"reward": GOLD_REWARD_TYPE,
"duration_id": QUEST_DURATION_ID,
"duration": QUEST_DURATION_SEC,
"start": start_ms,
"quantity": quest_quantity(level, rng),
"uid": 0,
}
## CH mercenary_book.gd::progress / status. Death is an earlier deadline inside
## the quest; a positive death equal to duration is NOT a finished quest (source
## oracle: "positive lifetime==duration enters death branch").
static func quest_progress(quest: Dictionary, now_ms: int) -> float:
if quest.is_empty():
return 0.0
var elapsed := clampi(now_ms - int(quest.get("start", 0)), 0, int(quest.get("duration", 0)) * 1000)
var death := int(quest.get("death", 0))
if death > 0 and death < int(quest.get("duration", 0)):
elapsed = mini(elapsed, death * 1000)
return f32(f32(float(elapsed)) / f32(float(int(quest.get("duration", 0)) * 1000)))
static func quest_status(quest: Dictionary, now_ms: int) -> String:
if quest.is_empty():
return "idle"
var death := int(quest.get("death", 0))
if death > 0 and now_ms >= int(quest.get("start", 0)) + death * 1000:
return "dead"
var remaining := f32(f32(f32(100.0 - f32(quest_progress(quest, now_ms) * 100.0)) / 100.0) * float(quest.get("duration", 0)))
return "ready" if int(quest.get("start", 0)) > 0 and death == 0 and remaining == 0.0 else "running"
## CH mercenary_book.gd::revival_cost, including the level>54 -1 sentinel and the
## uint32 multiply wrap. Payment currency is WR-original (revive_charges).
static func revival_cost(level: int) -> int:
if level > REVIVAL_LEVEL_CAP:
return -1
var base: float = ceil(pow(REVIVAL_BASE, float(level)) + REVIVAL_FLAT)
if base > 4294967295.0:
return -1
return (int(base) * REVIVAL_MULTIPLIER) & 4294967295
## CH mercenary_book.gd::advance-equivalent life generation: while RandFloat() <= .8
## add a day; finally add Range(1,86400). A bounded attempt count keeps a corrupt
## save from hanging the game; legal source vectors are unchanged.
static func generate_life(rng: Dictionary) -> int:
var days := 0
for _i in 4096:
if rng_float(rng) > f32(0.8):
return days * 86400 + rng_step(rng) % 86400 + 1
days += 1
return -1
## CH autoclicker_book.gd::price / rate / advance.
static func autoclicker_price(owned: int) -> int:
if owned > int((9007199254740991 - 1000) / 500):
return -1
return AUTOCLICKER_BASE_PRICE + owned * AUTOCLICKER_STEP
static func autoclicker_rate(count: int, nog_stacks: int = 0) -> float:
# CH: BigValue.new(10*count) below 5; above it, power(1.5,count-1).scale(10).ceiled().
var base: float = RATE_LINEAR * float(count) if count < 5 else ceil(f32(pow(RATE_EXP_BASE, float(count - 1))) * RATE_LINEAR)
return base + float(count) * float(nog_stacks)
static func autoclicker_advance(state: Dictionary, delta: float, virtual: int = 0) -> Dictionary:
var dt := f32(delta)
if delta < 0.0 or not is_finite(dt):
return {"clicks": 0, "service": false}
var count := float(maxi(0, int(state.get("owned", 0)) + virtual))
var total := autoclicker_rate(int(count)) * dt + float(state.get("remainder", 0.0))
var whole := int(floor(total))
state["remainder"] = clampf(total - float(whole), 0.0, 0.9999999999999999)
state["timer"] = f32(float(state.get("timer", 0.0)) + dt)
var service := float(state["timer"]) >= f32(SERVICE_TICK_SEC)
if service:
state["timer"] = f32(float(state["timer"]) - f32(SERVICE_TICK_SEC))
return {"clicks": whole, "service": service}
## CH clickable_book.gd::draw / ruby_gate / ruby_tier / advance / consume.
static func clickable_draw(state: Dictionary, reward: bool) -> float:
var key := "reward_seed" if reward else "spawn_seed"
var uses := "reward_uses" if reward else "spawn_uses"
var stepped := rng_step({"seed": state.get(key, 1), "uses": state.get(uses, 0)})
state[key] = stepped
state[uses] = int(state.get(uses, 0)) + 1
return float(stepped) / float(MODULUS)
static func clickable_tier(sample: float, ruby_percent: float = 0.0) -> int:
var chance := ruby_percent / 100.0
if sample < chance + TIER25:
return 25
return 20 if sample < chance + TIER20 else 10
## Advance the 30 Hz scheduler. Long absence is capped at 600 s: offline gold
## never creates click entitlements (clickable_book.gd local rule).
static func clickable_advance(state: Dictionary, delta: float, unlocked: bool) -> bool:
if delta <= 0.0 or not is_finite(delta):
return false
var ticks := float(state.get("phase", 0.0)) + minf(delta, CLICKABLE_ABSENCE_CAP_SEC) * CLICKABLE_TICKS_PER_SEC
var whole := int(floor(ticks + 1e-9))
state["phase"] = maxf(0.0, ticks - float(whole))
if not unlocked or int(state.get("active_uid", 0)) != 0:
return false
var chance := 1.0 / (CLICKABLE_SPAWN_INTERVAL_SEC * CLICKABLE_TICKS_PER_SEC)
for _i in whole:
if clickable_draw(state, false) < chance:
state["active_uid"] = int(state.get("next_uid", 1))
state["next_uid"] = int(state.get("next_uid", 1)) + 1
state["revision"] = int(state.get("revision", 0)) + 1
return true
return false
## Exact CH draw order: ruby gate draw, then tier draw on success. The tier is
## paid as WR crystal by the labelled ruby->crystal payment adapter.
static func clickable_reward(state: Dictionary, uid: int) -> Dictionary:
if uid <= 0 or int(state.get("active_uid", 0)) != uid:
return {}
if clickable_draw(state, true) >= RUBY_GATE:
state["active_uid"] = 0
state["total_claims"] = int(state.get("total_claims", 0)) + 1
state["revision"] = int(state.get("revision", 0)) + 1
return {"tier": 0, "crystal": 0}
var tier := clickable_tier(clickable_draw(state, true))
state["ruby_rewards"] = int(state.get("ruby_rewards", 0)) + 1
state["total_claims"] = int(state.get("total_claims", 0)) + 1
state["active_uid"] = 0
state["revision"] = int(state.get("revision", 0)) + 1
return {"tier": tier, "crystal": tier}
## CH achievement_book.gd::scan for the one source-bound record (id 43).
## `numWorldResets` is progression.ascensions in CH; WR's explicit world-reset
## counter is rebuild_count. Frozen battle rules are untouched; the reward is a
## labelled auto-click output adapter.
static func achievement_scan(stats: Dictionary, obtained: Array) -> Dictionary:
var unlocked: Array = []
var bonus := int(stats.get("click_bonus", 0))
if int(stats.get(CLICK_BONUS_CHECK, 0)) >= CLICK_BONUS_THRESHOLD and not obtained.has(CLICK_BONUS_ACHIEVEMENT_ID):
obtained.append(CLICK_BONUS_ACHIEVEMENT_ID)
bonus += CLICK_BONUS_AMOUNT
unlocked.append(CLICK_BONUS_ACHIEVEMENT_ID)
return {"obtained": obtained, "click_bonus": bonus, "unlocked": unlocked}