From 16c801bcb6a4b357be50bfe2383b5d89a330d775 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sat, 22 Mar 2025 00:26:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8=E5=81=B7?= =?UTF-8?q?=E8=8F=9C=E3=80=81=E6=94=B6=E8=8F=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 2 +- farm/farm.py | 130 +++++++++++++++++++++++++++------------------------ 2 files changed, 69 insertions(+), 63 deletions(-) diff --git a/command.py b/command.py index e2da46d..344a4a4 100644 --- a/command.py +++ b/command.py @@ -295,7 +295,7 @@ async def _(session: Uninfo, target: Match[At]): point = await g_pSqlManager.getUserPointByUid(tar.target) if point < 0: - await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() + await MessageUtils.build_message("目标尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.stealing(uid, tar.target) diff --git a/farm/farm.py b/farm/farm.py index 16f326b..7999bf0 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -301,7 +301,7 @@ class CFarmManager: plant = {} - soilNames = [f"soil{i}" for i in range(soilUnlock)] + soilNames = [f"soil{i + 1}" for i in range(soilUnlock)] soilStatuses = await asyncio.gather(*[ g_pSqlManager.getUserSoilStatusBySoilID(uid, name) for name in soilNames @@ -312,30 +312,35 @@ class CFarmManager: experience = 0 for (soil_name, (status, info)) in zip(soilNames, soilStatuses): - if not status: - soilInfo = info.split(',') - plantId = soilInfo[0] - plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore + if len(info) <= 0: + continue - currentTime = datetime.now() - matureTime = datetime.fromtimestamp(int(soilInfo[2])) + soilInfo = info.split(',') + if soilInfo[3] == 4: + continue - if currentTime >= matureTime: - number = plantInfo['harvest'] + plantId = soilInfo[0] + plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore - #判断该土地作物是否被透过 - if len(soilInfo[4]) > 0: - stealingStatus = soilInfo[4].split('|') - for isUser in stealingStatus: - user = isUser.split('-') - number -= user[1] + currentTime = datetime.now() + matureTime = datetime.fromtimestamp(int(soilInfo[2])) - plant[plantId] = plant.get(plantId, 0) + number - experience += plantInfo['experience'] - harvestRecords.append(f"收获作物:{plantId},数量为:{number},经验为:{plantInfo['experience']}") + if currentTime >= matureTime: + number = plantInfo['harvest'] - #批量更新数据库操作 - await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soil_name, "", 4) + #判断该土地作物是否被透过 + if len(soilInfo[4]) > 0: + stealingStatus = soilInfo[4].split('|') + for isUser in stealingStatus: + user = isUser.split('-') + number -= user[1] + + plant[plantId] = plant.get(plantId, 0) + number + experience += plantInfo['experience'] + harvestRecords.append(f"收获作物:{plantId},数量为:{number},经验为:{plantInfo['experience']}") + + #批量更新数据库操作 + await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soil_name, "", 4) if experience > 0: harvestRecords.append(f"\t累计获得经验:{experience}") @@ -495,7 +500,7 @@ class CFarmManager: plant = {} #根据解锁土地,获取每块土地状态信息 - soilNames = [f"soil{i}" for i in range(soilUnlock)] + soilNames = [f"soil{i + 1}" for i in range(soilUnlock)] soilStatuses = await asyncio.gather(*[ g_pSqlManager.getUserSoilStatusBySoilID(target, name) for name in soilNames @@ -508,53 +513,54 @@ class CFarmManager: for (soilName, (status, info)) in zip(soilNames, soilStatuses): isStealing = False - if not info: - soilInfo = info.split(',') - if soilInfo[3] == 4: + if len(info) < 0: + continue + + soilInfo = info.split(',') + if soilInfo[3] == 4: + continue + + plantId = soilInfo[0] + plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore + + currentTime = datetime.now() + matureTime = datetime.fromtimestamp(int(soilInfo[2])) + + stealingNumber = 0 + + if currentTime >= matureTime: + #先获取用户是否偷过该土地 + stealingStatus = soilInfo[4].split('|') + for isUser in stealingStatus: + user = isUser.split('-') + + if user[0] == uid: + isStealing = True + break + + stealingNumber += int(user[1]) + + #如果偷过,则跳过该土地 + if isStealing: continue - plantId = soilInfo[0] - plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore + stealingNumber -= plantInfo['harvest'] + randomNumber = random.choice([1, 2]) + randomNumber = min(randomNumber, stealingNumber) - currentTime = datetime.now() - matureTime = datetime.fromtimestamp(int(soilInfo[2])) + if randomNumber > 0: + plant[plantId] = plant.get(plantId, 0) + randomNumber + harvestRecords.append(f"成功偷到作物:{plantId},数量为:{randomNumber}") - stealingNumber = 0 + stealingStatus.append(f"|{uid}-{randomNumber}") - if currentTime >= matureTime: - #先获取用户是否偷过该土地 - stealingStatus = soilInfo[4].split('|') - for isUser in stealingStatus: - user = isUser.split('-') + #如果将作物偷完,就直接更新状态 并记录用户偷取过 + if plantInfo['harvest'] - randomNumber + stealingNumber == 0: + sql = f"UPDATE soil SET {soilName} = ',,,4,{stealingStatus}' WHERE uid = '{target}'" + else: + sql = f"UPDATE soil SET {soilName} = '{soilInfo[0]},{soilInfo[1]},{soilInfo[2]},{soilInfo[3]},{stealingStatus}' WHERE uid = '{target}'" - if user[0] == uid: - isStealing = True - break - - stealingNumber += int(user[1]) - - #如果偷过,则跳过该土地 - if isStealing: - continue - - stealingNumber -= plantInfo['harvest'] - randomNumber = random.choice([1, 2]) - randomNumber = min(randomNumber, stealingNumber) - - if randomNumber > 0: - plant[plantId] = plant.get(plantId, 0) + randomNumber - harvestRecords.append(f"成功偷到作物:{plantId},数量为:{randomNumber}") - - newElement = f"|{uid}-{randomNumber}" - stealingStatus.append(newElement) - - #如果将作物偷完,就直接更新状态 并记录用户偷取过 - if plantInfo['harvest'] - randomNumber + stealingNumber == 0: - sql = f"UPDATE soil SET {soilName} = ',,,4,{stealingStatus}' WHERE uid = '{target}'" - else: - sql = f"UPDATE soil SET {soilName} = '{soilInfo[0]},{soilInfo[1]},{soilInfo[2]},{soilInfo[3]},{stealingStatus}' WHERE uid = '{target}'" - - await g_pSqlManager.executeDB(sql) + await g_pSqlManager.executeDB(sql) if not plant: return "目标没有作物可以被偷"