"""Normal inventory actions and reviewed expansion quotes.""" from dataclasses import dataclass from .model import Action @dataclass(frozen=True) class Expansion: kind: str currency: str cost: int level: int index: int position: int = -1 @property def path(self): return "stackService/stackOpen" if self.kind == "stack" else "roomService/roomCreateBy" + ("Money" if self.currency == "money" else "Ke") @property def payload(self): return {"openType": 1 if self.currency == "money" else 2, "position": self.position} if self.kind == "stack" else {} @property def description(self): return f"{'开启坑位 ' + str(self.position + 1) if self.kind == 'stack' else '新建牧场'}:{self.cost} {'金币' if self.currency == 'money' else '氪金'},需要角色等级 {self.level}" def expansion_quote(catalog, snapshot, kind, currency, position=-1): if kind not in ("stack", "room") or currency not in ("money", "ke"): raise ValueError("未知扩建类型") history = snapshot.raw.get("history", {}) records = snapshot.raw["stacks" if kind == "stack" else "rooms"] if any(row.get("openType") is None for row in records): raise ValueError("尚未读到完整的设施开启类型,请刷新后重试") open_type = 1 if currency == "money" else 2 # HistoryVo derives these counters from actual openType records; legacy # history.numAdd* fields can remain zero and are not a price authority. index = sum(int(row["openType"]) == open_type for row in records) price = catalog.data.get(kind + "_price", {}).get(str(index)) if not price or int(price.get(currency, -1)) < 0: raise ValueError("该方式已达到扩建上限") cost, level = int(price[currency]), int(price["level" if currency == "money" else "kelevel"]) master = snapshot.raw["master"] if int(master.get("level", 0)) < level: raise ValueError(f"角色需要达到 {level} 级") if int(master.get(currency, 0)) < cost: raise ValueError(f"{'金币' if currency == 'money' else '氪金'}不足,需要 {cost}") if kind == "stack": total = int(catalog.data.get("stack_meta", {}).get("total", 0)) if not 0 <= position < total or position == 3: raise ValueError("请选择未开启的普通坑位;VIP坑位由VIP资格决定") if any(int(s.get("position", -1)) == position for s in snapshot.raw["stacks"]): raise ValueError("该坑位已经开启") elif currency == "money": passed = history.get("passTask") or {} learned = passed.get("1001011") is not None if isinstance(passed, dict) else "1001011" in {str(key) for key in passed} if not learned and not history.get("openFarmBuild"): raise ValueError("尚未解锁金币建设牧场功能(需完成任务1001011)") return Expansion(kind, currency, cost, level, index, position) def manual_monster_actions(catalog, snapshot, kind, monster_ids, target_id=0): ids = list(dict.fromkeys(int(mid) for mid in monster_ids)) if not ids or any(mid <= 0 or mid not in snapshot.monsters for mid in ids): raise ValueError("请选择仍存在的魔物") monsters = [snapshot.monsters[mid] for mid in ids] for mon in monsters: if (mon.get("lock") or mon.get("sysLock") or mon.get("entangle") or mon.get("inExploreTeam") or mon.get("inBuild") or int(mon["id"]) in snapshot.team_ids or any(mon.get(f"equip{i}") for i in range(1, 6))): raise ValueError("选中包含锁定、羁绊、在队、探索、建筑中或已装备的魔物,请先在游戏中调整") if mon.get("process") not in (2, 3) or int(mon.get("mode", 0)) != 2: raise ValueError("只能处理已成熟的魔物") if kind == "feed": target = snapshot.monsters.get(int(target_id)) if not target or target.get("process") != 3 or int(target_id) in ids: raise ValueError("喂养目标必须在牧场中,且不能作为素材") cap = catalog.max_level(target) if cap is None or int(target.get("level", 1)) >= cap: raise ValueError("目标已达到当前突破上限,或上限未知,不能喂养") if any(mon.get("process") != 3 for mon in monsters): raise ValueError("喂养素材需先从培育室收取到牧场") foods = "、".join(catalog.monster_label(mon) for mon in monsters) return [Action("feed", f"喂养 {catalog.monster_label(target)} ← {len(ids)} 只素材:{foods}", "monsterService/monsterIntensify", {"targetId": int(target_id), "foods": ids})] if kind != "sell": raise ValueError("未知魔物操作") return [Action("sell", f"派遣 {len(ids)} 只魔物", "monsterService/monsterSell", {"monsterIds": ids})]