🚑 修复无法正常铲除荒废作物的BUG

This commit is contained in:
Art_Sakura 2025-06-30 03:43:44 +08:00
parent 564d9858f5
commit 69ddbe4669
4 changed files with 23 additions and 35 deletions

View File

@ -273,7 +273,7 @@ class CUserSignDB(CSqlManager):
sql = "SELECT signDate FROM userSignLog WHERE uid=? AND signDate LIKE ?" sql = "SELECT signDate FROM userSignLog WHERE uid=? AND signDate LIKE ?"
async with cls.m_pDB.execute(sql, (uid, f"{monthStr}-%")) as cursor: async with cls.m_pDB.execute(sql, (uid, f"{monthStr}-%")) as cursor:
rows = await cursor.fetchall() rows = await cursor.fetchall()
signedDays = set(int(r[0][-2:]) for r in rows if r[0][-2:].isdigit()) signedDays = {int(r[0][-2:]) for r in rows if r[0][-2:].isdigit()}
except Exception as e: except Exception as e:
logger.warning("绘制签到图时数据库查询失败", e=e) logger.warning("绘制签到图时数据库查询失败", e=e)
signedDays = set() signedDays = set()

View File

@ -24,6 +24,7 @@ class CUserSoilDB(CSqlManager):
"weedStatus": "INTEGER DEFAULT 0", # 杂草状态 0=无杂草1=有杂草 "weedStatus": "INTEGER DEFAULT 0", # 杂草状态 0=无杂草1=有杂草
"waterStatus": "INTEGER DEFAULT 0", # 缺水状态 0=不缺水1=缺水 "waterStatus": "INTEGER DEFAULT 0", # 缺水状态 0=不缺水1=缺水
"harvestCount": "INTEGER DEFAULT 0", # 收获次数 "harvestCount": "INTEGER DEFAULT 0", # 收获次数
"isSoilPlanted": "INTEGER DEFAULT 0", # 是否种植作物
"PRIMARY KEY": "(uid, soilIndex)", "PRIMARY KEY": "(uid, soilIndex)",
} }
@ -182,8 +183,8 @@ class CUserSoilDB(CSqlManager):
INSERT INTO userSoil INSERT INTO userSoil
(uid, soilIndex, plantName, plantTime, matureTime, (uid, soilIndex, plantName, plantTime, matureTime,
soilLevel, wiltStatus, fertilizerStatus, bugStatus, soilLevel, wiltStatus, fertilizerStatus, bugStatus,
weedStatus, waterStatus, harvestCount) weedStatus, waterStatus, harvestCount, isSoilPlanted)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
""", """,
( (
soilInfo["uid"], soilInfo["uid"],
@ -198,6 +199,7 @@ class CUserSoilDB(CSqlManager):
soilInfo.get("weedStatus", 0), soilInfo.get("weedStatus", 0),
soilInfo.get("waterStatus", 0), soilInfo.get("waterStatus", 0),
soilInfo.get("harvestCount", 0), soilInfo.get("harvestCount", 0),
soilInfo.get("isSoilPlanted", 0),
), ),
) )
@ -216,8 +218,8 @@ class CUserSoilDB(CSqlManager):
INSERT INTO userSoil INSERT INTO userSoil
(uid, soilIndex, plantName, plantTime, matureTime, (uid, soilIndex, plantName, plantTime, matureTime,
soilLevel, wiltStatus, fertilizerStatus, bugStatus, soilLevel, wiltStatus, fertilizerStatus, bugStatus,
weedStatus, waterStatus, harvestCount) weedStatus, waterStatus, harvestCount, isSoilPlanted)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
""", """,
( (
soilInfo["uid"], soilInfo["uid"],
@ -232,6 +234,7 @@ class CUserSoilDB(CSqlManager):
soilInfo.get("weedStatus", 0), soilInfo.get("weedStatus", 0),
soilInfo.get("waterStatus", 0), soilInfo.get("waterStatus", 0),
soilInfo.get("harvestCount", 0), soilInfo.get("harvestCount", 0),
soilInfo.get("isSoilPlanted", 0),
), ),
) )
@ -360,6 +363,7 @@ class CUserSoilDB(CSqlManager):
"weedStatus", "weedStatus",
"waterStatus", "waterStatus",
"harvestCount", "harvestCount",
"isSoilPlanted",
} }
setClauses = [] setClauses = []
values = [] values = []
@ -413,23 +417,6 @@ class CUserSoilDB(CSqlManager):
"DELETE FROM userSoil WHERE uid = ? AND soilIndex = ?", (uid, soilIndex) "DELETE FROM userSoil WHERE uid = ? AND soilIndex = ?", (uid, soilIndex)
) )
@classmethod
async def isSoilPlanted(cls, uid: str, soilIndex: int) -> bool:
"""判断指定用户的指定土地是否已种植
Args:
uid (str): 用户ID
soilIndex (int): 土地索引
Returns:
bool: 如果 plantName 不为空且 plantTime 大于 0则视为已种植返回 True否则 False
"""
soilInfo = await cls.getUserSoil(uid, soilIndex)
if not soilInfo:
return False
return bool(soilInfo.get("plantName")) and soilInfo.get("plantTime", 0) > 0
@classmethod @classmethod
async def sowingByPlantName(cls, uid: str, soilIndex: int, plantName: str) -> bool: async def sowingByPlantName(cls, uid: str, soilIndex: int, plantName: str) -> bool:
"""播种指定作物到用户土地区 """播种指定作物到用户土地区
@ -481,6 +468,7 @@ class CUserSoilDB(CSqlManager):
"weedStatus": 0, "weedStatus": 0,
"waterStatus": 0, "waterStatus": 0,
"harvestCount": 0, "harvestCount": 0,
"isSoilPlanted": 1,
} }
) )
return True return True

View File

@ -552,14 +552,14 @@ class CFarmManager:
harvestCount = 0 # 成功收获数量 harvestCount = 0 # 成功收获数量
for i in range(1, soilNumber + 1): for i in range(1, soilNumber + 1):
# 如果没有种植
if not await g_pDBService.userSoil.isSoilPlanted(uid, i):
continue
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i) soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
if not soilInfo: if not soilInfo:
continue continue
# 如果没有种植
if soilInfo.get("isSoilPlanted", 0):
continue
level = soilInfo.get("soilLevel", 0) level = soilInfo.get("soilLevel", 0)
# 如果是枯萎状态 # 如果是枯萎状态
@ -676,14 +676,14 @@ class CFarmManager:
experience = 0 experience = 0
for i in range(1, soilNumber + 1): for i in range(1, soilNumber + 1):
# 如果没有种植
if not await g_pDBService.userSoil.isSoilPlanted(uid, i):
continue
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i) soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
if not soilInfo: if not soilInfo:
continue continue
# 如果没有种植
if soilInfo.get("isSoilPlanted", 0):
continue
# 如果不是枯萎状态 # 如果不是枯萎状态
if soilInfo.get("wiltStatus", 0) == 0: if soilInfo.get("wiltStatus", 0) == 0:
continue continue
@ -704,6 +704,7 @@ class CFarmManager:
"plantTime": 0, "plantTime": 0,
"matureTime": 0, "matureTime": 0,
"wiltStatus": 0, "wiltStatus": 0,
"isSoilPlanted": 0,
}, },
) )
@ -810,14 +811,14 @@ class CFarmManager:
isStealingPlant = 0 isStealingPlant = 0
for i in range(1, soilNumber + 1): for i in range(1, soilNumber + 1):
# 如果没有种植
if not await g_pDBService.userSoil.isSoilPlanted(target, i):
continue
soilInfo = await g_pDBService.userSoil.getUserSoil(target, i) soilInfo = await g_pDBService.userSoil.getUserSoil(target, i)
if not soilInfo: if not soilInfo:
continue continue
# 如果没有种植
if soilInfo.get("isSoilPlanted", 0):
continue
# 如果是枯萎状态 # 如果是枯萎状态
if soilInfo.get("wiltStatus", 1) == 1: if soilInfo.get("wiltStatus", 1) == 1:
continue continue

View File

@ -10,7 +10,6 @@ from rich.progress import (
TimeRemainingColumn, TimeRemainingColumn,
TransferSpeedColumn, TransferSpeedColumn,
) )
from zhenxun.configs.config import Config from zhenxun.configs.config import Config
from zhenxun.services.log import logger from zhenxun.services.log import logger