🐛 修复铲除荒废作物会清空地块的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()
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):

View File

@ -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,
}
)

View File

@ -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),