1.修复一些bug2.冒险现在可以放弃
This commit is contained in:
@@ -728,6 +728,51 @@ async def handle_heal(self, user_id: int, chat_id: int) -> str:
|
||||
- 阻碍因素:无
|
||||
- 状态:成功
|
||||
|
||||
2025-11-10_19:40:20
|
||||
- 已修改:combat_service.py, combat_plugin_adventure.py
|
||||
- 更改:新增“停止冒险”指令,允许玩家立即放弃当前冒险且不获得奖励
|
||||
- 原因:满足手动终止冒险的需求,防止长时间等待仍无法退出
|
||||
- 完成内容:
|
||||
- 实现 `abort_current_adventure`,清理冒险状态并标记定时任务完成
|
||||
- 将提前终止的冒险记录为 `abandoned` 状态,避免奖励结算
|
||||
- 插件新增指令解析、帮助文案与用户反馈,阻止放弃后继续冒险
|
||||
- 阻碍因素:无
|
||||
- 状态:成功
|
||||
|
||||
2025-11-10_19:57:19
|
||||
- 已修改:combat_plugin_adventure.py, combat_plugin_adventure.py(WPSCombatAdventureAbort), Plugins/WPSCombatSystem/__init__.py
|
||||
- 更改:根据核心路由逻辑拆分“停止冒险”命令入口,新增独立插件并修正冒险命令解析
|
||||
- 原因:中央路由在进入插件前已移除命令词,原实现误用命令匹配导致放弃指令无效
|
||||
- 完成内容:
|
||||
- 还原冒险插件的命令注册,仅通过参数关键字触发放弃流程
|
||||
- 新增 `WPSCombatAdventureAbort` 插件,处理 `停止冒险` 等独立指令
|
||||
- 更新帮助文档、导出列表,并在模块入口导出新插件
|
||||
- 阻碍因素:无
|
||||
- 状态:成功
|
||||
|
||||
2025-11-10_20:45:09
|
||||
- 已修改:combat_service.py, combat_plugin_adventure.py
|
||||
- 更改:简化冒险指令逻辑,支持 `冒险 放弃` 作为冒险链终止指令,并统一结算后提示
|
||||
- 原因:阶段奖励应立即发放,同时允许玩家在结算后停止继续冒险
|
||||
- 完成内容:
|
||||
- 服务新增 `get_last_adventure_record`,供插件查询最近记录状态
|
||||
- `冒险` 命令加入放弃分支:进行中则终止,已结算则反馈奖励已发放
|
||||
- `继续冒险` 使用新查询接口,避免重复 SQL
|
||||
- 放弃插件扩展:若无进行中冒险,对最近记录返回友好提示
|
||||
- 帮助文档更新,明确命令用途与结算机制
|
||||
- 阻碍因素:无
|
||||
- 状态:成功
|
||||
|
||||
2025-11-10_20:55:00
|
||||
- 已修改:WPSConfigSystem.py, combat_service.py
|
||||
- 更改:修复冒险奖励与积分调整未生效问题
|
||||
- 原因:同步服务直接调用异步 `adjust_user_points` 未执行,导致积分不变
|
||||
- 完成内容:
|
||||
- 为 `WPSConfigAPI` 提供同步接口 `adjust_user_points_sync`
|
||||
- 冒险奖励、治疗费用、PVP胜负积分均改用同步接口
|
||||
- 阻碍因素:无
|
||||
- 状态:成功
|
||||
|
||||
# 最终审查
|
||||
|
||||
## 实施总结
|
||||
|
||||
2
PWF
2
PWF
Submodule PWF updated: ac68bb27a3...ca3cf114e3
@@ -12,7 +12,7 @@ from .combat_models import (
|
||||
from .combat_service import CombatService
|
||||
from .combat_plugin_status import WPSCombatStatus
|
||||
from .combat_plugin_equipment import WPSCombatEquipment
|
||||
from .combat_plugin_adventure import WPSCombatAdventure
|
||||
from .combat_plugin_adventure import WPSCombatAdventure, WPSCombatAdventureAbort
|
||||
from .combat_plugin_battle import WPSCombatBattle
|
||||
from .combat_plugin_heal import WPSCombatHeal
|
||||
|
||||
@@ -28,6 +28,7 @@ __all__ = [
|
||||
"WPSCombatStatus",
|
||||
"WPSCombatEquipment",
|
||||
"WPSCombatAdventure",
|
||||
"WPSCombatAdventureAbort",
|
||||
"WPSCombatBattle",
|
||||
"WPSCombatHeal",
|
||||
]
|
||||
|
||||
@@ -48,9 +48,11 @@ class WPSCombatAdventure(WPSCombatBase):
|
||||
# 默认视为继续冒险,支持直接命令 `继续冒险`
|
||||
return await self._handle_continue_adventure(chat_id, user_id, [])
|
||||
|
||||
# 判断是开始新冒险还是继续
|
||||
# 判断是开始新冒险、继续或结束
|
||||
command = tokens[0].lower()
|
||||
|
||||
if command in ["放弃", "停止"]:
|
||||
return await self._handle_finish_adventure(chat_id, user_id)
|
||||
if command in ["开始", "start"]:
|
||||
# 开始新冒险(第1阶段)
|
||||
food_items = tokens[1:] if len(tokens) > 1 else []
|
||||
@@ -85,6 +87,56 @@ class WPSCombatAdventure(WPSCombatBase):
|
||||
|
||||
return await self.send_markdown_message(msg, chat_id, user_id)
|
||||
|
||||
async def _handle_finish_adventure(
|
||||
self,
|
||||
chat_id: int,
|
||||
user_id: int
|
||||
) -> Optional[str]:
|
||||
"""处理结束冒险(不再继续)"""
|
||||
service = self.service()
|
||||
status = service.get_player_status(user_id)
|
||||
if status.get("current_adventure_id"):
|
||||
_success, msg = service.abort_current_adventure(user_id)
|
||||
return await self.send_markdown_message(msg, chat_id, user_id)
|
||||
|
||||
last_record = service.get_last_adventure_record(user_id)
|
||||
if not last_record:
|
||||
return await self.send_markdown_message(
|
||||
"ℹ️ 你尚未开始冒险,可使用 `冒险 开始`。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
record_status = last_record["status"]
|
||||
stage = last_record["stage"]
|
||||
if record_status == "success":
|
||||
return await self.send_markdown_message(
|
||||
(
|
||||
f"✅ 第 {stage} 阶段冒险已完成并发放奖励。\n"
|
||||
"若不再继续,冒险链已自然结束;未来可随时使用 `冒险 开始` 重新开启。"
|
||||
),
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if record_status == "failed":
|
||||
return await self.send_markdown_message(
|
||||
"❌ 最近一次冒险失败,奖励已结算且需要治疗或重新开始。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if record_status == "abandoned":
|
||||
return await self.send_markdown_message(
|
||||
"ℹ️ 上一次冒险已放弃,无需额外操作。如需重新开启,请使用 `冒险 开始`。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
return await self.send_markdown_message(
|
||||
f"ℹ️ 最近一次冒险状态为 {record_status},无需执行放弃指令。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
async def _handle_continue_adventure(
|
||||
self,
|
||||
chat_id: int,
|
||||
@@ -105,37 +157,35 @@ class WPSCombatAdventure(WPSCombatBase):
|
||||
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:
|
||||
last_record = service.get_last_adventure_record(user_id)
|
||||
if not last_record:
|
||||
return await self.send_markdown_message(
|
||||
"❌ 你还没有完成任何冒险,请使用 `冒险 开始 [食物...]` 开始第1阶段",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
if row["status"] != "success":
|
||||
if last_record["status"] == "failed":
|
||||
return await self.send_markdown_message(
|
||||
"❌ 最近一次冒险失败,冒险已结束。请先使用 `冒险 开始 [食物...]` 重新从第1阶段开始",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if last_record["status"] == "abandoned":
|
||||
return await self.send_markdown_message(
|
||||
"⚠️ 最近一次冒险已被你放弃,需要重新从第1阶段开始",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if last_record["status"] != "success":
|
||||
return await self.send_markdown_message(
|
||||
f"❌ 最近一次冒险状态为 {last_record['status']},无法继续。请使用 `冒险 开始 [食物...]` 重新冒险",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
# 下一阶段
|
||||
next_stage = row["stage"] + 1
|
||||
next_stage = last_record["stage"] + 1
|
||||
|
||||
success, msg, adventure_id = service.start_adventure(
|
||||
user_id=user_id,
|
||||
@@ -165,21 +215,87 @@ class WPSCombatAdventure(WPSCombatBase):
|
||||
return """# 🗺️ 冒险系统
|
||||
**命令格式:**
|
||||
- `冒险 开始 [食物1] [食物2] ...`:开始第1阶段冒险
|
||||
- `继续冒险 [食物1] [食物2] ...`:继续下一阶段
|
||||
- `继续冒险 [食物1] [食物2] ...` 或 `冒险 继续 ...`:继续下一阶段
|
||||
- `冒险 放弃`:结束当前冒险链(阶段奖励已结算)
|
||||
- `停止冒险` / `放弃冒险`:在冒险进行中立即终止当前阶段(无奖励)
|
||||
|
||||
**说明:**
|
||||
- 每个阶段耗时翻倍(15min → 30min → 60min...)
|
||||
- 食物(果酒)是可选的,可提供buff加成(时间缩减、收益提升等)
|
||||
- 不提供食物也可以冒险,只是没有buff加成
|
||||
- 成功率受装备强度和运势影响
|
||||
- 失败会受伤,需消耗100积分治疗
|
||||
- 成功后可选择继续或停止
|
||||
- 阶段结束时立即判定成功/失败并发放奖励
|
||||
- 完成后可选择继续下一阶段或直接放弃
|
||||
- 冒险失败会受伤,需要消耗100积分治疗
|
||||
|
||||
**示例:**
|
||||
- `冒险 开始`:不使用食物开始第1阶段
|
||||
- `冒险 开始 薄荷果酒`:使用1个薄荷果酒(时间缩减10%)
|
||||
- `继续冒险 银杏果酒 银杏果酒`:使用2个银杏果酒(时间缩减20%)
|
||||
- `继续冒险 银杏果酒`:继续下一阶段并使用银杏果酒
|
||||
- `冒险 放弃`:冒险阶段已结算但不再继续
|
||||
"""
|
||||
|
||||
|
||||
__all__ = ["WPSCombatAdventure"]
|
||||
class WPSCombatAdventureAbort(WPSCombatBase):
|
||||
"""冒险放弃指令插件"""
|
||||
|
||||
def is_enable_plugin(self) -> bool:
|
||||
return True
|
||||
|
||||
def wake_up(self) -> None:
|
||||
super().wake_up()
|
||||
logger.Log(
|
||||
"Info",
|
||||
f"{ConsoleFrontColor.GREEN}WPSCombatAdventureAbort 插件已加载{ConsoleFrontColor.RESET}"
|
||||
)
|
||||
self.register_plugin("停止冒险")
|
||||
self.register_plugin("放弃冒险")
|
||||
self.register_plugin("abort_adventure")
|
||||
|
||||
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
|
||||
"""直接放弃当前冒险"""
|
||||
service = self.service()
|
||||
status = service.get_player_status(user_id)
|
||||
|
||||
if status.get("current_adventure_id"):
|
||||
_success, msg = service.abort_current_adventure(user_id)
|
||||
return await self.send_markdown_message(msg, chat_id, user_id)
|
||||
|
||||
last_record = service.get_last_adventure_record(user_id)
|
||||
if not last_record:
|
||||
return await self.send_markdown_message(
|
||||
"ℹ️ 你尚未开始冒险,可使用 `冒险 开始`。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
record_status = last_record["status"]
|
||||
stage = last_record["stage"]
|
||||
if record_status == "success":
|
||||
return await self.send_markdown_message(
|
||||
(
|
||||
f"✅ 第 {stage} 阶段冒险已完成并发放奖励。\n"
|
||||
"若不再继续,冒险链已自然结束;未来可随时使用 `冒险 开始` 重新开启。"
|
||||
),
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if record_status == "failed":
|
||||
return await self.send_markdown_message(
|
||||
"❌ 最近一次冒险失败,奖励已结算且需要治疗或重新开始。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
if record_status == "abandoned":
|
||||
return await self.send_markdown_message(
|
||||
"ℹ️ 上一次冒险已放弃,无需额外操作。如需重新开启,请使用 `冒险 开始`。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
return await self.send_markdown_message(
|
||||
f"ℹ️ 最近一次冒险状态为 {record_status},无需执行放弃指令。",
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["WPSCombatAdventure", "WPSCombatAdventureAbort"]
|
||||
|
||||
@@ -10,7 +10,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from PWF.Convention.Runtime.Architecture import Architecture
|
||||
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
|
||||
from PWF.CoreModules.database import get_db
|
||||
from PWF.CoreModules.database import STATUS_COMPLETED, get_db
|
||||
from Plugins.WPSBackpackSystem import WPSBackpackSystem, BackpackItemTier
|
||||
from Plugins.WPSConfigSystem import WPSConfigAPI
|
||||
from Plugins.WPSFortuneSystem import WPSFortuneSystem
|
||||
@@ -382,7 +382,7 @@ class CombatService:
|
||||
return False, f"❌ 积分不足,治疗需要 {self.heal_cost} 积分,当前仅有 {user_points} 积分"
|
||||
|
||||
# 扣除积分
|
||||
config_api.adjust_user_points(0, user_id, -self.heal_cost, "治疗费用")
|
||||
config_api.adjust_user_points_sync(user_id, -self.heal_cost, "治疗费用")
|
||||
|
||||
# 解除受伤状态
|
||||
self.set_injured(user_id, False)
|
||||
@@ -535,6 +535,102 @@ class CombatService:
|
||||
# ========================================================================
|
||||
# 冒险系统 - 流程方法
|
||||
# ========================================================================
|
||||
|
||||
def abort_current_adventure(self, user_id: int) -> Tuple[bool, str]:
|
||||
"""
|
||||
立即放弃当前冒险(无奖励,清理状态)
|
||||
|
||||
Args:
|
||||
user_id: 玩家ID
|
||||
|
||||
Returns:
|
||||
(是否成功, 消息)
|
||||
"""
|
||||
cursor = self._db.conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT current_adventure_id FROM combat_player_status WHERE user_id = ?",
|
||||
(user_id,),
|
||||
)
|
||||
status_row = cursor.fetchone()
|
||||
|
||||
if not status_row or not status_row["current_adventure_id"]:
|
||||
return False, "❌ 当前没有进行中的冒险"
|
||||
|
||||
adventure_id = status_row["current_adventure_id"]
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT adventure_id, stage, status, scheduled_task_id
|
||||
FROM combat_adventure_records
|
||||
WHERE adventure_id = ?
|
||||
""",
|
||||
(adventure_id,),
|
||||
)
|
||||
adventure = cursor.fetchone()
|
||||
|
||||
if not adventure:
|
||||
cursor.execute(
|
||||
"UPDATE combat_player_status SET current_adventure_id = NULL WHERE user_id = ?",
|
||||
(user_id,),
|
||||
)
|
||||
self._db.conn.commit()
|
||||
return False, "❌ 未找到冒险记录,状态已重置"
|
||||
|
||||
if adventure["status"] != "in_progress":
|
||||
cursor.execute(
|
||||
"UPDATE combat_player_status SET current_adventure_id = NULL WHERE user_id = ?",
|
||||
(user_id,),
|
||||
)
|
||||
self._db.conn.commit()
|
||||
return False, f"❌ 冒险已结算(状态:{adventure['status']})"
|
||||
|
||||
scheduled_task_id = adventure["scheduled_task_id"]
|
||||
if scheduled_task_id:
|
||||
try:
|
||||
self._db.update_task_status(int(scheduled_task_id), STATUS_COMPLETED)
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
self._config.Log(
|
||||
"Warning",
|
||||
f"{ConsoleFrontColor.YELLOW}取消冒险定时任务失败: {exc}{ConsoleFrontColor.RESET}",
|
||||
)
|
||||
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE combat_adventure_records
|
||||
SET status = ?, rewards = NULL, scheduled_task_id = NULL
|
||||
WHERE adventure_id = ? AND status = 'in_progress'
|
||||
""",
|
||||
("abandoned", adventure_id),
|
||||
)
|
||||
cursor.execute(
|
||||
"UPDATE combat_player_status SET current_adventure_id = NULL WHERE user_id = ?",
|
||||
(user_id,),
|
||||
)
|
||||
self._db.conn.commit()
|
||||
|
||||
stage = adventure["stage"]
|
||||
self._config.Log(
|
||||
"Info",
|
||||
f"{ConsoleFrontColor.LIGHTCYAN_EX}用户 {user_id} 放弃冒险 {adventure_id}(阶段 {stage}){ConsoleFrontColor.RESET}",
|
||||
)
|
||||
|
||||
return True, f"⚠️ 已放弃第 {stage} 阶段冒险,本阶段奖励作废"
|
||||
|
||||
def get_last_adventure_record(self, user_id: int) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
获取最近一次冒险记录(无论状态)
|
||||
"""
|
||||
cursor = self._db.conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM combat_adventure_records
|
||||
WHERE user_id = ?
|
||||
ORDER BY adventure_id DESC
|
||||
LIMIT 1
|
||||
""",
|
||||
(user_id,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
def start_adventure(
|
||||
self,
|
||||
@@ -900,7 +996,7 @@ class CombatService:
|
||||
# 1. 积分
|
||||
if "points" in rewards:
|
||||
config_api: WPSConfigAPI = Architecture.Get(WPSConfigAPI)
|
||||
config_api.adjust_user_points(0, user_id, rewards["points"], "冒险奖励")
|
||||
config_api.adjust_user_points_sync(user_id, rewards["points"], "冒险奖励")
|
||||
|
||||
# 2. 物品
|
||||
if "items" in rewards:
|
||||
@@ -1396,8 +1492,8 @@ class CombatService:
|
||||
loser_points = config_api.get_user_points(0, loser_id)
|
||||
actual_reward = min(reward, loser_points)
|
||||
|
||||
config_api.adjust_user_points(0, loser_id, -actual_reward, f"PVP战斗失败(战斗{battle_id})")
|
||||
config_api.adjust_user_points(0, winner_id, actual_reward, f"PVP战斗胜利(战斗{battle_id})")
|
||||
config_api.adjust_user_points_sync(loser_id, -actual_reward, f"PVP战斗失败(战斗{battle_id})")
|
||||
config_api.adjust_user_points_sync(winner_id, actual_reward, f"PVP战斗胜利(战斗{battle_id})")
|
||||
|
||||
self._db.conn.commit()
|
||||
|
||||
|
||||
@@ -182,6 +182,10 @@ class WPSConfigAPI(WPSAPI):
|
||||
|
||||
async def adjust_user_points(self, chat_id: int, user_id: int, delta: int, reason: str = "") -> int:
|
||||
return await self._adjust_points(chat_id, user_id, delta, reason)
|
||||
|
||||
def adjust_user_points_sync(self, user_id: int, delta: int, reason: str = "") -> int:
|
||||
"""同步调整积分,供非异步流程使用"""
|
||||
return self._adjust_db_points(user_id, delta)
|
||||
|
||||
def _help_message(self) -> str:
|
||||
return '''# 🛠️ Config 命令帮助
|
||||
|
||||
3
swagger-ui-bundle.js
Normal file
3
swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
swagger-ui.css
Normal file
3
swagger-ui.css
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user