from dataclasses import dataclass from .quests import condition_ok, indexed @dataclass class Stage: stage_id: str level: str name: str city: int unlocked: bool passed: bool open: bool stamina: int tickets: str def stages(catalog, snapshot): history = snapshot.raw.get("history", {}) result = [] for key, row in catalog.data["stage_info"].items(): special = catalog.data.get("stage_sp", {}).get(key, {}) opened = not row.get("closed") and condition_ok(special.get("condition"), snapshot) for level, info in row.get("level", {}).items(): unlocked = indexed(indexed(history.get("unlockStage"), key), level, False) == True passed = indexed(indexed(history.get("passStage"), key), level, False) == True base = row.get("cost") or {} tickets = ", ".join(f"{i['typeId']}×{i['num']}" for i in base.get("items", [])) result.append(Stage(key, str(level), row.get("name", key), int(row.get("city", 0)), unlocked, passed, opened, int(base.get("ti", 0)) + int(info.get("cost", 0)), tickets)) return result