1.修复被错误删除的炼金配方查看插件类2.新增更多装备与配方3.新增闪烁粉尘用于合成共鸣粉末
This commit is contained in:
@@ -1321,5 +1321,201 @@ class WPSAlchemyGame(WPSAPI):
|
||||
)
|
||||
|
||||
|
||||
class WPSAlchemyRecipeLookup(WPSAPI):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._alchemy: Optional[WPSAlchemyGame] = None
|
||||
self._backpack: Optional[WPSBackpackSystem] = None
|
||||
|
||||
def get_guide_subtitle(self) -> str:
|
||||
return "查询指定物品涉及的炼金配方"
|
||||
|
||||
def collect_command_entries(self) -> Sequence[GuideEntry]:
|
||||
return (
|
||||
{
|
||||
"title": "炼金配方",
|
||||
"identifier": "炼金配方",
|
||||
"description": "展示物品作为材料、成功产物或失败产物的所有配方。",
|
||||
"metadata": {"别名": "alchemy_recipe"},
|
||||
},
|
||||
)
|
||||
|
||||
def collect_guide_entries(self) -> Sequence[GuideEntry]:
|
||||
return (
|
||||
{
|
||||
"title": "查询格式",
|
||||
"description": "`炼金配方 <物品ID>` 或 `炼金配方 <物品名称>`,忽略大小写。",
|
||||
},
|
||||
{
|
||||
"title": "输出结构",
|
||||
"description": "结果按材料/成功/失败三类分组,列出配方材料与成功率。",
|
||||
},
|
||||
)
|
||||
|
||||
def dependencies(self) -> List[type]:
|
||||
return [WPSAlchemyGame, WPSBackpackSystem]
|
||||
|
||||
def is_enable_plugin(self) -> bool:
|
||||
return True
|
||||
|
||||
def wake_up(self) -> None:
|
||||
self._alchemy = Architecture.Get(WPSAlchemyGame)
|
||||
self._backpack = Architecture.Get(WPSBackpackSystem)
|
||||
self.register_plugin("炼金配方")
|
||||
self.register_plugin("alchemy_recipe")
|
||||
logger.Log(
|
||||
"Info",
|
||||
f"{ConsoleFrontColor.GREEN}WPSAlchemyRecipeLookup 插件已加载{ConsoleFrontColor.RESET}",
|
||||
)
|
||||
|
||||
async def callback(
|
||||
self, message: str, chat_id: int, user_id: int
|
||||
) -> Optional[str]:
|
||||
payload = self.parse_message_after_at(message).strip()
|
||||
if not payload:
|
||||
return await self.send_markdown_message(self._help_text(), chat_id, user_id)
|
||||
|
||||
backpack = self._backpack or Architecture.Get(WPSBackpackSystem)
|
||||
definition = self._resolve_definition(payload, backpack)
|
||||
if definition is None:
|
||||
return await self.send_markdown_message(
|
||||
f"❌ 未找到物品 `{payload}`,请确认输入的物品 ID 或名称。",
|
||||
chat_id,
|
||||
user_id,
|
||||
)
|
||||
|
||||
alchemy = self._alchemy or Architecture.Get(WPSAlchemyGame)
|
||||
material_recipes = alchemy.get_recipes_using_item(definition.item_id)
|
||||
produce_map = alchemy.get_recipes_producing_item(definition.item_id)
|
||||
success_recipes = produce_map["success"]
|
||||
fail_recipes = produce_map["fail"]
|
||||
|
||||
message_text = self._format_markdown(
|
||||
definition,
|
||||
material_recipes,
|
||||
success_recipes,
|
||||
fail_recipes,
|
||||
backpack,
|
||||
)
|
||||
return await self.send_markdown_message(message_text, chat_id, user_id)
|
||||
|
||||
def _resolve_definition(
|
||||
self, identifier: str, backpack: WPSBackpackSystem
|
||||
) -> Optional[BackpackItemDefinition]:
|
||||
lowered = identifier.strip().lower()
|
||||
cursor = get_db().conn.cursor()
|
||||
cursor.execute(
|
||||
f"""
|
||||
SELECT item_id
|
||||
FROM {WPSBackpackSystem.ITEMS_TABLE}
|
||||
WHERE lower(item_id) = ? OR lower(name) = ?
|
||||
LIMIT 1
|
||||
""",
|
||||
(lowered, lowered),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
item_id = row["item_id"] if row else identifier.strip()
|
||||
try:
|
||||
return backpack._get_definition(item_id) # noqa: SLF001
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def _format_markdown(
|
||||
self,
|
||||
target: BackpackItemDefinition,
|
||||
material_recipes: List[AlchemyRecipe],
|
||||
success_recipes: List[AlchemyRecipe],
|
||||
fail_recipes: List[AlchemyRecipe],
|
||||
backpack: WPSBackpackSystem,
|
||||
) -> str:
|
||||
lines = [
|
||||
f"# 🔍 炼金配方查询|{target.name}",
|
||||
f"- 物品 ID:`{target.item_id}`",
|
||||
"---",
|
||||
]
|
||||
lines.append("## 作为配方材料")
|
||||
lines.extend(
|
||||
self._format_recipe_entries(material_recipes, backpack)
|
||||
or ["- 暂无记录"]
|
||||
)
|
||||
|
||||
lines.append("\n## 作为成功产物")
|
||||
lines.extend(
|
||||
self._format_recipe_entries(success_recipes, backpack, role="success")
|
||||
or ["- 暂无记录"]
|
||||
)
|
||||
|
||||
lines.append("\n## 作为失败产物")
|
||||
lines.extend(
|
||||
self._format_recipe_entries(fail_recipes, backpack, role="fail")
|
||||
or ["- 暂无记录"]
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
def _format_recipe_entries(
|
||||
self,
|
||||
recipes: List[AlchemyRecipe],
|
||||
backpack: WPSBackpackSystem,
|
||||
*,
|
||||
role: str = "material",
|
||||
) -> List[str]:
|
||||
if not recipes:
|
||||
return []
|
||||
entries: List[str] = []
|
||||
for recipe in recipes:
|
||||
materials = self._summarize_materials(recipe, backpack)
|
||||
success_name = self._resolve_item_name(recipe.success_item_id, backpack)
|
||||
fail_name = self._resolve_item_name(recipe.fail_item_id, backpack)
|
||||
rate = f"{recipe.base_success_rate:.0%}"
|
||||
if role == "material":
|
||||
entry = (
|
||||
f"- 材料:{materials}|成功产物:`{success_name}`|"
|
||||
f"失败产物:`{fail_name}`|成功率:{rate}"
|
||||
)
|
||||
elif role == "success":
|
||||
entry = (
|
||||
f"- 材料:{materials}|成功率:{rate}|"
|
||||
f"失败产物:`{fail_name}`"
|
||||
)
|
||||
else:
|
||||
entry = (
|
||||
f"- 材料:{materials}|成功率:{rate}|"
|
||||
f"成功产物:`{success_name}`"
|
||||
)
|
||||
entries.append(entry)
|
||||
return entries
|
||||
|
||||
def _summarize_materials(
|
||||
self, recipe: AlchemyRecipe, backpack: WPSBackpackSystem
|
||||
) -> str:
|
||||
counter = Counter(recipe.materials)
|
||||
parts: List[str] = []
|
||||
for item_id, count in sorted(counter.items()):
|
||||
name = self._resolve_item_name(item_id, backpack)
|
||||
if count == 1:
|
||||
parts.append(f"`{name}`")
|
||||
else:
|
||||
parts.append(f"`{name}` × {count}")
|
||||
return " + ".join(parts)
|
||||
|
||||
def _resolve_item_name(
|
||||
self, item_id: str, backpack: WPSBackpackSystem
|
||||
) -> str:
|
||||
try:
|
||||
definition = backpack._get_definition(item_id) # noqa: SLF001
|
||||
return definition.name
|
||||
except Exception:
|
||||
return item_id
|
||||
|
||||
def _help_text(self) -> str:
|
||||
return (
|
||||
"# ⚗️ 炼金配方查询帮助\n"
|
||||
"- `炼金配方 <物品ID>`\n"
|
||||
"- `炼金配方 <物品名称>`\n"
|
||||
"> 输入需要精确匹配注册物品,名称不区分大小写。\n"
|
||||
"> 积分炼金费用将进入奖池,根据挡位概率抽取奖池奖励;部分挡位会额外掉落普通物品。"
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["WPSAlchemyGame", "WPSAlchemyRecipeLookup"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user