修复新增炼金系统时出现的错误
This commit is contained in:
@@ -11,6 +11,7 @@ from PWF.Convention.Runtime.Architecture import Architecture
|
||||
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
|
||||
from PWF.CoreModules.database import get_db, STATUS_COMPLETED
|
||||
from PWF.CoreModules.plugin_interface import DatabaseModel
|
||||
from PWF.CoreModules.flags import get_internal_debug
|
||||
|
||||
from .WPSAPI import WPSAPI
|
||||
from .WPSBackpackSystem import (
|
||||
@@ -25,6 +26,7 @@ from .WPSFortuneSystem import WPSFortuneSystem
|
||||
|
||||
logger: ProjectConfig = Architecture.Get(ProjectConfig)
|
||||
FORTUNE_COEFF:float = logger.FindItem("alchemy_fortune_coeff", 0.03)
|
||||
COOLDOWN_MINUTES:int = logger.FindItem("alchemy_cooldown_minutes", 2)
|
||||
logger.SaveProperties()
|
||||
|
||||
|
||||
@@ -64,12 +66,8 @@ class WPSAlchemyGame(WPSAPI):
|
||||
self._fail_index: Dict[str, Set[Tuple[str, str, str]]] = defaultdict(set)
|
||||
self._fortune_coeff = FORTUNE_COEFF
|
||||
# 从配置读取冷却时间(分钟)
|
||||
from PWF.CoreModules.flags import get_internal_debug
|
||||
cooldown_minutes = logger.FindItem("alchemy_cooldown_minutes", 2)
|
||||
if get_internal_debug():
|
||||
cooldown_minutes = 0
|
||||
self._cooldown_minutes = cooldown_minutes
|
||||
self._cooldown_ms = int(cooldown_minutes * 60 * 1000)
|
||||
self._cooldown_minutes = 0 if get_internal_debug() else COOLDOWN_MINUTES
|
||||
self._cooldown_ms = int(self._cooldown_minutes * 60 * 1000)
|
||||
logger.SaveProperties()
|
||||
|
||||
@override
|
||||
@@ -322,8 +320,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
)
|
||||
|
||||
# 注册定时任务
|
||||
task_id = None
|
||||
if self._cooldown_ms > 0:
|
||||
task_id = self.register_clock(
|
||||
self._settle_alchemy_callback,
|
||||
self._cooldown_ms,
|
||||
@@ -340,10 +336,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
(task_id, alchemy_id),
|
||||
)
|
||||
get_db().conn.commit()
|
||||
else:
|
||||
# Debug模式,立即结算
|
||||
success, msg, rewards = self.settle_alchemy(alchemy_id)
|
||||
return msg
|
||||
|
||||
# 计算预计完成时间
|
||||
cursor = get_db().conn.cursor()
|
||||
@@ -354,7 +346,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
record = cursor.fetchone()
|
||||
expected_end_time = datetime.fromisoformat(record["expected_end_time"])
|
||||
|
||||
from PWF.CoreModules.flags import get_internal_debug
|
||||
debug_hint = " **[DEBUG模式]**" if get_internal_debug() else ""
|
||||
|
||||
time_str = "立即结算" if self._cooldown_minutes == 0 else f"{self._cooldown_minutes} 分钟"
|
||||
@@ -430,8 +421,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
)
|
||||
|
||||
# 注册定时任务
|
||||
task_id = None
|
||||
if self._cooldown_ms > 0:
|
||||
task_id = self.register_clock(
|
||||
self._settle_alchemy_callback,
|
||||
self._cooldown_ms,
|
||||
@@ -448,10 +437,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
(task_id, alchemy_id),
|
||||
)
|
||||
get_db().conn.commit()
|
||||
else:
|
||||
# Debug模式,立即结算
|
||||
success, msg, rewards = self.settle_alchemy(alchemy_id)
|
||||
return msg
|
||||
|
||||
# 计算预计完成时间
|
||||
cursor = get_db().conn.cursor()
|
||||
@@ -462,7 +447,6 @@ class WPSAlchemyGame(WPSAPI):
|
||||
record = cursor.fetchone()
|
||||
expected_end_time = datetime.fromisoformat(record["expected_end_time"])
|
||||
|
||||
from PWF.CoreModules.flags import get_internal_debug
|
||||
debug_hint = " **[DEBUG模式]**" if get_internal_debug() else ""
|
||||
|
||||
time_str = "立即结算" if self._cooldown_minutes == 0 else f"{self._cooldown_minutes} 分钟"
|
||||
@@ -580,12 +564,14 @@ class WPSAlchemyGame(WPSAPI):
|
||||
|
||||
def settle_alchemy(self, alchemy_id: int) -> Tuple[bool, str, Optional[Dict]]:
|
||||
"""结算炼金"""
|
||||
import sqlite3
|
||||
|
||||
cursor = get_db().conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM alchemy_records WHERE alchemy_id = ?",
|
||||
(alchemy_id,),
|
||||
)
|
||||
record = cursor.fetchone()
|
||||
record: sqlite3.Row = cursor.fetchone()
|
||||
|
||||
if not record:
|
||||
return False, "❌ 炼金记录不存在", None
|
||||
@@ -738,14 +724,9 @@ class WPSAlchemyGame(WPSAPI):
|
||||
)
|
||||
|
||||
# 更新定时任务状态
|
||||
scheduled_task_id = record.get("scheduled_task_id")
|
||||
scheduled_task_id: int = record["scheduled_task_id"]
|
||||
if scheduled_task_id:
|
||||
try:
|
||||
get_db().update_task_status(int(scheduled_task_id), STATUS_COMPLETED)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
get_db().conn.commit()
|
||||
get_db().update_task_status(scheduled_task_id, STATUS_COMPLETED)
|
||||
|
||||
return True, "".join(message_lines), result_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user