Files
windroost/tools/fullgame/side_systems.py
T
wushenghua ee3ec6ee21 fix(side-records): make A137/A142 garrison records visible and claimable
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.
2026-11-29 13:53:18 +08:00

218 lines
9.0 KiB
Python

#!/usr/bin/env python3
"""Side-system runtime (FINAL_GAME_DESIGN 11).
Authoritative model shared with GDScript (`side_systems.gd`) via a parity gate:
- 5 partners: low-pressure tasks, no combat, no failure penalty. Five tiers
each, metric-driven, one claim per tier.
- 167 records: milestones derived from play counters, stage rewards every
3rd record, no miss penalty, never bound to consecutive days.
- 6 black-market offers: crystal-only (in-game currency), never pay-to-win.
All state lives in the profile dict; nothing here depends on wall-clock time.
"""
from __future__ import annotations
from typing import Any, Dict, List
# partner id -> (metric key, threshold step per tier). Five tiers max.
PARTNER_TASKS: Dict[str, tuple] = {
"P01": ("highest_node", 10), # expedition distance
"P02": ("relic_count", 1), # gear/material mastery
"P03": ("records_claimed", 3), # archive progress
"P04": ("battle_wins", 5), # recovery work
"P05": ("new_sky_count", 1), # new-sky / rift work
}
MAX_TIER = 5
# record category -> (metric key, step). Record j of a category completes when
# metric >= j * step; the thresholds are reachable through ordinary play.
RECORD_METRICS: Dict[str, tuple] = {
"推进": ("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),
}
# market id -> (crystal price, effect key). No real-money path, no raw stats.
MARKET_PRICES: Dict[str, int] = {
"M01": 40, "M02": 30, "M03": 20, "M04": 15, "M05": 10, "M06": 12,
}
def _num(profile: Dict[str, Any], key: str) -> int:
value = profile.get(key, 0)
try:
n = int(value)
except (TypeError, ValueError):
return 0
return max(0, n)
def _count(profile: Dict[str, Any], key: str) -> int:
value = profile.get(key)
return len(value) if isinstance(value, (dict, list)) else 0
def metrics(profile: Dict[str, Any]) -> Dict[str, int]:
"""Derived counters used by both partners and records."""
claimed: List[str] = profile.get("claimed_rewards", []) or []
return {
"highest_node": _num(profile, "highest_node"),
"relic_count": _count(profile, "relics"),
"records_claimed": sum(1 for r in claimed if str(r).startswith("A")),
"battle_wins": _num(profile, "battle_wins"),
"new_sky_count": _num(profile, "new_sky_count"),
"nodes_cleared": len(profile.get("completed_nodes", []) or []),
"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": sum(len(v) for v in (profile.get("partner_claims") or {}).values()),
"garrison_arrange_count": _num(profile, "garrison_arrange_count"),
"collectibles": _count(profile, "relics") + _count(profile, "emblems"),
"final_clears": _num(profile, "final_boss_first_clears"),
}
def partner_status(profile: Dict[str, Any], partners: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
m = metrics(profile)
claims = profile.get("partner_claims") or {}
out = []
for p in partners:
pid = str(p.get("id", ""))
if pid not in PARTNER_TASKS:
continue
key, step = PARTNER_TASKS[pid]
reached = min(MAX_TIER, m[key] // max(1, step))
claimed = len(claims.get(pid, []) or [])
out.append({
"id": pid, "name": p.get("name", ""), "role": p.get("role", ""),
"metric": key, "progress": m[key], "step": step,
"level": reached, "claimed": claimed,
"claimable": max(0, reached - claimed),
"next_reward_gold": 20 * (claimed + 1),
"next_reward_crystal": 2 * (claimed + 1),
})
return out
def claim_partner(profile: Dict[str, Any], partner_id: str) -> Dict[str, Any]:
"""Claim the next task tier for one partner (no failure path)."""
status = {row["id"]: row for row in partner_status(profile, _default_partners())}
row = status.get(partner_id)
if row is None or row["claimable"] <= 0:
return {"ok": False, "reason": "no_claimable_task"}
claims = profile.setdefault("partner_claims", {})
tiers = claims.setdefault(partner_id, [])
tier = row["claimed"] + 1
tiers.append(tier)
gold = 20 * tier
crystal = 2 * tier
profile["gold"] = _num(profile, "gold") + gold
profile["crystal"] = _num(profile, "crystal") + crystal
return {"ok": True, "tier": tier, "gold": gold, "crystal": crystal}
def _default_partners() -> List[Dict[str, Any]]:
return [{"id": pid, "name": pid, "role": ""} for pid in PARTNER_TASKS]
def record_status(profile: Dict[str, Any], records: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
m = metrics(profile)
claimed: List[str] = profile.get("claimed_rewards", []) or []
out = []
for r in records:
rid = str(r.get("id", ""))
cat = str(r.get("category", ""))
if cat not in RECORD_METRICS:
continue
key, step = RECORD_METRICS[cat]
order = max(1, int(r.get("order", 1)))
target = order * step
complete = m[key] >= target
is_claimed = rid in claimed
stage = str(r.get("reward_kind", "")) == "stage"
out.append({
"id": rid, "category": cat, "order": order,
"metric": key, "target": target, "progress": min(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
def claim_record(profile: Dict[str, Any], record_id: str,
records: List[Dict[str, Any]]) -> Dict[str, Any]:
row = next((r for r in record_status(profile, records) if r["id"] == record_id), None)
if row is None or not row["claimable"]:
return {"ok": False, "reason": "record_not_claimable"}
claimed = profile.setdefault("claimed_rewards", [])
claimed.append(record_id)
# Partner P03 (记录官) specialty: record rewards scale with its level.
import partner_perks as PP
paid = PP.apply_record_reward(profile, row["reward_gold"], row["reward_crystal"])
profile["gold"] = _num(profile, "gold") + paid["gold"]
profile["crystal"] = _num(profile, "crystal") + paid["crystal"]
return {"ok": True, "gold": paid["gold"], "crystal": paid["crystal"]}
def market_status(profile: Dict[str, Any], market: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
crystal = _num(profile, "crystal")
return [{
"id": str(m.get("id", "")), "category": m.get("category", ""),
"price": MARKET_PRICES.get(str(m.get("id", "")), 0),
"affordable": crystal >= MARKET_PRICES.get(str(m.get("id", "")), 0),
"currency": "crystal", "pay_to_win": False,
} for m in market]
def purchase(profile: Dict[str, Any], offer_id: str, pack: Dict[str, Any]) -> Dict[str, Any]:
"""Buy one crystal-only offer. Returns ok=False on insufficient crystal."""
price = MARKET_PRICES.get(offer_id)
if price is None:
return {"ok": False, "reason": "unknown_offer"}
if _num(profile, "crystal") < price:
return {"ok": False, "reason": "insufficient_crystal"}
profile["crystal"] = _num(profile, "crystal") - price
effect = {
"M01": "relic", "M02": "emblem", "M03": "star_fragments",
"M04": "cosmetic", "M05": "time_tool", "M06": "recovery",
}[offer_id]
if effect == "relic":
owned = profile.setdefault("relics", {})
for r in pack.get("relics", []):
rid = str(r.get("id", ""))
if rid and rid not in owned:
owned[rid] = True
return {"ok": True, "effect": effect, "granted": rid}
elif effect == "emblem":
owned = profile.setdefault("emblems", {})
for i in range(1, 7):
eid = f"E{i:02d}"
if eid not in owned:
owned[eid] = True
return {"ok": True, "effect": effect, "granted": eid}
elif effect == "star_fragments":
profile["star_fragments"] = _num(profile, "star_fragments") + 25
elif effect == "cosmetic":
profile.setdefault("cosmetics", {})[offer_id] = True
elif effect == "time_tool":
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
gold = 100
profile["gold"] = _num(profile, "gold") + gold
return {"ok": True, "effect": effect, "gold": gold}
return {"ok": True, "effect": effect}