- 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
272 lines
14 KiB
GDScript
272 lines
14 KiB
GDScript
extends SceneTree
|
|
|
|
## S5/S6 focused domain evidence for the four CH systems adapters.
|
|
## No UI input is claimed here; real ScreenTouch evidence lives in
|
|
## ch_systems_touch_test.gd. All constants and formulas are checked against the
|
|
## pinned CH source bundle by tools/fullgame/check_ch_systems_parity.py.
|
|
|
|
const OUTPUT_PATH := "res://artifacts/ch_systems_test.json"
|
|
const REVISION := "46cc8ad46ac886918ee1b2c1b0e946e1f5e17c04"
|
|
const ChSystems = preload("res://scripts/ch_systems_adapter.gd")
|
|
|
|
var _problems: Array = []
|
|
var _steps: Array = []
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _check(cond: bool, msg: String) -> void:
|
|
if not cond:
|
|
_problems.append(msg)
|
|
|
|
|
|
func _record(name: String, data: Dictionary) -> void:
|
|
var e := data.duplicate()
|
|
e["step"] = name
|
|
_steps.append(e)
|
|
|
|
|
|
func _run() -> void:
|
|
_constants()
|
|
_quest_math()
|
|
_quest_lifecycle()
|
|
_death_and_revival()
|
|
_autoclicker()
|
|
_achievement()
|
|
_clickable()
|
|
_offline_consumer()
|
|
_corruption_and_migration()
|
|
_finish()
|
|
|
|
|
|
func _constants() -> void:
|
|
_check(ChSystems.HIRE_COST == 40, "CH hire cost must be 40")
|
|
_check(ChSystems.REROLL_COST == 10, "CH reroll cost must be 10")
|
|
_check(ChSystems.RECRUIT_MS == 28800000, "CH recruit window must be 28800000 ms")
|
|
_check(ChSystems.QUEST_DURATION_SEC == 300, "duration tier must be 300 s")
|
|
_check(ChSystems.revival_cost(1) == 120, "revival cost at level 1 must be 120")
|
|
_check(ChSystems.revival_cost(55) == -1, "level above 54 uses the CH -1 sentinel")
|
|
_check(ChSystems.autoclicker_price(0) == 1000, "first auto-clicker costs 1000")
|
|
_check(ChSystems.autoclicker_price(1) == 1500, "second auto-clicker costs 1500")
|
|
_check(is_equal_approx(ChSystems.autoclicker_rate(0), 0.0), "zero autoclickers produce no clicks")
|
|
_check(is_equal_approx(ChSystems.autoclicker_rate(4), 40.0), "linear rate below 5")
|
|
_check(is_equal_approx(ChSystems.autoclicker_rate(5), 51.0), "exp rate at 5 is ceil(1.5^4*10)=51")
|
|
_check(absf(ChSystems.RUBY_GATE - (15770583.0 / 33554432.0)) < 1e-12, "ruby gate must be pinned")
|
|
_record("constants", {"hire_cost": ChSystems.HIRE_COST, "revival_1": ChSystems.revival_cost(1),
|
|
"revival_55": ChSystems.revival_cost(55), "price_0": ChSystems.autoclicker_price(0),
|
|
"rate_5": ChSystems.autoclicker_rate(5)})
|
|
|
|
|
|
func _quest_math() -> void:
|
|
var rng := ChSystems.fresh_rng(1)
|
|
var qty := ChSystems.quest_quantity(1, rng)
|
|
# qty = f32(f32(24*300/86400)*3.2) = 0.26666..., so one draw rounds 0 or 1.
|
|
_check(qty >= 0 and qty <= 1, "level 1 gold quest pays 0 or 1 gold")
|
|
_check(int(rng.get("uses", 0)) == 1, "rounding consumes exactly one LCG use")
|
|
var big := ChSystems.quest_quantity(20, ChSystems.fresh_rng(1))
|
|
_check(big >= qty, "quest quantity grows with level")
|
|
var q := ChSystems.make_quest(1000, 1, ChSystems.fresh_rng(1))
|
|
_check(int(q.get("reward", 0)) == ChSystems.GOLD_REWARD_TYPE, "only the gold reward kind is used")
|
|
_check(int(q.get("duration", 0)) == 300, "only the 300 s tier is used")
|
|
_record("quest_math", {"qty_level_1": qty, "qty_level_20": big, "quest": q})
|
|
|
|
|
|
func _quest_lifecycle() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
profile["crystal"] = 100
|
|
var hire := ProfileStore.hire_merc(profile)
|
|
_check(bool(hire.get("ok")), "hire with crystal must succeed")
|
|
_check(int(profile.get("crystal", 0)) == 100 - ChSystems.HIRE_COST, "hire debits pinned crystal price")
|
|
_check((profile.get("merc_quests", []) as Array).size() == 1, "one mercenary slot created")
|
|
var uid := int(hire.get("uid", 0))
|
|
var started := ProfileStore.start_quest(profile, uid, 1000000)
|
|
_check(bool(started.get("ok")), "quest start must succeed")
|
|
var slot := ProfileStore.ch_slot(profile, uid)
|
|
var quest: Dictionary = slot.get("quest", {})
|
|
_check(ChSystems.quest_status(quest, 1000000) == "running", "quest starts running")
|
|
_check(ChSystems.quest_status(quest, 1000000 + 150000) == "running", "quest still running halfway")
|
|
# Freeze death: a positive death shorter than duration ends in death, so set
|
|
# it to zero to observe the ordinary ready transition.
|
|
quest["death"] = 0
|
|
slot["quest"] = quest
|
|
_check(ChSystems.quest_status(quest, 1000000 + 300000) == "ready", "quest becomes ready at deadline")
|
|
var before_gold := int(profile.get("gold", 0))
|
|
var claimed := ProfileStore.finish_quest(profile, uid, 1000000 + 300000)
|
|
_check(bool(claimed.get("ok")), "ready quest must be collectable")
|
|
_check(int(profile.get("gold", 0)) == before_gold + int(claimed.get("gold", 0)), "quest gold credited")
|
|
_check((ProfileStore.ch_slot(profile, uid).get("quest", {}) as Dictionary).is_empty(), "quest slot cleared")
|
|
var replay := ProfileStore.finish_quest(profile, uid, 1000000 + 300000)
|
|
_check(not bool(replay.get("ok")) and str(replay.get("reason", "")) == "not_ready",
|
|
"an empty slot cannot be collected twice")
|
|
var persisted := ProfileStore.load_profile()
|
|
_check(int(persisted.get("gold", 0)) == int(profile.get("gold", 0)), "quest payout persisted")
|
|
_record("quest_lifecycle", {"uid": uid, "hire": hire, "claimed": claimed, "replay": replay})
|
|
|
|
|
|
func _death_and_revival() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
profile["crystal"] = 100
|
|
profile["revive_charges"] = 2
|
|
var hire := ProfileStore.hire_merc(profile)
|
|
var uid := int(hire.get("uid", 0))
|
|
ProfileStore.start_quest(profile, uid, 2000000)
|
|
var slot := ProfileStore.ch_slot(profile, uid)
|
|
var quest: Dictionary = slot.get("quest", {})
|
|
quest["death"] = 5
|
|
slot["quest"] = quest
|
|
_check(ChSystems.quest_status(quest, 2000000 + 5000) == "dead", "short life ends in death")
|
|
var refused := ProfileStore.finish_quest(profile, uid, 2000000 + 5000)
|
|
_check(not bool(refused.get("ok")), "a dead quest cannot be collected")
|
|
var revived := ProfileStore.revive_merc(profile, uid, 2000000 + 5000)
|
|
_check(bool(revived.get("ok")), "revive with a WR charge must succeed")
|
|
_check(int(profile.get("revive_charges", 0)) == 1, "revive consumes one charge")
|
|
var after: Dictionary = ProfileStore.ch_slot(profile, uid).get("quest", {})
|
|
_check(int(after.get("death", -1)) == 0, "revival clears the death deadline")
|
|
_check(ChSystems.quest_status(after, 2000000 + 5000) == "running", "revived quest resumes")
|
|
var no_charge := ProfileStore.revive_merc(profile, uid, 2000000 + 5000)
|
|
_check(not bool(no_charge.get("ok")), "revive without a charge is refused")
|
|
_record("death_revival", {"cost": revived.get("cost"), "charges": profile.get("revive_charges"),
|
|
"status": ChSystems.quest_status(after, 2000000 + 5000)})
|
|
|
|
|
|
func _autoclicker() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
profile["gold"] = 5000
|
|
var buy := ProfileStore.buy_autoclicker(profile)
|
|
_check(bool(buy.get("ok")) and int(buy.get("price", 0)) == 1000, "first purchase costs 1000 gold")
|
|
_check(int(profile.get("gold", 0)) == 4000, "purchase debits gold")
|
|
var state := {"owned": 1, "remainder": 0.0, "timer": 0.0}
|
|
var step: Dictionary = ChSystems.autoclicker_advance(state, 0.25)
|
|
_check(int(step.get("clicks", 0)) == 2, "one auto-clicker at 10/s yields 2 clicks in 0.25 s")
|
|
_check(bool(step.get("service")), "service tick fires after 0.1 s")
|
|
var again: Dictionary = ChSystems.autoclicker_advance(state, 0.25)
|
|
_check(int(again.get("clicks", 0)) >= 2, "remainder carries into the next advance")
|
|
var ticks := ProfileStore.tick_ch_services(profile, 0.25, true)
|
|
_check(int(ticks.get("clicks", 0)) >= 2, "runtime tick accumulates autoclicks")
|
|
_check(int((profile.get("autoclick", {}) as Dictionary).get("owned", 0)) == 1, "owned count survives tick")
|
|
_check(ProfileStore.ch_auto_dps(profile) >= 10.0, "autoclicks contribute dps-equivalent output")
|
|
_record("autoclick", {"buy": buy, "step": step, "remainder": state.get("remainder"),
|
|
"dps": ProfileStore.ch_auto_dps(profile)})
|
|
|
|
|
|
func _achievement() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
var first := ProfileStore.tick_ch_services(profile, 0.016, false)
|
|
_check(not bool(first.get("achievement")), "achievement stays locked before a rebuild")
|
|
profile["rebuild_count"] = 1
|
|
var second := ProfileStore.tick_ch_services(profile, 0.016, true)
|
|
_check(bool(second.get("achievement")), "first world reset unlocks CH achievement 43")
|
|
var ach: Dictionary = profile.get("ch_achievements", {})
|
|
_check(int(ach.get("click_bonus", 0)) == ChSystems.CLICK_BONUS_AMOUNT, "click bonus is the pinned +10")
|
|
_check((ach.get("obtained", []) as Array).has(ChSystems.CLICK_BONUS_ACHIEVEMENT_ID), "achievement id 43 recorded")
|
|
_check(is_equal_approx(ProfileStore.ch_auto_dps(profile), float(ChSystems.CLICK_BONUS_AMOUNT)),
|
|
"achievement bonus reaches the auto-click output adapter")
|
|
var third := ProfileStore.tick_ch_services(profile, 0.016, true)
|
|
_check(not bool(third.get("achievement")), "achievement cannot unlock twice")
|
|
# The shell persists on the unlock tick; the domain probe does the same.
|
|
_check(ProfileStore.save_profile(profile), "achievement state must be writable")
|
|
var reloaded := ProfileStore.load_profile()
|
|
var ra: Dictionary = reloaded.get("ch_achievements", {})
|
|
_check(int(ra.get("click_bonus", 0)) == ChSystems.CLICK_BONUS_AMOUNT, "achievement persisted")
|
|
_record("achievement", {"first": first, "second": second, "bonus": ach.get("click_bonus")})
|
|
|
|
|
|
func _clickable() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
var click: Dictionary = profile.get("clickable", {})
|
|
# One minute of 30 Hz ticks at the pinned 1/1800 chance: the deterministic
|
|
# source stream may or may not spawn; force the known seed path by advancing
|
|
# enough time, then assert the one-active-UID invariant.
|
|
var spawned := false
|
|
for _i in 120:
|
|
if ChSystems.clickable_advance(click, 1.0, true):
|
|
spawned = true
|
|
break
|
|
_check(spawned, "a windfall spawns within a bounded play window")
|
|
var uid := int(click.get("active_uid", 0))
|
|
_check(uid > 0, "spawned windfall owns a positive UID")
|
|
var blocked: bool = ChSystems.clickable_advance(click, 60.0, true)
|
|
_check(not blocked, "no second windfall while one is active")
|
|
profile["clickable"] = click
|
|
var before := int(profile.get("crystal", 0))
|
|
var claim := ProfileStore.claim_clickable(profile, uid)
|
|
_check(bool(claim.get("ok")), "active windfall can be claimed")
|
|
_check(int(profile.get("crystal", 0)) >= before, "windfall pays crystal via the ruby->crystal adapter")
|
|
var tier := int(claim.get("tier", 0))
|
|
_check(tier in [0, 10, 20, 25], "tier is one of the pinned CH outcomes")
|
|
_check(int((profile.get("clickable", {}) as Dictionary).get("active_uid", 0)) == 0, "claim clears the active UID")
|
|
var replay := ProfileStore.claim_clickable(profile, uid)
|
|
_check(not bool(replay.get("ok")), "a claimed UID cannot pay twice")
|
|
var reloaded := ProfileStore.load_profile()
|
|
_check(int((reloaded.get("clickable", {}) as Dictionary).get("active_uid", 0)) == 0, "claim persisted")
|
|
_record("clickable", {"uid": uid, "tier": tier, "crystal": claim.get("crystal"), "replay": replay})
|
|
|
|
|
|
func _offline_consumer() -> void:
|
|
var profile := ProfileStore.fresh_profile()
|
|
profile["gold"] = 5000
|
|
ProfileStore.buy_autoclicker(profile)
|
|
profile["rebuild_count"] = 1
|
|
ProfileStore.tick_ch_services(profile, 0.016, true)
|
|
profile["last_saved_at"] = int(Time.get_unix_time_from_system()) - 3600
|
|
profile["offline_anchor_ms"] = int(profile["last_saved_at"]) * 1000
|
|
var report := ProfileStore.build_offline_report(profile, 33.0 + ProfileStore.ch_auto_dps(profile))
|
|
_check(report is Dictionary and not report.is_empty(), "autoclick dps feeds a real offline report")
|
|
_check(int(report.get("gold", 0)) > 0, "offline report pays gold")
|
|
_record("offline_consumer", {"dps": ProfileStore.ch_auto_dps(profile), "gold": report.get("gold")})
|
|
|
|
|
|
func _corruption_and_migration() -> void:
|
|
var old := ProfileStore.fresh_profile()
|
|
old["schema"] = 6
|
|
old["gold"] = 77
|
|
old.erase("merc_quests")
|
|
old.erase("autoclick")
|
|
old.erase("clickable")
|
|
old.erase("ch_achievements")
|
|
var migrated := ProfileStore._migrate(old)
|
|
_check(int(migrated.get("schema", 0)) == ProfileStore.SCHEMA, "v6 migrates to current schema")
|
|
_check(int(migrated.get("gold", 0)) == 77, "v6 gold carried forward")
|
|
_check(migrated.has("autoclick") and migrated.has("clickable"), "v7 fields added additively")
|
|
var bad := ProfileStore.fresh_profile()
|
|
bad["merc_quests"] = [{"uid": -5, "level": 9999, "quest": {"reward": 9, "duration": 9, "start": -1, "quantity": 999}}]
|
|
bad["autoclick"] = {"owned": -3, "remainder": 5.0, "timer": -1.0, "total_clicks": -1, "service_ticks": -2}
|
|
bad["clickable"] = {"spawn_seed": -1, "reward_seed": 0, "next_uid": 2, "active_uid": 9,
|
|
"phase": 3.0, "total_claims": 0, "ruby_rewards": 5, "revision": -1}
|
|
bad["ch_achievements"] = {"obtained": [999, 43], "click_bonus": 999, "revision": -4}
|
|
var safe := ProfileStore.normalize_for_test(bad)
|
|
_check((safe.get("merc_quests", []) as Array).is_empty(), "corrupt merc slot dropped")
|
|
var auto: Dictionary = safe.get("autoclick", {})
|
|
_check(int(auto.get("owned", -1)) == 0 and float(auto.get("remainder", -1)) == 0.0, "corrupt autoclick reset")
|
|
var click: Dictionary = safe.get("clickable", {})
|
|
_check(int(click.get("active_uid", -1)) == 0 and float(click.get("phase", -1)) == 0.0, "corrupt clickable reset")
|
|
var ach: Dictionary = safe.get("ch_achievements", {})
|
|
_check((ach.get("obtained", []) as Array).max() == ChSystems.CLICK_BONUS_ACHIEVEMENT_ID,
|
|
"unknown achievement id dropped")
|
|
_check(int(ach.get("click_bonus", -1)) == ChSystems.CLICK_BONUS_AMOUNT, "bonus recomputed from known id")
|
|
_record("corruption", {"schema": migrated.get("schema"), "gold": migrated.get("gold"),
|
|
"safe_autoclick": auto, "safe_clickable": click, "safe_ach": ach})
|
|
DirAccess.remove_absolute(ProfileStore.save_path())
|
|
|
|
|
|
func _finish() -> void:
|
|
var passed := _problems.is_empty()
|
|
var report := {"schema": 1, "kind": "windroost_ch_systems_test",
|
|
"ch_source_revision": REVISION, "overall": "PASS" if passed else "FAIL",
|
|
"problems": _problems, "steps": _steps}
|
|
var dir := ProjectSettings.globalize_path("res://artifacts")
|
|
DirAccess.make_dir_recursive_absolute(dir)
|
|
var out := FileAccess.open(dir.path_join("ch_systems_test.json"), FileAccess.WRITE)
|
|
if out != null:
|
|
out.store_string(JSON.stringify(report, "\t", true))
|
|
out.close()
|
|
for e in _steps:
|
|
print("CH_SYSTEMS_STEP %s" % JSON.stringify(e))
|
|
if passed:
|
|
print("CH_SYSTEMS_DOMAIN_PASS")
|
|
else:
|
|
print("CH_SYSTEMS_DOMAIN_FAIL %s" % "; ".join(_problems))
|
|
quit(0 if passed else 1)
|