"""冒险系统插件 - PVE冒险模式""" from __future__ import annotations from typing import Optional from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig from .combat_plugin_base import WPSCombatBase logger: ProjectConfig = ProjectConfig() class WPSCombatAdventure(WPSCombatBase): """冒险系统插件""" def is_enable_plugin(self) -> bool: return True def wake_up(self) -> None: super().wake_up() logger.Log( "Info", f"{ConsoleFrontColor.GREEN}WPSCombatAdventure 插件已加载{ConsoleFrontColor.RESET}" ) self.register_plugin("冒险") self.register_plugin("adventure") self.register_plugin("继续冒险") # 恢复过期冒险 service = self.service() service.recover_overdue_adventures() async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]: """ 处理冒险命令 命令格式: - 冒险 开始 [食物1] [食物2] ... - 继续冒险 [食物1] [食物2] ... """ message = self.parse_message_after_at(message).strip() tokens = message.split() if not tokens: # 默认视为继续冒险,支持直接命令 `继续冒险` return await self._handle_continue_adventure(chat_id, user_id, []) # 判断是开始新冒险还是继续 command = tokens[0].lower() if command in ["开始", "start"]: # 开始新冒险(第1阶段) food_items = tokens[1:] if len(tokens) > 1 else [] return await self._handle_start_adventure(chat_id, user_id, food_items) elif command in ["继续", "continue"]: food_items = tokens[1:] if len(tokens) > 1 else [] return await self._handle_continue_adventure(chat_id, user_id, food_items) else: # 默认视为继续冒险,tokens 即为食物列表 food_items = tokens return await self._handle_continue_adventure(chat_id, user_id, food_items) async def _handle_start_adventure( self, chat_id: int, user_id: int, food_items: list ) -> Optional[str]: """处理开始新冒险""" service = self.service() # 第1阶段 stage = 1 success, msg, adventure_id = service.start_adventure( user_id=user_id, chat_id=chat_id, stage=stage, food_items=food_items, register_callback=self ) return await self.send_markdown_message(msg, chat_id, user_id) async def _handle_continue_adventure( self, chat_id: int, user_id: int, food_items: list ) -> Optional[str]: """处理继续冒险""" service = self.service() # 获取当前冒险状态 status = service.get_player_status(user_id) current_adventure_id = status.get("current_adventure_id") if current_adventure_id: return await self.send_markdown_message( "❌ 你已经在冒险中,请等待当前冒险完成", chat_id, user_id ) # 查找最近一次冒险结果 from PWF.CoreModules.database import get_db db = get_db() cursor = db.conn.cursor() cursor.execute( """ SELECT stage, status FROM combat_adventure_records WHERE user_id = ? ORDER BY adventure_id DESC LIMIT 1 """, (user_id,) ) row = cursor.fetchone() if not row: return await self.send_markdown_message( "❌ 你还没有完成任何冒险,请使用 `冒险 开始 [食物...]` 开始第1阶段", chat_id, user_id ) if row["status"] != "success": return await self.send_markdown_message( "❌ 最近一次冒险失败,冒险已结束。请先使用 `冒险 开始 [食物...]` 重新从第1阶段开始", chat_id, user_id ) # 下一阶段 next_stage = row["stage"] + 1 success, msg, adventure_id = service.start_adventure( user_id=user_id, chat_id=chat_id, stage=next_stage, food_items=food_items, register_callback=self ) return await self.send_markdown_message(msg, chat_id, user_id) async def _settle_adventure_callback( self, adventure_id: int, user_id: int, chat_id: int ) -> None: """冒险结算回调(时钟任务)""" service = self.service() success, msg, rewards = service.settle_adventure(adventure_id) # 发送结算消息 await self.send_markdown_message(msg, chat_id, user_id) def _help_message(self) -> str: """帮助信息""" return """# 🗺️ 冒险系统 **命令格式:** - `冒险 开始 [食物1] [食物2] ...`:开始第1阶段冒险 - `继续冒险 [食物1] [食物2] ...`:继续下一阶段 **说明:** - 每个阶段耗时翻倍(15min → 30min → 60min...) - 食物(果酒)是可选的,可提供buff加成(时间缩减、收益提升等) - 不提供食物也可以冒险,只是没有buff加成 - 成功率受装备强度和运势影响 - 失败会受伤,需消耗100积分治疗 - 成功后可选择继续或停止 **示例:** - `冒险 开始`:不使用食物开始第1阶段 - `冒险 开始 薄荷果酒`:使用1个薄荷果酒(时间缩减10%) - `继续冒险 银杏果酒 银杏果酒`:使用2个银杏果酒(时间缩减20%) """ __all__ = ["WPSCombatAdventure"]