新增冒险查看倒计时
This commit is contained in:
35
.tasks/2025-11-12_1_show_adventure_remaining_time.md
Normal file
35
.tasks/2025-11-12_1_show_adventure_remaining_time.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# 背景
|
||||
文件名:2025-11-12_1_show_adventure_remaining_time
|
||||
创建于:2025-11-12_15:54:56
|
||||
创建者:desktop-l305h65\admin
|
||||
主分支:main
|
||||
任务分支:无
|
||||
Yolo模式:Off
|
||||
|
||||
# 任务描述
|
||||
@WPSCombatSystem 当前冒险系统无法查看剩余时间, 我想要让 @combat_plugin_adventure.py (153-158) 中可以显示冒险时长
|
||||
|
||||
# 项目概览
|
||||
WPSCombatSystem 冒险子系统
|
||||
|
||||
# 分析
|
||||
当前冒险状态由 `combat_player_status.current_adventure_id` 标识,冒险启动时 `combat_service.start_adventure` 会写入 `combat_adventure_records`,其中 `expected_end_time` 记录预计结束时间。`combat_plugin_adventure._handle_continue_adventure` 在检测到 `current_adventure_id` 时直接返回固定提示,没有查询该记录,因此无法显示剩余时间。需要读取当前冒险记录并根据 `expected_end_time` 与当前时间的差值计算分钟数,用户要求倒计时采用向上取整。
|
||||
|
||||
# 提议的解决方案
|
||||
1. 在 `combat_service` 中新增 `get_adventure_by_id(adventure_id)`,查询 `combat_adventure_records` 并以字典返回,供插件层复用。
|
||||
2. 修改 `combat_plugin_adventure._handle_continue_adventure`:检测到 `current_adventure_id` 时调用上述方法查询冒险记录,若状态为 `in_progress` 则读取 `expected_end_time`,与当前时间比较计算剩余秒数,向上取整为分钟数 `(remaining_seconds + 59) // 60`,并在提示中展示剩余分钟及预计完成时间;若记录缺失或状态异常,返回带有错误说明的原始提示。
|
||||
3. 所有时间解析使用 `datetime.fromisoformat`,失败时捕获异常并退回默认提示。
|
||||
|
||||
# 当前执行步骤:"4. 更新任务进度记录"
|
||||
|
||||
# 任务进度
|
||||
2025-11-12_16:32:57
|
||||
- 已修改:Plugins/WPSCombatSystem/combat_service.py Plugins/WPSCombatSystem/combat_plugin_adventure.py .tasks/2025-11-12_1_show_adventure_remaining_time.md
|
||||
- 更改:新增服务层冒险查询方法,并在冒险插件中展示剩余时间信息,同时更新任务记录
|
||||
- 原因:支持冒险系统显示进行中冒险的倒计时
|
||||
- 阻碍因素:无
|
||||
- 状态:未确认
|
||||
|
||||
# 最终审查
|
||||
(空)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
|
||||
@@ -151,12 +152,50 @@ class WPSCombatAdventure(WPSCombatBase):
|
||||
current_adventure_id = status.get("current_adventure_id")
|
||||
|
||||
if current_adventure_id:
|
||||
adventure = service.get_adventure_by_id(current_adventure_id)
|
||||
if not adventure:
|
||||
return await self.send_markdown_message(
|
||||
"❌ 你已经在冒险中,请等待当前冒险完成",
|
||||
(
|
||||
"❌ 你已经在冒险中,但未找到相关记录,请稍后重试或联系管理员。"
|
||||
f"\n- 冒险ID:{current_adventure_id}"
|
||||
),
|
||||
chat_id,
|
||||
user_id
|
||||
)
|
||||
|
||||
expected_end_str = adventure.get("expected_end_time")
|
||||
try:
|
||||
expected_end = datetime.fromisoformat(expected_end_str) if expected_end_str else None
|
||||
except (TypeError, ValueError):
|
||||
expected_end = None
|
||||
|
||||
if expected_end:
|
||||
remaining_seconds = (expected_end - datetime.now()).total_seconds()
|
||||
if remaining_seconds <= 0:
|
||||
message = [
|
||||
"⏳ 当前冒险已进入结算,请稍候等待系统发放结果。",
|
||||
f"- 冒险ID:{current_adventure_id}",
|
||||
f"- 预计完成:{expected_end.strftime('%Y-%m-%d %H:%M')}"
|
||||
]
|
||||
else:
|
||||
remaining_minutes = int((remaining_seconds + 59) // 60)
|
||||
remaining_text = (
|
||||
"不到 1 分钟" if remaining_minutes == 0 else f"约 {remaining_minutes} 分钟"
|
||||
)
|
||||
message = [
|
||||
"⏳ 你已经在冒险中,请等待当前冒险完成。",
|
||||
f"- 冒险ID:{current_adventure_id}",
|
||||
f"- 剩余时间:{remaining_text}",
|
||||
f"- 预计完成:{expected_end.strftime('%Y-%m-%d %H:%M')}"
|
||||
]
|
||||
else:
|
||||
message = [
|
||||
"❌ 你已经在冒险中,但无法解析预计结束时间,请稍后重试。",
|
||||
f"- 冒险ID:{current_adventure_id}"
|
||||
]
|
||||
|
||||
return await self.send_markdown_message("\n".join(message), chat_id, user_id)
|
||||
|
||||
last_record = service.get_last_adventure_record(user_id)
|
||||
if not last_record:
|
||||
return await self.send_markdown_message(
|
||||
|
||||
@@ -639,6 +639,18 @@ class CombatService:
|
||||
row = cursor.fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
def get_adventure_by_id(self, adventure_id: int) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
根据冒险ID获取冒险记录
|
||||
"""
|
||||
cursor = self._db.conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM combat_adventure_records WHERE adventure_id = ?",
|
||||
(adventure_id,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
def start_adventure(
|
||||
self,
|
||||
user_id: int,
|
||||
|
||||
Reference in New Issue
Block a user