From a59ac4ded63a0a69a9a2cbc7d2fc7d642be36175 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Sun, 26 Oct 2025 13:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E6=B7=BB=E5=8A=A0=E6=94=B6?= =?UTF-8?q?=E8=8E=B7=E6=AC=A1=E6=95=B0=E5=88=A4=E6=96=AD=E4=BD=9C=E7=89=A9?= =?UTF-8?q?=E5=8D=87=E6=98=9F=EF=BC=8C=E4=B8=80=E4=BA=8C=E4=B8=89=E5=9B=9B?= =?UTF-8?q?=E4=BA=94=E6=98=9F=E4=BD=9C=E7=89=A9=E5=86=99=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 48 -------------------- core/database/userPlantCount.py | 18 ++++++++ core/database/userSoil.py | 16 ++++++- core/farm.py | 75 -------------------------------- resource/db/plant.db | Bin 36864 -> 36864 bytes 5 files changed, 33 insertions(+), 124 deletions(-) diff --git a/command.py b/command.py index 05a40e0..bc1ef6b 100644 --- a/command.py +++ b/command.py @@ -98,7 +98,6 @@ diuse_farm = on_alconna( Subcommand("my-vipPoint", help_text="我的点券"), Subcommand("farm-help", help_text="农场帮助"), Subcommand("vipSeed-shop", Args["res?", MultiVar(str)], help_text="种子商店"), - Subcommand("my-plantcount", help_text="我的作物收获次数"), ), priority=5, block=True, @@ -777,50 +776,3 @@ async def _(session: Uninfo, res: Match[tuple[str, ...]]): image = await g_pShopManager.getSeedShopImage(filterKey, page, 1) await MessageUtils.build_message(image).send() - - -diuse_farm.shortcut( - "我的收获次数", - command="我的农场", - arguments=["my-plantcount"], - prefix=True, -) - - -@diuse_farm.assign("my-plantcount") -async def _(session: Uninfo, res: Match[tuple[str, ...]]): - uid = str(session.user.id) - player = await g_pToolManager.getPlayerByUid(uid) - if player is None or not await player.isRegistered(): - await g_pToolManager.repeat() - return - - if res.result is inspect._empty: - raw = [] - else: - raw = res.result - - filterKey: str | int | None = None - page: int = 1 - - if len(raw) >= 1 and raw[0] is not None: - first = raw[0] - if isinstance(first, str) and first.isdigit(): - page = int(first) - else: - filterKey = first - - if ( - len(raw) >= 2 - and raw[1] is not None - and isinstance(raw[1], str) - and raw[1].isdigit() - ): - page = int(raw[1]) - - if filterKey is None: - image = await g_pFarmManager.getUserPlantCountImage(uid, page, 0) - else: - image = await g_pFarmManager.getUserPlantCountImage(uid, filterKey, page) - - await MessageUtils.build_message(image).send() diff --git a/core/database/userPlantCount.py b/core/database/userPlantCount.py index 5e7d41e..726d699 100644 --- a/core/database/userPlantCount.py +++ b/core/database/userPlantCount.py @@ -75,6 +75,24 @@ class CUserPlantCountDB(CSqlManager): rows = await cursor.fetchall() return {row["plant"]: row["count"] for row in rows} + @classmethod + async def getUserPlantCountByPlantName(cls, uid: str, plant: str) -> int: + """根据用户Uid和植物名称获取该对应的收获次数 + + Args: + uid (str): 用户uid + plant (str): 植物名称 + + Returns: + int: 收获次数 + """ + cursor = await cls.m_pDB.execute( + "SELECT count FROM userPlantCount WHERE uid = ? AND plant = ?", + (uid, plant), + ) + row = await cursor.fetchone() + return row["count"] if row else 0 + @classmethod async def updateUserPlantCountByName(cls, uid: str, plant: str, count: int) -> bool: """根据植物名称更新植物的收获次数 diff --git a/core/database/userSoil.py b/core/database/userSoil.py index 2a6d401..32ab53d 100644 --- a/core/database/userSoil.py +++ b/core/database/userSoil.py @@ -384,7 +384,7 @@ class CUserSoilDB(CSqlManager): if soilInfo and soilInfo.get("plantName"): return False - # 获取植物配置 + # 获取植物配置""" """ plantCfg = await g_pDBService.plant.getPlantByName(plantName) if not plantCfg: logger.error(f"未知植物: {plantName}") @@ -404,6 +404,20 @@ class CUserSoilDB(CSqlManager): async with cls._transaction(): prev = soilInfo or {} await cls._deleteUserSoil(uid, soilIndex) + # 根据此植物收获次数对其星级进行升级 + if g_pDBService.plant.existsPlant("一星" + plantName): + harvestCounts = ( + await g_pDBService.userPlantCount.getUserPlantCountByPlantName( + uid, plantName + ) + ) + if harvestCounts >= 350: + plantName = "一星" + plantName + if harvestCounts >= 700: + plantName = "二星" + plantName + if harvestCounts >= 1200: + plantName = "三星" + plantName + await cls._insertUserSoil( { "uid": uid, diff --git a/core/farm.py b/core/farm.py index 98efe8f..1770fa9 100644 --- a/core/farm.py +++ b/core/farm.py @@ -1230,80 +1230,5 @@ class CFarmManager: return f"兑换{num}点券成功,当前点券:{number},赠送点券:{giftPoints},当前农场币:{point}" - @classmethod - async def getUserPlantCountImage( - cls, uid: str, filterKey: str | int = 1, num: int = 1 - ) -> bytes: - """获取用户作物收获次数图片 - - Args: - filterKey (str|int): - - 字符串: 根据关键字筛选种子名称 - - 整数: 翻至对应页(无筛选) - num (int, optional): 当 filterKey 为字符串时,用于指定页码。Defaults to 1. - - Returns: - bytes: 返回商店图片bytes - """ - # 解析参数:区分筛选关键字和页码 - filterStr = None - if isinstance(filterKey, int): - page = filterKey - else: - filterStr = filterKey - page = num - - # 表头定义 - columnName = [ - "-", - "种子名称", - "收获次数", - ] - - # 查询用户作物收获次数(返回 dict: {plant: count})并根据筛选关键字过滤 - plants = await g_pDBService.userPlantCount.getUserPlantCountByUid(uid) or {} - filteredPlants = [] - - for name, cnt in plants.items(): - # 字符串筛选 - if filterStr and filterStr not in name: - continue - filteredPlants.append({"plant": name, "count": cnt}) - - # 计算分页 - totalCount = len(filteredPlants) - pageCount = math.ceil(totalCount / 15) if totalCount else 1 - startIndex = (page - 1) * 15 - pageItems = filteredPlants[startIndex : startIndex + 15] - - # 构建数据行 - dataList = [] - for plant in pageItems: - # 图标处理 - icon = "" - iconPath = g_sResourcePath / f"plant/{plant['plant']}/icon.png" - if iconPath.exists(): - icon = (iconPath, 33, 33) - - dataList.append( - [ - icon, - plant["plant"], # 种子名称 - plant["count"], # 收获次数 - ] - ) - - # 页码标题 - title = f"收获次数 页数: {page}/{pageCount}" - - # 渲染表格并返回图片bytes - result = await ImageTemplate.table_page( - title, - "", - columnName, - dataList, - ) - return result.pic2bytes() - g_pFarmManager = CFarmManager() diff --git a/resource/db/plant.db b/resource/db/plant.db index f9f0150f8a3f0bcef1182dc3b93d4bc802175bab..da5cce45065cccef877b00670c8ef829b1cacd9a 100644 GIT binary patch delta 7275 zcmai&du$ZP9mn@E`?}lPH4kGR#`gIEHn#Ek{5Z$hU>*T%2LdgsBGM{Rby7o>(gqqz zpvjsx$}K1~HU`SWDo!8{391U1);z>Rkt#L)qfMhEttyeImCtunEvN~kX=qDlXLfIP z?k;mkAoKHnf4|>+XFjttJ1{B?j0%JELX#ZFY3^Tss5Zt=o_q3?X^7?>7~~}LzIo5Q zGd{iOrYXb!t9E$&Ub$8zfR*PXplEHS^Z{p{H=i=+8SfhjqdW9zXe{(tNYO9pTlLD| z`@xrj9f7|EMgw0B=-PGdS*>3ENF7v{DgRW)l+B7RUz5Kl!zAbS?3Eh&?3Kk_Juj%L z$~%90HC2N@tCN=xP8~Thb#-Lw?1fv0MrKMIW<-Y9Ee~7$_KISzndgx};Q5Cs!Q`c} z)WH)|``<{ucDghkiVFL5v86o{X=sjgz<;C7&d)8;R`_pgOEePcx0f@rrT0&y_nk{0 zoJb!|)W*#Y;W6DRkgkW3E;(^JIes=h^lEzW#ZD*PjzY~X%gMHdn3FnsE&0l?aCgm4 zx~JLcdhMl-)fwm3P|l@}UQPXE@2!#Hp19c}?3f`A|9ZW+(w(f*hZD(HehydGwiT7`vmbJ_s>Y)w zsnI^&8aoPwxb5v7W}iH~p}DMKjosmR^d*|~(DCHNwbX?(J3EWkdx984kh*d`b>%?% z!1Z|4T!92leReyetI3OdaAR;pn-`m1NK?1UZY$<$zO1X%8)H+a4s2;PS9uj$85NSp zFQiX8Lx&Zfh?q;gVYD!Y0U=IaeG?Yh+HS5z0*G%k@5CgJABVit`07yzTmjyi8QExj zjhGNAh;M|EE(_n7u&hvXO*z>RzId!z_!dmpYcHlS^p>TUjo=#_(p|38sGZ7_+o7izDA?aMwed1Dox`X71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