Continued FULL_GAME_GOAL. The three side systems had authored content but no runtime, so none of their numbers were actually used. Added a Python-authoritative engine and a GDScript mirror (parity gate over 3 profile tiers) plus a real UI. - 5 partners: tiered low-pressure tasks derived from play counters (distance, relics, records, wins, new skies), no combat and no failure penalty, claim once per tier for gold/crystal. - 167 records: progress from play counters, stage rewards every third record, one-time claims, no miss penalty or daily streak; list shows claimable milestones and X/167 progress. - 6 black-market offers: crystal-only purchases (relic/emblem/material/cosmetic/ time/recovery), no pay-to-win; insufficient balance is a clean rejection. - Skyport 旅团事务 page with three tabs; claims/purchases route through the real engines and persist. Added battle_wins/total_gold_earned/partner_claims/ revive_charges/cosmetics profile fields with normalization, and victory now increments the win/earned counters in both slice and world flows. - side_systems_ui_test drives tabs/claims/purchases/locale through real hooks; registered alongside parity in the full gate. Added p3a_side capture and ignored regenerated artifact files. All gates pass incl. 25 UI captures; P2_CHECKS_PASS. prototype/ untracked.
213 lines
8.7 KiB
Python
213 lines
8.7 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),
|
|
"收集": ("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()),
|
|
"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)
|
|
profile["gold"] = _num(profile, "gold") + row["reward_gold"]
|
|
profile["crystal"] = _num(profile, "crystal") + row["reward_crystal"]
|
|
return {"ok": True, "gold": row["reward_gold"], "crystal": row["reward_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}
|