From 69ddbe46694445e68bb5c627fdc65df55ce49046 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Mon, 30 Jun 2025 03:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=E4=BF=AE=E5=A4=8D=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E9=93=B2=E9=99=A4=E8=8D=92=E5=BA=9F?= =?UTF-8?q?=E4=BD=9C=E7=89=A9=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/userSign.py | 2 +- database/userSoil.py | 30 +++++++++--------------------- farm/farm.py | 25 +++++++++++++------------ request.py | 1 - 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/database/userSign.py b/database/userSign.py index a68569d..ffe2abe 100644 --- a/database/userSign.py +++ b/database/userSign.py @@ -273,7 +273,7 @@ class CUserSignDB(CSqlManager): sql = "SELECT signDate FROM userSignLog WHERE uid=? AND signDate LIKE ?" async with cls.m_pDB.execute(sql, (uid, f"{monthStr}-%")) as cursor: 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: logger.warning("绘制签到图时数据库查询失败", e=e) signedDays = set() diff --git a/database/userSoil.py b/database/userSoil.py index cd0e7c5..e167b71 100644 --- a/database/userSoil.py +++ b/database/userSoil.py @@ -24,6 +24,7 @@ class CUserSoilDB(CSqlManager): "weedStatus": "INTEGER DEFAULT 0", # 杂草状态 0=无杂草,1=有杂草 "waterStatus": "INTEGER DEFAULT 0", # 缺水状态 0=不缺水,1=缺水 "harvestCount": "INTEGER DEFAULT 0", # 收获次数 + "isSoilPlanted": "INTEGER DEFAULT 0", # 是否种植作物 "PRIMARY KEY": "(uid, soilIndex)", } @@ -182,8 +183,8 @@ class CUserSoilDB(CSqlManager): INSERT INTO userSoil (uid, soilIndex, plantName, plantTime, matureTime, soilLevel, wiltStatus, fertilizerStatus, bugStatus, - weedStatus, waterStatus, harvestCount) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?) + weedStatus, waterStatus, harvestCount, isSoilPlanted) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) """, ( soilInfo["uid"], @@ -198,6 +199,7 @@ class CUserSoilDB(CSqlManager): soilInfo.get("weedStatus", 0), soilInfo.get("waterStatus", 0), soilInfo.get("harvestCount", 0), + soilInfo.get("isSoilPlanted", 0), ), ) @@ -216,8 +218,8 @@ class CUserSoilDB(CSqlManager): INSERT INTO userSoil (uid, soilIndex, plantName, plantTime, matureTime, soilLevel, wiltStatus, fertilizerStatus, bugStatus, - weedStatus, waterStatus, harvestCount) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?) + weedStatus, waterStatus, harvestCount, isSoilPlanted) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) """, ( soilInfo["uid"], @@ -232,6 +234,7 @@ class CUserSoilDB(CSqlManager): soilInfo.get("weedStatus", 0), soilInfo.get("waterStatus", 0), soilInfo.get("harvestCount", 0), + soilInfo.get("isSoilPlanted", 0), ), ) @@ -360,6 +363,7 @@ class CUserSoilDB(CSqlManager): "weedStatus", "waterStatus", "harvestCount", + "isSoilPlanted", } setClauses = [] values = [] @@ -413,23 +417,6 @@ class CUserSoilDB(CSqlManager): "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 async def sowingByPlantName(cls, uid: str, soilIndex: int, plantName: str) -> bool: """播种指定作物到用户土地区 @@ -481,6 +468,7 @@ class CUserSoilDB(CSqlManager): "weedStatus": 0, "waterStatus": 0, "harvestCount": 0, + "isSoilPlanted": 1, } ) return True diff --git a/farm/farm.py b/farm/farm.py index 9cae8a3..0a65901 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -552,14 +552,14 @@ class CFarmManager: harvestCount = 0 # 成功收获数量 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) if not soilInfo: continue + # 如果没有种植 + if soilInfo.get("isSoilPlanted", 0): + continue + level = soilInfo.get("soilLevel", 0) # 如果是枯萎状态 @@ -676,14 +676,14 @@ class CFarmManager: experience = 0 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) if not soilInfo: continue + # 如果没有种植 + if soilInfo.get("isSoilPlanted", 0): + continue + # 如果不是枯萎状态 if soilInfo.get("wiltStatus", 0) == 0: continue @@ -704,6 +704,7 @@ class CFarmManager: "plantTime": 0, "matureTime": 0, "wiltStatus": 0, + "isSoilPlanted": 0, }, ) @@ -810,14 +811,14 @@ class CFarmManager: isStealingPlant = 0 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) if not soilInfo: continue + # 如果没有种植 + if soilInfo.get("isSoilPlanted", 0): + continue + # 如果是枯萎状态 if soilInfo.get("wiltStatus", 1) == 1: continue diff --git a/request.py b/request.py index 5eae182..8773f13 100644 --- a/request.py +++ b/request.py @@ -10,7 +10,6 @@ from rich.progress import ( TimeRemainingColumn, TransferSpeedColumn, ) - from zhenxun.configs.config import Config from zhenxun.services.log import logger