Files
myrzx_bot/ranch_assistant/maps.py
T

83 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from dataclasses import dataclass
import json
from .quests import condition_ok, stage_has_level
def reward_summary(catalog, reward):
"""List configured possible rewards without rolling the random pool."""
if isinstance(reward, str):
try:
reward = json.loads(reward)
except ValueError:
return "附件格式未知"
if not isinstance(reward, dict):
return ""
parts = [f"{label} {reward[key]}" for key, label in (("money", "金币"), ("ke", "氪金"), ("ti", "体力"), ("exp", "经验")) if reward.get(key)]
names = catalog.data.get("item_names", {})
for piece in reward.get("rewards") or []:
if not isinstance(piece, dict):
continue
if piece.get("num", 0) > 0 and float(piece.get("chance", 1)) > 0:
for mon in piece.get("monsters") or []:
key = str(mon["name"])
parts.append(catalog.monster(key).get("name", key) + ("蛋" if not piece.get("monMode") else ""))
if piece.get("item_num", 0) > 0 and float(piece.get("item_chance", 1)) > 0:
for item in piece.get("items") or []:
values = str(item["name"]).split(",")
count = ""
if len(values) >= 3:
count = " ×" + (values[1] if values[1] == values[2] else values[1] + "~" + values[2])
parts.append(names.get(values[0], values[0]) + count)
for item in reward.get("items") or []:
key = str(item.get("type", item.get("typeId", "?")))
parts.append(f"{names.get(key, key)} ×{item.get('num', 1)}")
for mon in reward.get("mons") or []:
key = str(mon.get("type", "?"))
parts.append(f"{catalog.monster(key).get('name', key)}{'蛋' if not mon.get('mode') else ''} ×{mon.get('num', 1)}")
return ";".join(dict.fromkeys(parts))
@dataclass
class Stage:
stage_id: str
level: str
name: str
city: int
unlocked: bool
passed: bool
open: bool
stamina: int
tickets: str
number: str = ""
city_name: str = ""
stars: int = 0
sweep: bool = False
drops: str = ""
reason: str = ""
def stages(catalog, snapshot):
history = snapshot.raw.get("history") or {}
cities = catalog.data["game_setting"].get("cityInfo", {})
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)
city = int(row.get("city") or 0)
city_info = cities.get(str(city), {})
passed_levels = [i for i in (1, 2, 3) if stage_has_level(history, "passStage", key, i)]
sweep = not row.get("special") and not row.get("posmode") and len(passed_levels) == 3
for level, info in row.get("level", {}).items():
unlocked = stage_has_level(history, "unlockStage", key, level)
passed = stage_has_level(history, "passStage", key, level)
gate = city_info.get({"2": "openHardModeStage", "3": "openExtraModeStage"}.get(str(level), ""))
unlocked = unlocked and not info.get("levelLock") and (not gate or stage_has_level(history, "passStage", gate, 1))
base = row.get("cost") or {}
tickets = ", ".join(f"{catalog.data.get('item_names', {}).get(str(i['typeId']), i['typeId'])}×{i['num']}" for i in base.get("items", []))
reason = "未解锁" if not unlocked else "当前未开放" if not opened else "特殊关卡需手机实战" if row.get("special") or row.get("posmode") else "需三个难度全部通关" if not sweep else "可扫荡"
result.append(Stage(key, str(level), row.get("name") or key, city, unlocked, passed, opened,
int(base.get("ti") or 0) + int(info.get("cost") or 0), tickets,
row.get("tagname") or key, city_info.get("name", f"地区 {city}"), max(passed_levels, default=0),
sweep and unlocked and opened, reward_summary(catalog, info.get("reward")), reason))
return result