Continued FULL_GAME_GOAL. Closed the last L5 gap: design 11.4's five occasional interactions existed only as text, so none were playable. - low_freq.py / low_freq.gd dual engines (parity over 3 profile tiers): wind echo (every 6 wins), supply buoy (5-tap minigame, no failure), company crate (every 10 nodes + pity), commission (every 2 chapters, no miss penalty), journal (chapter lore + return rewards). All counter-driven — no wall clock, no daily pressure, never interrupts combat. - Side page gained a 4th 偶遇 tab; claims/taps route through the real engines and persist. Added `buoy` profile field with normalized bounds. - interactions_ui_test drives all five through real hooks; parity + UI tests registered in the full gate. Regenerated-artifact ignores added. All gates pass; P2_CHECKS_PASS. prototype/ untracked.
137 lines
5.1 KiB
GDScript
137 lines
5.1 KiB
GDScript
class_name LowFreq
|
|
extends RefCounted
|
|
|
|
## GDScript mirror of tools/fullgame/low_freq.py (parity gate). Counter-driven,
|
|
## never wall-clock: no daily pressure, no miss penalty, no combat interruption.
|
|
|
|
const ECHO_EVERY_WINS := 6
|
|
const ECHO_GOLD := 30
|
|
const BUOY_EVERY_WINS := 4
|
|
const BUOY_TAPS := 5
|
|
const BUOY_CRYSTAL := 4
|
|
const CRATE_EVERY_NODES := 10
|
|
const CRATE_GOLD := 40
|
|
const CRATE_FRAGMENTS := 3
|
|
const COMMISSION_EVERY_CHAPTERS := 2
|
|
const COMMISSION_GOLD := 15
|
|
const JOURNAL_GOLD := 8
|
|
const JOURNAL_CRYSTAL := 1
|
|
|
|
|
|
static func _num(profile: Dictionary, key: String) -> int:
|
|
var v = profile.get(key, 0)
|
|
if not (v is int or v is float):
|
|
return 0
|
|
return maxi(0, int(v))
|
|
|
|
|
|
static func _claimed(profile: Dictionary, prefix: String) -> int:
|
|
var n := 0
|
|
for k in (profile.get("claimed_rewards", []) as Array):
|
|
if str(k).begins_with(prefix):
|
|
n += 1
|
|
return n
|
|
|
|
|
|
static func _claim(profile: Dictionary, key: String) -> void:
|
|
var claimed: Array = profile.get("claimed_rewards", [])
|
|
if not claimed.has(key):
|
|
claimed.append(key)
|
|
profile["claimed_rewards"] = claimed
|
|
|
|
|
|
static func _chapter_cleared(profile: Dictionary, chapter: String) -> bool:
|
|
for n in (profile.get("completed_nodes", []) as Array):
|
|
if str(n).begins_with(chapter + "-"):
|
|
return true
|
|
return false
|
|
|
|
|
|
static func status(profile: Dictionary, pack: Dictionary = {}) -> Dictionary:
|
|
var wins := _num(profile, "battle_wins")
|
|
var nodes := (profile.get("completed_nodes", []) as Array).size()
|
|
var chapters := _num(profile, "completed_chapters")
|
|
var buoy: Dictionary = profile.get("buoy", {})
|
|
var buoy_available := wins / BUOY_EVERY_WINS > _claimed(profile, "buoy-") and not bool(buoy.get("active", false))
|
|
var chapters_list: Array = []
|
|
for n in pack.get("nodes", []):
|
|
var ck := str((n as Dictionary).get("chapter", ""))
|
|
if not ck.is_empty() and _chapter_cleared(profile, ck) and not chapters_list.has(ck):
|
|
chapters_list.append(ck)
|
|
chapters_list.sort()
|
|
var unread: Array = []
|
|
for c in chapters_list:
|
|
if not (profile.get("claimed_rewards", []) as Array).has("journal-%s" % c):
|
|
unread.append(c)
|
|
return {
|
|
"echo": {"available": wins / ECHO_EVERY_WINS - _claimed(profile, "echo-"), "reward_gold": ECHO_GOLD},
|
|
"buoy": {"available": buoy_available, "active": bool(buoy.get("active", false)),
|
|
"taps": _num(buoy, "taps"), "need": BUOY_TAPS, "reward_crystal": BUOY_CRYSTAL},
|
|
"crate": {"available": nodes / CRATE_EVERY_NODES - _claimed(profile, "crate-"),
|
|
"reward_gold": CRATE_GOLD, "reward_fragments": CRATE_FRAGMENTS},
|
|
"commission": {"available": chapters / COMMISSION_EVERY_CHAPTERS - _claimed(profile, "commission-"),
|
|
"reward_gold": COMMISSION_GOLD},
|
|
"journal": {"unread": unread, "reward_gold": JOURNAL_GOLD, "reward_crystal": JOURNAL_CRYSTAL},
|
|
}
|
|
|
|
|
|
static func claim_echo(profile: Dictionary) -> Dictionary:
|
|
if int(status(profile)["echo"]["available"]) <= 0:
|
|
return {"ok": false, "reason": "no_echo"}
|
|
var tier := _claimed(profile, "echo-") + 1
|
|
_claim(profile, "echo-%d" % tier)
|
|
profile["gold"] = _num(profile, "gold") + ECHO_GOLD
|
|
return {"ok": true, "gold": ECHO_GOLD}
|
|
|
|
|
|
static func start_buoy(profile: Dictionary) -> Dictionary:
|
|
if not bool(status(profile)["buoy"]["available"]):
|
|
return {"ok": false, "reason": "buoy_unavailable"}
|
|
profile["buoy"] = {"active": true, "taps": 0}
|
|
return {"ok": true, "taps": 0}
|
|
|
|
|
|
static func tap_buoy(profile: Dictionary) -> Dictionary:
|
|
var buoy: Dictionary = profile.get("buoy", {})
|
|
if not bool(buoy.get("active", false)):
|
|
return {"ok": false, "reason": "buoy_not_active"}
|
|
var taps := _num(buoy, "taps") + 1
|
|
buoy["taps"] = taps
|
|
profile["buoy"] = buoy
|
|
if taps < BUOY_TAPS:
|
|
return {"ok": true, "taps": taps, "done": false}
|
|
var tier := _claimed(profile, "buoy-") + 1
|
|
_claim(profile, "buoy-%d" % tier)
|
|
profile["buoy"] = {"active": false, "taps": 0}
|
|
profile["crystal"] = _num(profile, "crystal") + BUOY_CRYSTAL
|
|
return {"ok": true, "taps": taps, "done": true, "crystal": BUOY_CRYSTAL}
|
|
|
|
|
|
static func claim_crate(profile: Dictionary) -> Dictionary:
|
|
if int(status(profile)["crate"]["available"]) <= 0:
|
|
return {"ok": false, "reason": "no_crate"}
|
|
var tier := _claimed(profile, "crate-") + 1
|
|
_claim(profile, "crate-%d" % tier)
|
|
profile["gold"] = _num(profile, "gold") + CRATE_GOLD
|
|
profile["star_fragments"] = _num(profile, "star_fragments") + CRATE_FRAGMENTS
|
|
return {"ok": true, "gold": CRATE_GOLD, "fragments": CRATE_FRAGMENTS}
|
|
|
|
|
|
static func claim_commission(profile: Dictionary) -> Dictionary:
|
|
if int(status(profile)["commission"]["available"]) <= 0:
|
|
return {"ok": false, "reason": "no_commission"}
|
|
var tier := _claimed(profile, "commission-") + 1
|
|
_claim(profile, "commission-%d" % tier)
|
|
profile["gold"] = _num(profile, "gold") + COMMISSION_GOLD
|
|
return {"ok": true, "gold": COMMISSION_GOLD}
|
|
|
|
|
|
static func claim_journal(profile: Dictionary, chapter: String) -> Dictionary:
|
|
var one_node := [{"chapter": chapter}]
|
|
if not (status(profile, {"nodes": one_node})["journal"]["unread"] as Array).has(chapter):
|
|
return {"ok": false, "reason": "journal_locked"}
|
|
_claim(profile, "journal-%s" % chapter)
|
|
profile["gold"] = _num(profile, "gold") + JOURNAL_GOLD
|
|
profile["crystal"] = _num(profile, "crystal") + JOURNAL_CRYSTAL
|
|
return {"ok": true, "gold": JOURNAL_GOLD, "crystal": JOURNAL_CRYSTAL}
|