Files
NewWPSBot/Plugins/WPSCombatSystem/combat_plugin_equipment.py

344 lines
11 KiB
Python
Raw Normal View History

2025-11-10 14:59:07 +08:00
"""装备管理插件 - 装备和卸下物品"""
from __future__ import annotations
2025-11-12 22:58:36 +08:00
from typing import Optional, Sequence
2025-11-10 14:59:07 +08:00
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
2025-11-12 22:58:36 +08:00
from Plugins.WPSAPI import GuideEntry
2025-11-10 14:59:07 +08:00
from .combat_plugin_base import WPSCombatBase
logger: ProjectConfig = ProjectConfig()
2025-11-13 21:10:57 +08:00
class WPSCombatUnequipment(WPSCombatBase):
"""卸下战斗装备插件"""
2025-11-10 14:59:07 +08:00
2025-11-12 22:58:36 +08:00
def get_guide_subtitle(self) -> str:
2025-11-13 21:10:57 +08:00
return "卸下战斗装备"
2025-11-12 22:58:36 +08:00
def collect_command_entries(self) -> Sequence[GuideEntry]:
return (
GuideEntry(
title="卸下",
identifier="卸下 <槽位>",
description="卸下指定槽位weapon/helmet/armor/boots/accessory的装备。",
metadata={"别名": "unequip"},
icon="🧤",
),
)
def collect_guide_entries(self) -> Sequence[GuideEntry]:
return (
{
"title": "槽位说明",
"description": "支持 weapon/helmet/armor/boots/accessory 五个槽位。",
},
{
"title": "属性加成",
"description": "装备属性直接影响战斗与冒险计算,可在 `战斗属性` 指令中查看综合加成。",
},
)
2025-11-10 14:59:07 +08:00
def is_enable_plugin(self) -> bool:
return True
def wake_up(self) -> None:
super().wake_up()
logger.Log(
"Info",
2025-11-13 21:10:57 +08:00
f"{ConsoleFrontColor.GREEN}WPSCombatUnequipment 插件已加载{ConsoleFrontColor.RESET}"
2025-11-10 14:59:07 +08:00
)
self.register_plugin("卸下")
self.register_plugin("unequip")
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
"""
处理装备相关命令
命令格式
- 装备 <物品名>
- 卸下 <槽位>
"""
message = self.parse_message_after_at(message).strip()
if not message:
return await self._send_equipment_overview(chat_id, user_id)
2025-11-10 14:59:07 +08:00
tokens = message.split(maxsplit=1)
if not tokens:
return await self._send_equipment_overview(chat_id, user_id)
2025-11-10 14:59:07 +08:00
# 如果消息为空,说明只输入了命令词
if not tokens or len(tokens) == 0:
return await self.send_markdown_message(
self._help_message(),
chat_id,
user_id
)
# tokens[0] 应该是物品名或槽位
target = tokens[0] if len(tokens) > 0 else ""
if not target:
return await self._send_equipment_overview(chat_id, user_id)
if target.lower() in ["帮助", "help"]:
return await self.send_markdown_message(
self._help_message(),
chat_id,
user_id
)
2025-11-13 21:10:57 +08:00
2025-11-10 14:59:07 +08:00
slot_map = {
"weapon": "weapon", "武器": "weapon",
"helmet": "helmet", "头盔": "helmet",
"armor": "armor", "护甲": "armor",
"boots": "boots", "鞋子": "boots",
"accessory": "accessory", "饰品": "accessory",
}
if target.lower() in slot_map:
# 卸下操作
return await self._handle_unequip(chat_id, user_id, slot_map[target.lower()])
else:
2025-11-13 21:10:57 +08:00
return await self.send_markdown_message(
self._help_message(),
chat_id,
user_id
)
async def _handle_unequip(self, chat_id: int, user_id: int, slot: str) -> Optional[str]:
"""处理卸下命令"""
service = self.service()
success, msg = service.unequip_item(user_id, slot)
return await self.send_markdown_message(msg, chat_id, user_id)
def _help_message(self) -> str:
"""帮助信息"""
return """# ⚔️ 装备管理
**命令格式**
- `装备`查看当前装备
- `装备 <物品名>`装备指定物品
- `卸下 <槽位>`卸下指定槽位的装备
**槽位名称**
- weapon/武器
- helmet/头盔
- armor/护甲
- boots/鞋子
- accessory/饰品
**示例**
- `装备 木剑`
- `卸下 weapon`
"""
async def _send_equipment_overview(self, chat_id: int, user_id: int) -> Optional[str]:
"""展示当前装备概览"""
service = self.service()
equipped = service.get_equipped_items(user_id)
stats = service.calculate_player_stats(user_id)
slot_order = [
("weapon", "武器"),
("helmet", "头盔"),
("armor", "护甲"),
("boots", "鞋子"),
("accessory", "饰品"),
]
lines = [
"# 🛡️ 当前装备情况",
f"- 装备强度:`{stats.equipment_strength:.1f}`",
"",
"**装备栏:**",
]
for slot_key, slot_name in slot_order:
eq_def = equipped.get(slot_key) if equipped else None
if eq_def:
attrs = ", ".join([f"{attr}+{value}" for attr, value in eq_def.attributes.items()]) or "无属性加成"
tier_label = eq_def.tier.to_markdown_label(eq_def.tier.display_name)
lines.append(f"- {slot_name}{tier_label} {eq_def.name}{attrs}")
else:
lines.append(f"- {slot_name}`未装备`")
lines.append("\n> 使用 `装备 <物品名>` 可以直接穿戴,`卸下 <槽位>` 可卸下装备")
return await self.send_markdown_message("\n".join(lines), chat_id, user_id)
class WPSCombatEquipment(WPSCombatBase):
"""装备管理插件"""
def get_guide_subtitle(self) -> str:
return "穿戴战斗装备"
def collect_command_entries(self) -> Sequence[GuideEntry]:
return (
GuideEntry(
title="装备",
identifier="装备 [物品名|ID]",
description="穿戴指定装备,或不带参数时查看当前装备。",
metadata={"别名": "equip"},
icon="🛡️",
details=[
{"type": "list", "items": ["名称与 ID 均可匹配装备库条目。", "若未携带该装备会提示不足。"]},
],
),
)
def collect_guide_entries(self) -> Sequence[GuideEntry]:
return (
{
"title": "槽位说明",
"description": "支持 weapon/helmet/armor/boots/accessory 五个槽位。",
},
{
"title": "属性加成",
"description": "装备属性直接影响战斗与冒险计算,可在 `战斗属性` 指令中查看综合加成。",
},
)
def is_enable_plugin(self) -> bool:
return True
def wake_up(self) -> None:
super().wake_up()
logger.Log(
"Info",
f"{ConsoleFrontColor.GREEN}WPSCombatEquipment 插件已加载{ConsoleFrontColor.RESET}"
)
self.register_plugin("装备")
self.register_plugin("equip")
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
"""
处理装备相关命令
命令格式
- 装备 <物品名>
- 卸下 <槽位>
"""
message = self.parse_message_after_at(message).strip()
if not message:
return await self._send_equipment_overview(chat_id, user_id)
tokens = message.split(maxsplit=1)
if not tokens:
return await self._send_equipment_overview(chat_id, user_id)
# 如果消息为空,说明只输入了命令词
if not tokens or len(tokens) == 0:
return await self.send_markdown_message(
self._help_message(),
chat_id,
user_id
)
# tokens[0] 应该是物品名或槽位
target = tokens[0] if len(tokens) > 0 else ""
if not target:
return await self._send_equipment_overview(chat_id, user_id)
if target.lower() in ["帮助", "help"]:
return await self.send_markdown_message(
self._help_message(),
chat_id,
user_id
)
return await self._handle_equip(chat_id, user_id, target)
2025-11-10 14:59:07 +08:00
async def _handle_equip(self, chat_id: int, user_id: int, item_name: str) -> Optional[str]:
"""处理装备命令"""
if not item_name:
return await self.send_markdown_message(
"❌ 请指定要装备的物品名称\n用法:`装备 <物品名>`",
chat_id,
user_id
)
service = self.service()
# 尝试通过名称查找装备item_id
from .combat_models import EQUIPMENT_REGISTRY
item_id = None
for eq_id, eq_def in EQUIPMENT_REGISTRY.items():
if eq_def.name.lower() == item_name.lower() or eq_id.lower() == item_name.lower():
item_id = eq_id
break
if not item_id:
return await self.send_markdown_message(
f"❌ 未找到装备:{item_name}",
chat_id,
user_id
)
success, msg = service.equip_item(user_id, item_id)
return await self.send_markdown_message(msg, chat_id, user_id)
def _help_message(self) -> str:
"""帮助信息"""
return """# ⚔️ 装备管理
**命令格式**
- `装备`查看当前装备
2025-11-10 14:59:07 +08:00
- `装备 <物品名>`装备指定物品
- `卸下 <槽位>`卸下指定槽位的装备
**槽位名称**
- weapon/武器
- helmet/头盔
- armor/护甲
- boots/鞋子
- accessory/饰品
**示例**
- `装备 木剑`
- `卸下 weapon`
"""
async def _send_equipment_overview(self, chat_id: int, user_id: int) -> Optional[str]:
"""展示当前装备概览"""
service = self.service()
equipped = service.get_equipped_items(user_id)
stats = service.calculate_player_stats(user_id)
slot_order = [
("weapon", "武器"),
("helmet", "头盔"),
("armor", "护甲"),
("boots", "鞋子"),
("accessory", "饰品"),
]
lines = [
"# 🛡️ 当前装备情况",
f"- 装备强度:`{stats.equipment_strength:.1f}`",
"",
"**装备栏:**",
]
for slot_key, slot_name in slot_order:
eq_def = equipped.get(slot_key) if equipped else None
if eq_def:
attrs = ", ".join([f"{attr}+{value}" for attr, value in eq_def.attributes.items()]) or "无属性加成"
tier_label = eq_def.tier.to_markdown_label(eq_def.tier.display_name)
lines.append(f"- {slot_name}{tier_label} {eq_def.name}{attrs}")
else:
lines.append(f"- {slot_name}`未装备`")
lines.append("\n> 使用 `装备 <物品名>` 可以直接穿戴,`卸下 <槽位>` 可卸下装备")
return await self.send_markdown_message("\n".join(lines), chat_id, user_id)
2025-11-13 21:10:57 +08:00
__all__ = ["WPSCombatEquipment", "WPSCombatUnequipment"]