Port the minimal garrison record path from 8efd447: RECORD_METRICS and metrics() gain 驻扎/garrison_arrange_count in both Python and GDScript; profile gains additive garrison state with save-first one-shot arrange count. The arrange entry point is a quiet row on the side page (where the records live) so the current skyport action layout and its 360px touch flow stay unchanged. Adds real-ScreenTouch evidence for the records summary (167), A137/A142 rows, claims and save cold read.
243 lines
8.6 KiB
GDScript
243 lines
8.6 KiB
GDScript
class_name SideSystems
|
|
extends RefCounted
|
|
|
|
## Runtime mirror of tools/fullgame/side_systems.py (checked by parity gate).
|
|
## Partners: low-pressure tiered tasks, never combat, no failure penalty.
|
|
## Records: milestone progress from play counters, stage rewards, no daily bind.
|
|
## Market: crystal-only offers, no pay-to-win.
|
|
|
|
const WorldContent = preload("res://scripts/world_content.gd")
|
|
const PartnerPerks = preload("res://scripts/partner_perks.gd")
|
|
|
|
const PARTNER_TASKS := {
|
|
"P01": ["highest_node", 10],
|
|
"P02": ["relic_count", 1],
|
|
"P03": ["records_claimed", 3],
|
|
"P04": ["battle_wins", 5],
|
|
"P05": ["new_sky_count", 1],
|
|
}
|
|
const MAX_TIER := 5
|
|
const RECORD_METRICS := {
|
|
"推进": ["nodes_cleared", 1],
|
|
"战斗": ["battle_wins", 2],
|
|
"英雄": ["unlocked_hero_count", 2],
|
|
"Build": ["talent_count", 1],
|
|
"转生": ["essence_tier", 20],
|
|
"经济": ["gold_tier", 1000],
|
|
"伙伴": ["partner_tiers", 1],
|
|
"驻扎": ["garrison_arrange_count", 1],
|
|
"收集": ["collectibles", 1],
|
|
"终局": ["final_clears", 1],
|
|
}
|
|
const MARKET_PRICES := {"M01": 40, "M02": 30, "M03": 20, "M04": 15, "M05": 10, "M06": 12}
|
|
|
|
|
|
static func _num(profile: Dictionary, key: String) -> int:
|
|
var value = profile.get(key, 0)
|
|
if not (value is int or value is float):
|
|
return 0
|
|
return maxi(0, int(value))
|
|
|
|
|
|
static func _count(profile: Dictionary, key: String) -> int:
|
|
var value = profile.get(key)
|
|
if value is Dictionary or value is Array:
|
|
return (value as Array).size() if value is Array else (value as Dictionary).size()
|
|
return 0
|
|
|
|
|
|
static func metrics(profile: Dictionary) -> Dictionary:
|
|
var claimed: Array = profile.get("claimed_rewards", [])
|
|
var records_claimed := 0
|
|
for r in claimed:
|
|
if str(r).begins_with("A"):
|
|
records_claimed += 1
|
|
var partner_tiers := 0
|
|
var pc: Dictionary = profile.get("partner_claims", {})
|
|
for v in pc.values():
|
|
if v is Array:
|
|
partner_tiers += (v as Array).size()
|
|
return {
|
|
"highest_node": _num(profile, "highest_node"),
|
|
"relic_count": _count(profile, "relics"),
|
|
"records_claimed": records_claimed,
|
|
"battle_wins": _num(profile, "battle_wins"),
|
|
"new_sky_count": _num(profile, "new_sky_count"),
|
|
"nodes_cleared": (profile.get("completed_nodes", []) as Array).size(),
|
|
"unlocked_hero_count": _count(profile, "unlocked_heroes"),
|
|
"talent_count": _count(profile, "talents"),
|
|
"essence_tier": _num(profile, "total_essence_earned"),
|
|
"gold_tier": _num(profile, "total_gold_earned"),
|
|
"partner_tiers": partner_tiers,
|
|
"garrison_arrange_count": _num(profile, "garrison_arrange_count"),
|
|
"collectibles": _count(profile, "relics") + _count(profile, "emblems"),
|
|
"final_clears": _num(profile, "final_boss_first_clears"),
|
|
}
|
|
|
|
|
|
static func partner_status(profile: Dictionary, partners: Array) -> Array:
|
|
var m := metrics(profile)
|
|
var claims: Dictionary = profile.get("partner_claims", {})
|
|
var out: Array = []
|
|
for p in partners:
|
|
var row: Dictionary = p
|
|
var pid := str(row.get("id", ""))
|
|
if not PARTNER_TASKS.has(pid):
|
|
continue
|
|
var spec: Array = PARTNER_TASKS[pid]
|
|
var key := str(spec[0])
|
|
var step := int(spec[1])
|
|
var reached := mini(MAX_TIER, int(m[key]) / maxi(1, step))
|
|
var tiers: Array = claims.get(pid, [])
|
|
var claimed := tiers.size()
|
|
out.append({
|
|
"id": pid, "name": row.get("name", ""), "role": row.get("role", ""),
|
|
"metric": key, "progress": m[key], "step": step,
|
|
"level": reached, "claimed": claimed,
|
|
"claimable": maxi(0, reached - claimed),
|
|
"next_reward_gold": 20 * (claimed + 1),
|
|
"next_reward_crystal": 2 * (claimed + 1),
|
|
})
|
|
return out
|
|
|
|
|
|
static func claim_partner(profile: Dictionary, partner_id: String) -> Dictionary:
|
|
var status := partner_status(profile, _default_partners())
|
|
var row: Dictionary = {}
|
|
for r in status:
|
|
if str((r as Dictionary).get("id", "")) == partner_id:
|
|
row = r
|
|
break
|
|
if row.is_empty() or int(row.get("claimable", 0)) <= 0:
|
|
return {"ok": false, "reason": "no_claimable_task"}
|
|
var claims: Dictionary = profile.get("partner_claims", {})
|
|
if not claims.has(partner_id):
|
|
claims[partner_id] = []
|
|
var tiers: Array = claims[partner_id]
|
|
var tier := int(row.get("claimed", 0)) + 1
|
|
tiers.append(tier)
|
|
claims[partner_id] = tiers
|
|
profile["partner_claims"] = claims
|
|
var gold := 20 * tier
|
|
var crystal := 2 * tier
|
|
profile["gold"] = _num(profile, "gold") + gold
|
|
profile["crystal"] = _num(profile, "crystal") + crystal
|
|
return {"ok": true, "tier": tier, "gold": gold, "crystal": crystal}
|
|
|
|
|
|
static func _default_partners() -> Array:
|
|
var out: Array = []
|
|
for pid in PARTNER_TASKS.keys():
|
|
out.append({"id": pid, "name": pid, "role": ""})
|
|
return out
|
|
|
|
|
|
static func record_status(profile: Dictionary, records: Array) -> Array:
|
|
var m := metrics(profile)
|
|
var claimed: Array = profile.get("claimed_rewards", [])
|
|
var out: Array = []
|
|
for r in records:
|
|
var row: Dictionary = r
|
|
var rid := str(row.get("id", ""))
|
|
var cat := str(row.get("category", ""))
|
|
if not RECORD_METRICS.has(cat):
|
|
continue
|
|
var spec: Array = RECORD_METRICS[cat]
|
|
var key := str(spec[0])
|
|
var step := int(spec[1])
|
|
var order := maxi(1, int(row.get("order", 1)))
|
|
var target := order * step
|
|
var complete := int(m[key]) >= target
|
|
var is_claimed := claimed.has(rid)
|
|
var stage := str(row.get("reward_kind", "")) == "stage"
|
|
out.append({
|
|
"id": rid, "category": cat, "order": order,
|
|
"metric": key, "target": target,
|
|
"progress": mini(int(m[key]), target),
|
|
"complete": complete, "claimed": is_claimed,
|
|
"claimable": complete and not is_claimed,
|
|
"reward_gold": 100 if stage else 20,
|
|
"reward_crystal": 5 if stage else 1,
|
|
})
|
|
return out
|
|
|
|
|
|
static func claim_record(profile: Dictionary, record_id: String, records: Array) -> Dictionary:
|
|
var row: Dictionary = {}
|
|
for r in record_status(profile, records):
|
|
if str((r as Dictionary).get("id", "")) == record_id:
|
|
row = r
|
|
break
|
|
if row.is_empty() or not bool(row.get("claimable", false)):
|
|
return {"ok": false, "reason": "record_not_claimable"}
|
|
var claimed: Array = profile.get("claimed_rewards", [])
|
|
claimed.append(record_id)
|
|
profile["claimed_rewards"] = claimed
|
|
# Partner P03 (记录官) specialty: record rewards scale with its level.
|
|
var paid := PartnerPerks.apply_record_reward(profile, int(row.get("reward_gold", 0)), int(row.get("reward_crystal", 0)))
|
|
var gold := int(paid["gold"])
|
|
var crystal := int(paid["crystal"])
|
|
profile["gold"] = _num(profile, "gold") + gold
|
|
profile["crystal"] = _num(profile, "crystal") + crystal
|
|
return {"ok": true, "gold": gold, "crystal": crystal}
|
|
|
|
|
|
static func market_status(profile: Dictionary, market: Array) -> Array:
|
|
var crystal := _num(profile, "crystal")
|
|
var out: Array = []
|
|
for m in market:
|
|
var row: Dictionary = m
|
|
var oid := str(row.get("id", ""))
|
|
var price := int(MARKET_PRICES.get(oid, 0))
|
|
out.append({
|
|
"id": oid, "category": row.get("category", ""), "price": price,
|
|
"affordable": crystal >= price,
|
|
"currency": "crystal", "pay_to_win": false,
|
|
})
|
|
return out
|
|
|
|
|
|
static func purchase(profile: Dictionary, offer_id: String, pack: Dictionary) -> Dictionary:
|
|
var price: int = MARKET_PRICES.get(offer_id, -1)
|
|
if price < 0:
|
|
return {"ok": false, "reason": "unknown_offer"}
|
|
if _num(profile, "crystal") < price:
|
|
return {"ok": false, "reason": "insufficient_crystal"}
|
|
profile["crystal"] = _num(profile, "crystal") - price
|
|
var effects := {"M01": "relic", "M02": "emblem", "M03": "star_fragments",
|
|
"M04": "cosmetic", "M05": "time_tool", "M06": "recovery"}
|
|
var effect := str(effects.get(offer_id, ""))
|
|
if effect == "relic":
|
|
var owned: Dictionary = profile.get("relics", {})
|
|
for r in pack.get("relics", []):
|
|
var rid := str((r as Dictionary).get("id", ""))
|
|
if not rid.is_empty() and not owned.has(rid):
|
|
owned[rid] = true
|
|
profile["relics"] = owned
|
|
return {"ok": true, "effect": effect, "granted": rid}
|
|
elif effect == "emblem":
|
|
var owned2: Dictionary = profile.get("emblems", {})
|
|
for i in range(1, 7):
|
|
var eid := "E%02d" % i
|
|
if not owned2.has(eid):
|
|
owned2[eid] = true
|
|
profile["emblems"] = owned2
|
|
return {"ok": true, "effect": effect, "granted": eid}
|
|
elif effect == "star_fragments":
|
|
profile["star_fragments"] = _num(profile, "star_fragments") + 25
|
|
elif effect == "cosmetic":
|
|
var cosmetics: Dictionary = profile.get("cosmetics", {})
|
|
cosmetics[offer_id] = true
|
|
profile["cosmetics"] = cosmetics
|
|
elif effect == "time_tool":
|
|
var gold := 200 + 2 * _num(profile, "highest_node")
|
|
profile["gold"] = _num(profile, "gold") + gold
|
|
profile["total_gold_earned"] = _num(profile, "total_gold_earned") + gold
|
|
return {"ok": true, "effect": effect, "gold": gold}
|
|
elif effect == "recovery":
|
|
profile["revive_charges"] = _num(profile, "revive_charges") + 1
|
|
var gold2 := 100
|
|
profile["gold"] = _num(profile, "gold") + gold2
|
|
return {"ok": true, "effect": effect, "gold": gold2}
|
|
return {"ok": true, "effect": effect}
|