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 f9f0150..da5cce4 100644 Binary files a/resource/db/plant.db and b/resource/db/plant.db differ