🐛 修复铲除荒废作物会清空地块的BUG

This commit is contained in:
Art_Sakura 2025-06-29 21:31:09 +08:00
parent c6f24bc3c2
commit f4e192ff27
3 changed files with 35 additions and 23 deletions

View File

@ -557,7 +557,7 @@ soil_upgrade = on_alconna(
@soil_upgrade.handle() @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) uid = str(session.user.id)
if not await g_pToolManager.isRegisteredByUid(uid): if not await g_pToolManager.isRegisteredByUid(uid):

View File

@ -1,3 +1,5 @@
import math
from zhenxun.services.log import logger from zhenxun.services.log import logger
from ..config import g_bIsDebug from ..config import g_bIsDebug
@ -88,7 +90,7 @@ class CUserSoilDB(CSqlManager):
if not plantInfo: if not plantInfo:
return return
currentTime = g_pToolManager.dateTime().now().timestamp() currentTime = int(g_pToolManager.dateTime().now().timestamp())
# 如果当前时间已经超过或等于成熟时间,则作物已成熟或可收获 # 如果当前时间已经超过或等于成熟时间,则作物已成熟或可收获
if currentTime >= soilInfo["matureTime"]: if currentTime >= soilInfo["matureTime"]:
return return
@ -234,7 +236,7 @@ class CUserSoilDB(CSqlManager):
) )
@classmethod @classmethod
async def getUserSoil(cls, uid: str, soilIndex: int) -> dict | None: async def getUserSoil(cls, uid: str, soilIndex: int) -> dict:
"""获取指定用户某块土地的详细信息 """获取指定用户某块土地的详细信息
Args: Args:
@ -251,7 +253,7 @@ class CUserSoilDB(CSqlManager):
) )
row = await cursor.fetchone() row = await cursor.fetchone()
if not row: if not row:
return None return {}
columns = [description[0] for description in cursor.description] columns = [description[0] for description in cursor.description]
return dict(zip(columns, row)) return dict(zip(columns, row))
@ -442,7 +444,7 @@ class CUserSoilDB(CSqlManager):
""" """
# 校验土地区是否已种植 # 校验土地区是否已种植
soilInfo = await cls.getUserSoil(uid, soilIndex) soilInfo = await cls.getUserSoil(uid, soilIndex)
if not soilInfo: if soilInfo and soilInfo.get("plantName"):
return False return False
# 获取植物配置 # 获取植物配置
@ -457,7 +459,7 @@ class CUserSoilDB(CSqlManager):
percent = await cls.getSoilLevelTime(soilInfo.get("soilLevel", 0)) percent = await cls.getSoilLevelTime(soilInfo.get("soilLevel", 0))
# 处理土地等级带来的时间缩短 # 处理土地等级带来的时间缩短
time = time * (100 + percent) // 100 time = math.floor(time * (100 + percent) // 100)
matureTs = nowTs + time * 3600 matureTs = nowTs + time * 3600
@ -473,11 +475,11 @@ class CUserSoilDB(CSqlManager):
"plantTime": nowTs, "plantTime": nowTs,
"matureTime": matureTs, "matureTime": matureTs,
"soilLevel": prev.get("soilLevel", 0), "soilLevel": prev.get("soilLevel", 0),
"wiltStatus": prev.get("wiltStatus", 0), "wiltStatus": 0,
"fertilizerStatus": prev.get("fertilizerStatus", 0), "fertilizerStatus": 0,
"bugStatus": prev.get("bugStatus", 0), "bugStatus": 0,
"weedStatus": prev.get("weedStatus", 0), "weedStatus": 0,
"waterStatus": prev.get("waterStatus", 0), "waterStatus": 0,
"harvestCount": 0, "harvestCount": 0,
} }
) )

View File

@ -86,7 +86,7 @@ class CFarmManager:
if index < soilUnlock: if index < soilUnlock:
soilUrl = "" soilUrl = ""
# TODO 缺少判断用户土地资源状况 # TODO 缺少判断用户土地资源状况
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, index) soilInfo = await g_pDBService.userSoil.getUserSoil(uid, index + 1)
if not soilInfo: if not soilInfo:
soilUrl = "soil/普通土地.png" soilUrl = "soil/普通土地.png"
@ -582,7 +582,7 @@ class CFarmManager:
percent = await g_pDBService.userSoil.getSoilLevelHarvestNumber( percent = await g_pDBService.userSoil.getSoilLevelHarvestNumber(
level level
) )
number = number * (100 + percent) // 100 number = math.floor(number * (100 + percent) // 100)
if number <= 0: if number <= 0:
continue continue
@ -592,13 +592,13 @@ class CFarmManager:
# 处理土地等级带来的经验增长 向下取整 # 处理土地等级带来的经验增长 向下取整
percent = await g_pDBService.userSoil.getSoilLevelHarvestExp(level) percent = await g_pDBService.userSoil.getSoilLevelHarvestExp(level)
experience = experience * (100 + percent) // 100 experience = math.floor(experience * (100 + percent) // 100)
harvestRecords.append( harvestRecords.append(
g_sTranslation["harvest"]["append"].format( g_sTranslation["harvest"]["append"].format(
name=soilInfo["plantName"], name=soilInfo["plantName"],
num=number, num=number,
exp=experience, exp=plantInfo["experience"],
) )
) )
@ -687,9 +687,19 @@ class CFarmManager:
if g_bIsDebug: if g_bIsDebug:
experience += 999 experience += 999
# 批量更新数据库操作 # 更新数据库操作
await g_pDBService.userSoil.deleteUserSoil(uid, i) 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) await g_pDBService.userSteal.deleteStealRecord(uid, i)
@ -1001,7 +1011,9 @@ class CFarmManager:
soilLevelText = await g_pDBService.userSoil.getSoilLevel(soilLevel) soilLevelText = await g_pDBService.userSoil.getSoilLevel(soilLevel)
fileter = g_pJsonManager.m_pSoil["upgrade"][soilLevelText][countSoil] fileter = g_pJsonManager.m_pSoil["upgrade"][soilLevelText][countSoil]
lines = ["升级该土地所需:"] nextLevel = await g_pDBService.userSoil.getSoilLevelText(soilLevel)
lines = ["将土地升级至:" + nextLevel + "", "所需:"]
fields = [ fields = [
("level", "等级"), ("level", "等级"),
("point", "金币"), ("point", "金币"),
@ -1075,13 +1087,11 @@ class CFarmManager:
await g_pDBService.userSoil.matureNow(uid, soilIndex) await g_pDBService.userSoil.matureNow(uid, soilIndex)
# 更新数据库字段 # 更新数据库字段
await g_pDBService.user.updateUserPointByUid( point = userInfo.get("point", 0) - fileter.get("point", 0)
uid, userInfo.get("point", 0) - fileter.get("point", 0) await g_pDBService.user.updateUserPointByUid(uid, point)
)
await g_pDBService.user.updateUserPointByUid( vipPoint = userInfo.get("vipPoint", 0) - fileter.get("vipPoint", 0)
uid, userInfo.get("vipPoint", 0) - fileter.get("vipPoint", 0) await g_pDBService.user.updateUserVipPointByUid(uid, vipPoint)
)
return g_sTranslation["soilInfo"]["success"].format( return g_sTranslation["soilInfo"]["success"].format(
name=await g_pDBService.userSoil.getSoilLevelText(soilLevel), name=await g_pDBService.userSoil.getSoilLevelText(soilLevel),