From f4e192ff27acd711c23eb739ad2340e71d17ce30 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sun, 29 Jun 2025 21:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=93=B2?= =?UTF-8?q?=E9=99=A4=E8=8D=92=E5=BA=9F=E4=BD=9C=E7=89=A9=E4=BC=9A=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E5=9C=B0=E5=9D=97=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 2 +- database/userSoil.py | 22 ++++++++++++---------- farm/farm.py | 34 ++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/command.py b/command.py index e600dba..b5990e9 100644 --- a/command.py +++ b/command.py @@ -557,7 +557,7 @@ soil_upgrade = on_alconna( @soil_upgrade.handle() -async def _(session: Uninfo, index: Query[int] = AlconnaQuery("num", 1)): +async def _(session: Uninfo, index: Query[int] = AlconnaQuery("index", 1)): uid = str(session.user.id) if not await g_pToolManager.isRegisteredByUid(uid): diff --git a/database/userSoil.py b/database/userSoil.py index 627b7fc..87a315e 100644 --- a/database/userSoil.py +++ b/database/userSoil.py @@ -1,3 +1,5 @@ +import math + from zhenxun.services.log import logger from ..config import g_bIsDebug @@ -88,7 +90,7 @@ class CUserSoilDB(CSqlManager): if not plantInfo: return - currentTime = g_pToolManager.dateTime().now().timestamp() + currentTime = int(g_pToolManager.dateTime().now().timestamp()) # 如果当前时间已经超过或等于成熟时间,则作物已成熟或可收获 if currentTime >= soilInfo["matureTime"]: return @@ -234,7 +236,7 @@ class CUserSoilDB(CSqlManager): ) @classmethod - async def getUserSoil(cls, uid: str, soilIndex: int) -> dict | None: + async def getUserSoil(cls, uid: str, soilIndex: int) -> dict: """获取指定用户某块土地的详细信息 Args: @@ -251,7 +253,7 @@ class CUserSoilDB(CSqlManager): ) row = await cursor.fetchone() if not row: - return None + return {} columns = [description[0] for description in cursor.description] return dict(zip(columns, row)) @@ -442,7 +444,7 @@ class CUserSoilDB(CSqlManager): """ # 校验土地区是否已种植 soilInfo = await cls.getUserSoil(uid, soilIndex) - if not soilInfo: + if soilInfo and soilInfo.get("plantName"): return False # 获取植物配置 @@ -457,7 +459,7 @@ class CUserSoilDB(CSqlManager): percent = await cls.getSoilLevelTime(soilInfo.get("soilLevel", 0)) # 处理土地等级带来的时间缩短 - time = time * (100 + percent) // 100 + time = math.floor(time * (100 + percent) // 100) matureTs = nowTs + time * 3600 @@ -473,11 +475,11 @@ class CUserSoilDB(CSqlManager): "plantTime": nowTs, "matureTime": matureTs, "soilLevel": prev.get("soilLevel", 0), - "wiltStatus": prev.get("wiltStatus", 0), - "fertilizerStatus": prev.get("fertilizerStatus", 0), - "bugStatus": prev.get("bugStatus", 0), - "weedStatus": prev.get("weedStatus", 0), - "waterStatus": prev.get("waterStatus", 0), + "wiltStatus": 0, + "fertilizerStatus": 0, + "bugStatus": 0, + "weedStatus": 0, + "waterStatus": 0, "harvestCount": 0, } ) diff --git a/farm/farm.py b/farm/farm.py index 1beab59..ee9735d 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -86,7 +86,7 @@ class CFarmManager: if index < soilUnlock: soilUrl = "" # TODO 缺少判断用户土地资源状况 - soilInfo = await g_pDBService.userSoil.getUserSoil(uid, index) + soilInfo = await g_pDBService.userSoil.getUserSoil(uid, index + 1) if not soilInfo: soilUrl = "soil/普通土地.png" @@ -582,7 +582,7 @@ class CFarmManager: percent = await g_pDBService.userSoil.getSoilLevelHarvestNumber( level ) - number = number * (100 + percent) // 100 + number = math.floor(number * (100 + percent) // 100) if number <= 0: continue @@ -592,13 +592,13 @@ class CFarmManager: # 处理土地等级带来的经验增长 向下取整 percent = await g_pDBService.userSoil.getSoilLevelHarvestExp(level) - experience = experience * (100 + percent) // 100 + experience = math.floor(experience * (100 + percent) // 100) harvestRecords.append( g_sTranslation["harvest"]["append"].format( name=soilInfo["plantName"], num=number, - exp=experience, + exp=plantInfo["experience"], ) ) @@ -687,9 +687,19 @@ class CFarmManager: if g_bIsDebug: experience += 999 - # 批量更新数据库操作 + # 更新数据库操作 await g_pDBService.userSoil.deleteUserSoil(uid, i) + await g_pDBService.userSoil.updateUserSoilFields( + uid, + i, + { + "plantName": "", + "plantTime": 0, + "matureTime": 0, + }, + ) + # 铲除作物会将偷菜记录清空 await g_pDBService.userSteal.deleteStealRecord(uid, i) @@ -1001,7 +1011,9 @@ class CFarmManager: soilLevelText = await g_pDBService.userSoil.getSoilLevel(soilLevel) fileter = g_pJsonManager.m_pSoil["upgrade"][soilLevelText][countSoil] - lines = ["升级该土地所需:"] + nextLevel = await g_pDBService.userSoil.getSoilLevelText(soilLevel) + + lines = ["将土地升级至:" + nextLevel + "。", "所需:"] fields = [ ("level", "等级"), ("point", "金币"), @@ -1075,13 +1087,11 @@ class CFarmManager: await g_pDBService.userSoil.matureNow(uid, soilIndex) # 更新数据库字段 - await g_pDBService.user.updateUserPointByUid( - uid, userInfo.get("point", 0) - fileter.get("point", 0) - ) + point = userInfo.get("point", 0) - fileter.get("point", 0) + await g_pDBService.user.updateUserPointByUid(uid, point) - await g_pDBService.user.updateUserPointByUid( - uid, userInfo.get("vipPoint", 0) - fileter.get("vipPoint", 0) - ) + vipPoint = userInfo.get("vipPoint", 0) - fileter.get("vipPoint", 0) + await g_pDBService.user.updateUserVipPointByUid(uid, vipPoint) return g_sTranslation["soilInfo"]["success"].format( name=await g_pDBService.userSoil.getSoilLevelText(soilLevel),