1.修复一些bug2.冒险现在可以放弃

This commit is contained in:
2025-11-10 21:03:18 +08:00
parent 40f754e57b
commit 092ef58f23
8 changed files with 301 additions and 33 deletions

View File

@@ -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()