From 15c482f41faf32cc655fcd79be34464bbddc184c Mon Sep 17 00:00:00 2001 From: Mualamx Date: Thu, 23 Oct 2025 02:05:04 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=8E=A8=20=E6=B7=BB=E5=8A=A0=E4=BD=9C?= =?UTF-8?q?=E7=89=A9=E6=94=B6=E8=8E=B7=E6=AC=A1=E6=95=B0=E8=A1=A8=E5=8F=8A?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=9F=A5=E6=94=B9=EF=BC=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8F=AF=E6=9F=A5=E8=AF=A2=E4=BD=9C=E7=89=A9=E6=94=B6=E8=8E=B7?= =?UTF-8?q?=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 48 +++++++++++++ core/database/userPlantCount.py | 124 ++++++++++++++++++++++++++++++++ core/dbService.py | 4 ++ core/farm.py | 84 ++++++++++++++++++++++ utils/config.py | 1 + 5 files changed, 261 insertions(+) create mode 100644 core/database/userPlantCount.py diff --git a/command.py b/command.py index bc1ef6b..05a40e0 100644 --- a/command.py +++ b/command.py @@ -98,6 +98,7 @@ 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, @@ -776,3 +777,50 @@ 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 new file mode 100644 index 0000000..5e7d41e --- /dev/null +++ b/core/database/userPlantCount.py @@ -0,0 +1,124 @@ +from zhenxun.services.log import logger + +from .database import CSqlManager + + +class CUserPlantCountDB(CSqlManager): + @classmethod + async def initDB(cls): + userPlantCount = { + "uid": "TEXT NOT NULL", # 用户Uid + "plant": "TEXT NOT NULL", # 植物名称 + "count": "INTEGER NOT NULL DEFAULT 0", # 数量 + "PRIMARY KEY": "(uid, plant)", + } + + await cls.ensureTableSchema("userPlantCount", userPlantCount) + + @classmethod + async def addUserPlantCountByUid(cls, uid: str, plant: str, count: int = 1) -> bool: + """根据用户uid添加植物的收获次数 + + Args: + uid (str): 用户uid + plant (str): 植物名称 + count (int): 数量 + + Returns: + bool: 是否添加成功 + """ + try: + async with cls._transaction(): + async with cls.m_pDB.execute( + "SELECT count FROM userPlantCount WHERE uid = ? AND plant = ?", + (uid, plant), + ) as cursor: + row = await cursor.fetchone() + + if row: + newCount = row[0] + count + await cls.m_pDB.execute( + "UPDATE userPlantCount SET count = ? WHERE uid = ? AND plant = ?", + (newCount, uid, plant), + ) + else: + newCount = count + await cls.m_pDB.execute( + "INSERT INTO userPlantCount (uid, plant, count) VALUES (?, ?, ?)", + (uid, plant, count), + ) + + if newCount <= 0: + await cls.m_pDB.execute( + "DELETE FROM userPlantCount WHERE uid = ? AND plant = ?", + (uid, plant), + ) + return True + except Exception as e: + logger.warning("addUserPlantByUid 失败!", e=e) + return False + + @classmethod + async def getUserPlantCountByUid(cls, uid: str) -> dict: + """根据用户Uid获取该用户的所有植物的收获次数 + + Args: + uid (str): 用户uid + + Returns: + dict: 植物信息 + """ + + cursor = await cls.m_pDB.execute( + "SELECT plant, count FROM userPlantCount WHERE uid=?", (uid,) + ) + rows = await cursor.fetchall() + return {row["plant"]: row["count"] for row in rows} + + @classmethod + async def updateUserPlantCountByName(cls, uid: str, plant: str, count: int) -> bool: + """根据植物名称更新植物的收获次数 + + Args: + uid (str): 用户uid + plant (str): 植物名称 + count (int): 收获次数 + + Returns: + bool: 是否成功 + """ + try: + if count <= 0: + return await cls.deleteUserPlantCountByName(uid, plant) + + async with cls._transaction(): + await cls.m_pDB.execute( + "UPDATE userPlantCount SET count = ? WHERE uid = ? AND plant = ?", + (count, uid, plant), + ) + return True + except Exception as e: + logger.warning("updateUserPlantByName失败!", e=e) + return False + + @classmethod + async def deleteUserPlantCountByName(cls, uid: str, plant: str) -> bool: + """根据植物名称从植物仓库中删除植物 + + Args: + uid (str): 用户uid + seed (str): 种子名称 + + Returns: + bool: 是否成功 + """ + try: + async with cls._transaction(): + await cls.m_pDB.execute( + "DELETE FROM userPlantCount WHERE uid = ? AND plant = ?", + (uid, plant), + ) + return True + except Exception as e: + logger.warning("deleteUserPlantCountByName 删除失败!", e=e) + return False diff --git a/core/dbService.py b/core/dbService.py index cba82d9..a0928f4 100644 --- a/core/dbService.py +++ b/core/dbService.py @@ -4,6 +4,7 @@ class CDBService: from .database.user import CUserDB from .database.userItem import CUserItemDB from .database.userPlant import CUserPlantDB + from .database.userPlantCount import CUserPlantCountDB from .database.userSeed import CUserSeedDB from .database.userSign import CUserSignDB from .database.userSoil import CUserSoilDB @@ -33,6 +34,9 @@ class CDBService: self.userSign = CUserSignDB() await self.userSign.initDB() + self.userPlantCount = CUserPlantCountDB() + await self.userPlantCount.initDB() + async def cleanup(self): await self.plant.cleanup() diff --git a/core/farm.py b/core/farm.py index 0d66ebc..98efe8f 100644 --- a/core/farm.py +++ b/core/farm.py @@ -629,6 +629,15 @@ class CFarmManager: uid, soilInfo["plantName"], number ) + # 统计收获次数 + try: + await g_pDBService.userPlantCount.addUserPlantCountByUid( + uid, soilInfo["plantName"] + ) + except Exception: + # 忽略统计异常,避免影响主流程 + pass + # 如果到达收获次数上限 if soilInfo["harvestCount"] + 1 >= plantInfo["crop"]: await g_pDBService.userSoil.updateUserSoil( @@ -1221,5 +1230,80 @@ 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/utils/config.py b/utils/config.py index 8afdca7..9804e96 100644 --- a/utils/config.py +++ b/utils/config.py @@ -41,6 +41,7 @@ g_sTranslation = { "success": "✅ 农场开通成功!\n💼 初始资金:{point}农场币 🥳🎉", "repeat": "🎉 您已经开通农场啦~ 😄", "error": "⚠️ 开通失败,请稍后再试 💔", + "already": "🚜 你已经开通农场啦~ 快去种田吧 🌱", }, "buySeed": { "notSeed": "🌱 请在指令后跟需要购买的种子名称", From a59ac4ded63a0a69a9a2cbc7d2fc7d642be36175 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Sun, 26 Oct 2025 13:46:07 +0800 Subject: [PATCH 2/5] =?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`X71q-D);Zc76me+^->A7# za`COryNt1h;M-cX+7m2f2nfE7<`N`;_%2{{Md4d#wj&M1w5-3SH$pngl)puVYmqWoD6sYA+ua#lH_TFS50uP9Hc-D*u>9S90{!8-A<_=0#2 zw29Ti$Kocj3si|)#Lq-s{EPTbuqoIb{CaS`zAgA|<7VJy@R#~+>A5oSP3ejRz~7~E z=_EJ+-Ue?;L*S269PE-Fm14t-HvDdUWaCQSnkm)`&_4eW2COU*o86#)p93pM+`nUi zKSB!wRY&^}G9al65b9kh`r{R0hpbQU_ zIAwSRiBpD`J5}*kLl$_MFX;Jgf%zl_Wq2uC;dr;oGJKv-;x~LQiBpEpA%)2TpN)bR zDnJY`At@-sXQ362AI63klP4*|XOd#X@EJrt^|O)mPfvmANPgLRIcqlt)9^2xI5h=D zBu-6%N#fKL7^siSP98D^Azu(pfd%gaKqo1vDG1_C2DO+q1p%MLKLr|zQ&XUl!ek1R znWE+FzNkm#eZ!+j%JOzL}Nlk%BijgT0(8Cu8Xuqw~fG5A84ChGPZ@Bn? z#Qlbg|3g(#fsEnee|Z zwnwO&#(YZX-89@C+gqrsk&Zs@moobIujNgSwv)bT%*%Vza8IQ4dVj=`XWcaBvP%1y z*yw0G=$pnIN1Jogz@`1%Y;QD{0QaUbJMW1bYcfpjTx>4&1SJeX<`omKHQJB>-ZW-0 zy7HsAxyD$CH1MWTocE^T&K&+wu*hilD$Hb5@FV=h0wd}TV+Law8N9dF8=Xi{zs8>K zw1htl!tZ?Ebr-jUUw2=t{;08v8yh|wEr)WlZm&Sutd;^<-e!GZ~jmAAx z#t#Szs)hS(fI1K_*I4QO<0U{ zG`@N%+zpuT*Z#x{IoUA2?kUfYZ{c*kiRUQ{Gx*YH#-6xdLF1eFA*IXUi**EF*uqN` zLy6rv{o~_-bEc#5h1w$&zKLD=@x{}ejjuC$y7Y6b(iFZ>>!R;|)=%tow7K}A(iFax zp#}ltoA^QgWsEcg-zu}o6YO9J2)<={EfO^KC7xw;Md4ejS0hc`s>Jv6 delta 639 zcmZozz|^pSX@WHGBnAcsPAF!YsA0}HX=B0?ejXM6`CPy`F#{bV15+adAZ2O^q+I-j8RQw6CeISE zXLs-wW{?E39|>6VI{SddIT%4;^PE6uMrKY9j>(UVthpH(nHU+}IXOUl4P)!cuC4r& zi;PWy;y~aH5#MBNgTns_#Y zQ03z-VDcQ`a9RZCL+pQwre50;Rezx+Og}{Z7Bu-^mPVU(qHc)tu<(6h;6K1$%Wuy2 dWwW5d6Fz2#_QJ`9hN6>s>VE@cj-%lRKL8W@cRc_A From 36e7c8d580f3dc76bcc3c215c1a724aad572374f Mon Sep 17 00:00:00 2001 From: Mualamx Date: Mon, 27 Oct 2025 11:41:23 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=AB=98?= =?UTF-8?q?=E6=98=9F=E4=BD=9C=E7=89=A9=E7=9A=84=E6=94=B6=E8=8E=B7=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E5=9C=A8=E5=8E=9F=E4=BD=9C=E7=89=A9=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/userSoil.py | 2 +- core/farm.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/database/userSoil.py b/core/database/userSoil.py index 32ab53d..05319b6 100644 --- a/core/database/userSoil.py +++ b/core/database/userSoil.py @@ -37,7 +37,7 @@ class CUserSoilDB(CSqlManager): Args: soilIndex (int): 地块索引 从1开始 """ - if not g_bIsDebug: + if g_bIsDebug: return soilInfo = await cls.getUserSoil(uid, soilIndex) diff --git a/core/farm.py b/core/farm.py index 1770fa9..019cca2 100644 --- a/core/farm.py +++ b/core/farm.py @@ -631,8 +631,15 @@ class CFarmManager: # 统计收获次数 try: + # 统一处理星级植物名称 + plant_name = soilInfo["plantName"] + + # 简单判断是否包含"星",如果包含则分割取后半部分 + if "星" in plant_name: + plant_name = plant_name.split("星", 1)[-1] + await g_pDBService.userPlantCount.addUserPlantCountByUid( - uid, soilInfo["plantName"] + uid, plant_name ) except Exception: # 忽略统计异常,避免影响主流程 From 90f08187c568f333b8500662256479ac1c269d83 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Mon, 27 Oct 2025 11:43:11 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=85=20=E5=85=B3=E9=97=ADdebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/userSoil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/database/userSoil.py b/core/database/userSoil.py index 05319b6..32ab53d 100644 --- a/core/database/userSoil.py +++ b/core/database/userSoil.py @@ -37,7 +37,7 @@ class CUserSoilDB(CSqlManager): Args: soilIndex (int): 地块索引 从1开始 """ - if g_bIsDebug: + if not g_bIsDebug: return soilInfo = await cls.getUserSoil(uid, soilIndex) From ed25299c4bf4e87d73e31586ddbcb22820762d08 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Sat, 1 Nov 2025 13:53:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=98=9F?= =?UTF-8?q?=E7=BA=A7=E4=BD=9C=E7=89=A9=E7=BB=9F=E8=AE=A1=E6=94=B6=E8=8E=B7?= =?UTF-8?q?=E6=AC=A1=E6=95=B0BUG=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=92=AD?= =?UTF-8?q?=E7=A7=8D=E6=97=B6=E5=8D=87=E6=98=9FBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/userSoil.py | 26 +++++++++++++++++++------- core/farm.py | 10 +++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/database/userSoil.py b/core/database/userSoil.py index 32ab53d..34f8d8a 100644 --- a/core/database/userSoil.py +++ b/core/database/userSoil.py @@ -1,4 +1,5 @@ import math +import re from zhenxun.services.log import logger @@ -405,18 +406,29 @@ class CUserSoilDB(CSqlManager): prev = soilInfo or {} await cls._deleteUserSoil(uid, soilIndex) # 根据此植物收获次数对其星级进行升级 - if g_pDBService.plant.existsPlant("一星" + plantName): + # 为避免对已带星级前缀的作物重复添加前缀,先提取基础名称 + base_name = plantName + m = re.match(r"^(?:一星|二星|三星|四星|五星)", plantName) + if m: + base_name = plantName[len(m.group(0)) :] + + # 只有当存在一星升级配置时才尝试按收获次数升级 + if await g_pDBService.plant.existsPlant("一星" + base_name): harvestCounts = ( await g_pDBService.userPlantCount.getUserPlantCountByPlantName( - uid, plantName + uid, base_name ) ) - if harvestCounts >= 350: - plantName = "一星" + plantName - if harvestCounts >= 700: - plantName = "二星" + plantName + # 根据阈值设定最高星级(避免重复拼接) + prefix = "" if harvestCounts >= 1200: - plantName = "三星" + plantName + prefix = "三星" + elif harvestCounts >= 700: + prefix = "二星" + elif harvestCounts >= 350: + prefix = "一星" + + plantName = prefix + base_name if prefix else base_name await cls._insertUserSoil( { diff --git a/core/farm.py b/core/farm.py index 019cca2..4e1abd0 100644 --- a/core/farm.py +++ b/core/farm.py @@ -1,5 +1,6 @@ import math import random +import re from zhenxun.configs.config import Config from zhenxun.models.user_console import UserConsole @@ -631,12 +632,11 @@ class CFarmManager: # 统计收获次数 try: - # 统一处理星级植物名称 + # 处理星级前缀(只在前两字为 一星/二星/三星/四星/五星 时去掉前缀) plant_name = soilInfo["plantName"] - - # 简单判断是否包含"星",如果包含则分割取后半部分 - if "星" in plant_name: - plant_name = plant_name.split("星", 1)[-1] + m = re.match(r"^(?:一星|二星|三星|四星|五星)", plant_name) + if m: + plant_name = plant_name[len(m.group(0)) :] await g_pDBService.userPlantCount.addUserPlantCountByUid( uid, plant_name