From 6d3eb5d48f4e11b6ac9026a2d5a54eae90e4e835 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Mon, 12 May 2025 17:28:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20=E6=96=B0=E5=A2=9E=E5=86=9C?= =?UTF-8?q?=E5=9C=BA=E8=AF=A6=E8=BF=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 2 +- command.py | 24 +++++++++++- database/userSoil.py | 29 ++++++++++++++- farm/farm.py | 87 ++++++++++++++++++++++++++++++++++++++++++++ farm/shop.py | 16 ++++---- 5 files changed, 147 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index 8844eda..23e24d3 100644 --- a/__init__.py +++ b/__init__.py @@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata( """.strip(), extra=PluginExtraData( author="Art_Sakura", - version="1.2", + version="1.3", commands=[Command(command="我的农场")], menu_type="群内小游戏", configs=[ diff --git a/command.py b/command.py index 179cf1b..cc8f3be 100644 --- a/command.py +++ b/command.py @@ -6,6 +6,7 @@ from nonebot_plugin_alconna import (Alconna, AlconnaMatch, AlconnaQuery, Args, from nonebot_plugin_uninfo import Uninfo from nonebot_plugin_waiter import waiter +from zhenxun.configs.config import BotConfig from zhenxun.services.log import logger from zhenxun.utils.message import MessageUtils @@ -41,7 +42,6 @@ async def handle_register(session: Uninfo): return try: - # 获取原始用户名并安全处理 raw_name = str(session.user.name) safe_name = sanitize_username(raw_name) @@ -120,6 +120,7 @@ diuse_farm = on_alconna( Alconna( "我的农场", Option("--all", action=store_true), + Subcommand("detail", help_text="农场详述"), Subcommand("my-point", help_text="我的农场币"), Subcommand("seed-shop", Args["num?", int], help_text="种子商店"), Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"), @@ -148,6 +149,27 @@ async def _(session: Uninfo): image = await g_pFarmManager.drawFarmByUid(uid) await MessageUtils.build_message(image).send(reply_to=True) +diuse_farm.shortcut( + "农场详述", + command="我的农场", + arguments=["detail"], + prefix=True, +) + +@diuse_farm.assign("detail") +async def _(session: Uninfo): + uid = str(session.user.id) + + if await isRegisteredByUid(uid) == False: + return + + info = await g_pFarmManager.drawDetailFarmByUid(uid) + + a = await MessageUtils.alc_forward_msg(info, session.self_id, BotConfig.self_nickname).send(reply_to=True) + + logger.info(f"{a}") + + diuse_farm.shortcut( "我的农场币", command="我的农场", diff --git a/database/userSoil.py b/database/userSoil.py index efdd587..e8ca089 100644 --- a/database/userSoil.py +++ b/database/userSoil.py @@ -18,7 +18,7 @@ class CUserSoilDB(CSqlManager): #matureTime: 成熟时间 #soilLevel: 土地等级 0=普通地,1=红土地,2=黑土地,3=金土地 #wiltStatus: 枯萎状态 0=未枯萎,1=枯萎 - #fertilizerStatus: 施肥状态 0=未施肥,1=施肥 + #fertilizerStatus: 施肥状态 0=未施肥,1=施肥 2=增肥 #bugStatus: 虫害状态 0=无虫害,1=有虫害 #weedStatus: 杂草状态 0=无杂草,1=有杂草 #waterStatus: 缺水状态 0=不缺水,1=缺水 @@ -349,3 +349,30 @@ class CUserSoilDB(CSqlManager): except Exception as e: logger.error(f"播种失败!", e=e) return False + + @classmethod + async def getUserSoilStatus(cls, uid: str, soilIndex: int) -> str: + status = [] + soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex) + + if not soilInfo: + return "" + + if soilInfo.get("wiltStatus", 0) == 1: + return "枯萎" + + if soilInfo.get("fertilizerStatus", 0) == 1: + status.append("施肥") + elif soilInfo.get("fertilizerStatus", 0) == 2: + status.append("增肥") + + if soilInfo.get("bugStatus", 0) == 1: + status.append("虫害") + + if soilInfo.get("weedStatus", 0) == 1: + status.append("杂草") + + if soilInfo.get("waterStatus", 0) == 1: + status.append("缺水") + + return ",".join(status) diff --git a/farm/farm.py b/farm/farm.py index 6a00022..04b952b 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -170,6 +170,93 @@ class CFarmManager: return img.pic2bytes() + @classmethod + async def drawDetailFarmByUid(cls, uid: str) -> list: + info = [] + + farm = await cls.drawFarmByUid(uid) + + info.append(BuildImage.open(farm)) + + dataList = [] + columnName = [ + "-", + "土地ID", + "作物名称", + "成熟时间", + "土地状态", + "剩余产出", + ] + + icon = "" + soilNumber = await g_pDBService.user.getUserSoilByUid(uid) + + for i in range(1, soilNumber + 1): + soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i) + + if not soilInfo: + continue + + if soilInfo["soilLevel"] == 1: + iconPath = g_sResourcePath / f"soil/TODO.png" + else: + iconPath = g_sResourcePath / f"soil/普通土地.png" + + if iconPath.exists(): + icon = (iconPath, 33, 33) + + plantName = soilInfo.get("plantName", "-") + + if plantName == "-": + matureTime = "-" + soilStatus = "-" + plantNumber = "-" + else: + matureTime = datetime.fromtimestamp(int(soilInfo.get("matureTime", 0))).strftime("%Y-%m-%d %H:%M:%S.%f") + soilStatus = await g_pDBService.userSoil.getUserSoilStatus(uid, i) + + num = await g_pDBService.userSteal.getTotalStolenCount(uid, i) + planInfo = await g_pDBService.plant.getPlantByName(plantName) + + if not planInfo: + plantNumber = f"None / {num}" + else: + plantNumber = f"{planInfo['harvest']} / {num}" + + dataList.append( + [ + icon, + i, + plantName, + matureTime, + soilStatus, + plantNumber, + ]) + + if len(dataList) >= 15: + result = await ImageTemplate.table_page( + "土地详细信息", + "测试N\n测试2", + columnName, + dataList, + ) + + info.append(result) + dataList.clear() + + if i >= 30: + result = await ImageTemplate.table_page( + "土地详细信息", + "测试N\n测试2", + columnName, + dataList, + ) + + info.append(result) + dataList.clear() + + return info + @classmethod async def drawSoilPlant(cls, uid: str, soilIndex: int) -> tuple[bool, BuildImage, bool]: """绘制植物资源 diff --git a/farm/shop.py b/farm/shop.py index ae240f6..d5f024a 100644 --- a/farm/shop.py +++ b/farm/shop.py @@ -21,8 +21,8 @@ class CShopManager: bytes: 返回商店图片bytes """ - data_list = [] - column_name = [ + dataList = [] + columnName = [ "-", "种子名称", "种子单价", @@ -48,16 +48,16 @@ class CShopManager: continue icon = "" - icon_path = g_sResourcePath / f"plant/{plant['name']}/icon.png" - if icon_path.exists(): - icon = (icon_path, 33, 33) + iconPath = g_sResourcePath / f"plant/{plant['name']}/icon.png" + if iconPath.exists(): + icon = (iconPath, 33, 33) if plant['again'] == True: sell = "可以" else: sell = "不可以" - data_list.append( + dataList.append( [ icon, plant['name'], @@ -79,8 +79,8 @@ class CShopManager: result = await ImageTemplate.table_page( title, "购买示例:@小真寻 购买种子 大白菜 5", - column_name, - data_list, + columnName, + dataList, ) return result.pic2bytes()