From 46fecc768495c71d92ea554cfef618495f560780 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Fri, 21 Mar 2025 23:34:19 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=8B=A5?= =?UTF-8?q?=E5=B9=B2=E4=B8=AA=E5=B7=B2=E7=9F=A5BUG=20=F0=9F=90=9B=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=91=E7=9A=84=E5=86=9C=E5=9C=BA=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=8A=A5=E9=94=99=E7=9A=84BUG=20=F0=9F=90=9B?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E4=B8=BA1=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 2 + command.py | 101 ++++++++++++++++++++++++++++------------------ config/level.json | 13 +++--- database.py | 4 +- farm/farm.py | 18 ++++++--- farm/shop.py | 2 +- 6 files changed, 86 insertions(+), 54 deletions(-) diff --git a/__init__.py b/__init__.py index 23d56ec..9ff19c7 100644 --- a/__init__.py +++ b/__init__.py @@ -17,6 +17,7 @@ __plugin_meta__ = PluginMetadata( usage=""" 你也要种地? 指令: + at 开通农场 我的农场 我的农场币 种子商店 @@ -28,6 +29,7 @@ __plugin_meta__ = PluginMetadata( 我的作物 出售作物 [作物/种子名称] [数量] 偷菜 at + 开垦 购买农场币 [数量] 金币转换农场币比率是 1 : 2 """.strip(), extra=PluginExtraData( diff --git a/command.py b/command.py index 7491521..e2da46d 100644 --- a/command.py +++ b/command.py @@ -43,6 +43,7 @@ diuse_farm = on_alconna( Subcommand("harvest", help_text="收获"), Subcommand("eradicate", help_text="铲除"), Subcommand("my-plant", help_text="我的作物"), + # Subcommand("reclamation", help_text="开垦"), Subcommand("sell-plant", Args["name?", str]["num?", int], help_text="出售作物"), Subcommand("stealing", Args["target?", At], help_text="偷菜"), Subcommand("buy-point", Args["num?", int], help_text="购买农场币"), @@ -58,7 +59,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None image = await g_pFarmManager.drawFarmByUid(uid) @@ -77,7 +78,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None await MessageUtils.build_message(f"你的当前农场币为: {point}").send(reply_to=True) @@ -95,7 +96,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None image = await g_pShopManager.getSeedShopImage() @@ -119,7 +120,7 @@ async def _(session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("n point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pShopManager.buySeed(uid, name.result, num.result) @@ -138,7 +139,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.getUserSeedByUid(uid) @@ -162,7 +163,7 @@ async def _(session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("n point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.sowing(uid, name.result, num.result) @@ -182,7 +183,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.harvest(uid) @@ -201,7 +202,7 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.eradicate(uid) @@ -221,12 +222,32 @@ async def _(session: Uninfo): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.getUserPlantByUid(uid) await MessageUtils.build_message(result).send(reply_to=True) +# diuse_farm.shortcut( +# "开垦", +# command="我的农场", +# arguments=["reclamation"], +# prefix=True, +# ) + +# @diuse_farm.assign("reclamation") +# async def _(session: Uninfo): +# uid = str(session.user.id) +# point = await g_pSqlManager.getUserPointByUid(uid) + +# if point < 0: +# await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() +# return None + +# result = await g_pFarmManager.getUserPlantByUid(uid) +# await MessageUtils.build_message(result).send(reply_to=True) + + diuse_farm.shortcut( "出售作物(?P.*?)", command="我的农场", @@ -245,12 +266,41 @@ async def _(session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("n point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pShopManager.sellPlantByUid(uid, name.result, num.result) await MessageUtils.build_message(result).send(reply_to=True) +diuse_farm.shortcut( + "偷菜", + command="我的农场", + arguments=["stealing"], + prefix=True, +) + +@diuse_farm.assign("stealing") +async def _(session: Uninfo, target: Match[At]): + uid = str(session.user.id) + point = await g_pSqlManager.getUserPointByUid(uid) + + if point < 0: + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() + return None + + if not target.available: + await MessageUtils.build_message("请在指令后跟需要at的人").finish(reply_to=True) + + tar = target.result + point = await g_pSqlManager.getUserPointByUid(tar.target) + + if point < 0: + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() + return None + + result = await g_pFarmManager.stealing(uid, tar.target) + await MessageUtils.build_message(result).send(reply_to=True) + diuse_farm.shortcut( "购买农场币(.*?)", command="我的农场", @@ -269,37 +319,8 @@ async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)): point = await g_pSqlManager.getUserPointByUid(uid) if point < 0: - await MessageUtils.build_message("尚未开通农场").send() + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() return None result = await g_pFarmManager.buyPointByUid(uid, num.result) await MessageUtils.build_message(result).send(reply_to=True) - -diuse_farm.shortcut( - "偷菜", - command="我的农场", - arguments=["stealing"], - prefix=True, -) - -@diuse_farm.assign("stealing") -async def _(session: Uninfo, target: Match[At]): - uid = str(session.user.id) - point = await g_pSqlManager.getUserPointByUid(uid) - - if point < 0: - await MessageUtils.build_message("尚未开通农场").send() - return None - - if not target.available: - await MessageUtils.build_message("请在指令后跟需要at的人").finish(reply_to=True) - - tar = target.result - point = await g_pSqlManager.getUserPointByUid(tar.target) - - if point < 0: - await MessageUtils.build_message("尚未开通农场").send() - return None - - result = await g_pFarmManager.stealing(uid, tar.target) - await MessageUtils.build_message(result).send(reply_to=True) diff --git a/config/level.json b/config/level.json index 50166c8..7f8a501 100644 --- a/config/level.json +++ b/config/level.json @@ -1,12 +1,13 @@ { "level": { - "1": 0, - "2": 50, - "3": 75, - "4": 125, - "5": 185, - "6": 200, + "0": 0, + "1": 50, + "2": 75, + "3": 125, + "4": 185, + "5": 200, + "6": 250, "7": 275, "8": 350, "9": 500, diff --git a/database.py b/database.py index d6b2e8c..e04ce19 100644 --- a/database.py +++ b/database.py @@ -144,7 +144,7 @@ class CSqlManager: if not await cls.executeDB(userSoilInfo): return False - return True + return "开通农场成功" @classmethod async def getUserInfoByUid(cls, uid: str) -> dict: @@ -324,7 +324,7 @@ class CSqlManager: async with cls.m_pDB.execute(f"SELECT soil FROM user WHERE uid = '{uid}'") as cursor: async for row in cursor: - if row[0] == None or len(row[0]) <= 0: + if not row[0]: return 0 else: return int(row[0]) diff --git a/farm/farm.py b/farm/farm.py index ec6c339..31fdc4f 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -4,7 +4,6 @@ from datetime import date, datetime from io import StringIO from typing import Dict, List, Tuple -from Python311.Lib.PIL.ImImagePlugin import number from zhenxun.models.user_console import UserConsole from zhenxun.services.log import logger from zhenxun.utils._build_image import BuildImage @@ -72,7 +71,7 @@ class CFarmManager: y = soilPos[str(index + 1)]['y'] #如果土地已经到达对应等级 - if index > soilUnlock: + if index < soilUnlock: await img.paste(soil, (x, y)) isPlant, plant, isRipe= await cls.drawSoilPlant(uid, f"soil{str(index + 1)}") @@ -273,8 +272,6 @@ class CFarmManager: # 更新种子数量 num -= 1 plantDict[name] -= 1 - if plantDict[name] == 0: - del plantDict[name] # 更新数据库 await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soilName, name) @@ -443,7 +440,7 @@ class CFarmManager: else: sell = "不可以" - number = count * int(plantInfo['price']) + number = int(count) * plantInfo['price'] data_list.append( [ @@ -570,5 +567,16 @@ class CFarmManager: return "\n".join(harvestRecords) + # @classmethod + # async def reclamation(cls, uid: str) -> str: + + # userInfo = await g_pSqlManager.getUserInfoByUid(uid) + # level = await g_pSqlManager.getUserLevelByUid(uid) + + # rec = g_pJsonManager["reclamation"] # type: ignore + + # if not rec[f"{userInfo["soil"] + 1}"] == None + + # return "" g_pFarmManager = CFarmManager() diff --git a/farm/shop.py b/farm/shop.py index de156d9..5ab3e54 100644 --- a/farm/shop.py +++ b/farm/shop.py @@ -93,7 +93,7 @@ class CShopManager: return "购买出错!请检查需购买的种子名称!" - level = g_pSqlManager.getUserLevelByUid(uid) + level = await g_pSqlManager.getUserLevelByUid(uid) if level < plantInfo['level']: return "你的等级不够哦,努努力吧" From 43b2184597639d421c4bb9e333a06e1ab057d448 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sat, 22 Mar 2025 00:08:23 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=87=91?= =?UTF-8?q?=E5=B8=81=E6=9B=B4=E6=96=B0=E5=BC=82=E5=B8=B8BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 10 ++-------- farm/farm.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/database.py b/database.py index e04ce19..01f208c 100644 --- a/database.py +++ b/database.py @@ -221,13 +221,7 @@ class CSqlManager: return -1 try: - async with cls.m_pDB.execute( - """UPDATE user - SET point = ? - WHERE uid = ? - RETURNING point""", - (point, uid) - ) as cursor: + async with cls.m_pDB.execute(f"UPDATE user SET point = {point} WHERE uid = '{uid}'") as cursor: async for row in cursor: return int(row[0]) @@ -235,7 +229,7 @@ class CSqlManager: return -1 except Exception as e: # 记录详细错误日志(建议记录堆栈) - logger.error(f"更新失败: {e}") + logger.error(f"金币更新失败: {e}") return -1 @classmethod diff --git a/farm/farm.py b/farm/farm.py index 31fdc4f..16f326b 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -374,7 +374,7 @@ class CFarmManager: experience = 0 for (soil_name, (status, info)) in zip(soilNames, soilStatuses): - if not status: + if not info: soilInfo = info.split(',') if int(soilInfo[3]) == 4: experience += 3 @@ -505,11 +505,14 @@ class CFarmManager: harvestRecords: List[str] = [] isStealing = False - for(soilName, (status, info)) in zip(soilNames, soilStatuses): + for (soilName, (status, info)) in zip(soilNames, soilStatuses): isStealing = False - if not status: + if not info: soilInfo = info.split(',') + if soilInfo[3] == 4: + continue + plantId = soilInfo[0] plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore @@ -542,7 +545,8 @@ class CFarmManager: plant[plantId] = plant.get(plantId, 0) + randomNumber harvestRecords.append(f"成功偷到作物:{plantId},数量为:{randomNumber}") - stealingStatus += f"|{uid}-{randomNumber}" + newElement = f"|{uid}-{randomNumber}" + stealingStatus.append(newElement) #如果将作物偷完,就直接更新状态 并记录用户偷取过 if plantInfo['harvest'] - randomNumber + stealingNumber == 0: 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 3/6] =?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 "目标没有作物可以被偷" From 09b51bf548ca182946661708d79ff976c12b85b3 Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sat, 22 Mar 2025 21:23:20 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=90=9B=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=E6=9E=AF=E8=90=8E?= =?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 --- __init__.py | 3 +++ command.py | 7 +++++++ farm/farm.py | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 9ff19c7..297a380 100644 --- a/__init__.py +++ b/__init__.py @@ -51,6 +51,9 @@ async def start(): # 初始化读取Json await g_pJsonManager.init() + # await g_pFarmManager.reclamation("1754798088") + # await g_pSqlManager.initUserInfoByUid("1754798088", "Art_Sakura", 0, 100) + # 析构函数 @driver.on_shutdown async def shutdown(): diff --git a/command.py b/command.py index 344a4a4..dfbff5c 100644 --- a/command.py +++ b/command.py @@ -247,6 +247,13 @@ async def _(session: Uninfo): # result = await g_pFarmManager.getUserPlantByUid(uid) # await MessageUtils.build_message(result).send(reply_to=True) +# diuse_farm.set_path_arg("reclamation", "") + + +# @diuse_farm.got("test") +# async def _(session: Uninfo, flag: str = ArgStr("flag")): +# await MessageUtils.build_message("测试一下").send(reply_to=True) + diuse_farm.shortcut( "出售作物(?P.*?)", diff --git a/farm/farm.py b/farm/farm.py index 7999bf0..f48250f 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -371,7 +371,7 @@ class CFarmManager: soilUnlock = await g_pSqlManager.getUserSoilByUid(uid) - 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 @@ -583,10 +583,18 @@ class CFarmManager: # userInfo = await g_pSqlManager.getUserInfoByUid(uid) # level = await g_pSqlManager.getUserLevelByUid(uid) - # rec = g_pJsonManager["reclamation"] # type: ignore + # rec = g_pJsonManager.m_pLevel["reclamation"] # type: ignore - # if not rec[f"{userInfo["soil"] + 1}"] == None + # try: + # rec = rec[f"{userInfo['soil'] + 1}"] - # return "" + # #TODO 缺少判断需要的Item + # if level >= rec['level'] and userInfo['point'] >= rec['point']: + + + # except Exception as e: + # return "获取升级土地条件失败!" + + # return "开垦土地失败,未知错误" g_pFarmManager = CFarmManager() From b1f25f12685466be2b516f42002c3d4aa83def9e Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sat, 22 Mar 2025 23:17:14 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=9A=91=20=E8=BF=98=E6=98=AF=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=93=B2=E9=99=A4=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- farm/farm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farm/farm.py b/farm/farm.py index f48250f..83c4a17 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -379,7 +379,7 @@ class CFarmManager: experience = 0 for (soil_name, (status, info)) in zip(soilNames, soilStatuses): - if not info: + if info: soilInfo = info.split(',') if int(soilInfo[3]) == 4: experience += 3 From f85ab9758c44ce45c6aae9e792f7a5d9e2f7459a Mon Sep 17 00:00:00 2001 From: Art_Sakura <1754798088@qq.com> Date: Sun, 23 Mar 2025 23:41:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=90=9B=20=E8=A7=A3=E5=86=B3=E4=BA=86B?= =?UTF-8?q?UG=EF=BC=8C=E4=BD=86=E6=98=AF=E5=BF=98=E4=BA=86=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=95=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 40 ++++++++++++++++++++-------------------- database.py | 2 +- farm/farm.py | 50 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/command.py b/command.py index dfbff5c..6bc76b0 100644 --- a/command.py +++ b/command.py @@ -43,7 +43,7 @@ diuse_farm = on_alconna( Subcommand("harvest", help_text="收获"), Subcommand("eradicate", help_text="铲除"), Subcommand("my-plant", help_text="我的作物"), - # Subcommand("reclamation", help_text="开垦"), + Subcommand("reclamation", Args["name", str], help_text="开垦"), Subcommand("sell-plant", Args["name?", str]["num?", int], help_text="出售作物"), Subcommand("stealing", Args["target?", At], help_text="偷菜"), Subcommand("buy-point", Args["num?", int], help_text="购买农场币"), @@ -228,31 +228,31 @@ async def _(session: Uninfo): result = await g_pFarmManager.getUserPlantByUid(uid) await MessageUtils.build_message(result).send(reply_to=True) -# diuse_farm.shortcut( -# "开垦", -# command="我的农场", -# arguments=["reclamation"], -# prefix=True, -# ) +diuse_farm.shortcut( + "开垦", + command="我的农场", + arguments=["reclamation"], + prefix=True, +) -# @diuse_farm.assign("reclamation") -# async def _(session: Uninfo): -# uid = str(session.user.id) -# point = await g_pSqlManager.getUserPointByUid(uid) +@diuse_farm.assign("reclamation") +async def _(session: Uninfo): + uid = str(session.user.id) + point = await g_pSqlManager.getUserPointByUid(uid) -# if point < 0: -# await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() -# return None + if point < 0: + await MessageUtils.build_message("尚未开通农场,快at我发送 开通农场 开通吧").send() + return None -# result = await g_pFarmManager.getUserPlantByUid(uid) -# await MessageUtils.build_message(result).send(reply_to=True) + result = await g_pFarmManager.getUserPlantByUid(uid) + await MessageUtils.build_message(result).send(reply_to=True) -# diuse_farm.set_path_arg("reclamation", "") + diuse_farm.set_path_arg("reclamation", "result") -# @diuse_farm.got("test") -# async def _(session: Uninfo, flag: str = ArgStr("flag")): -# await MessageUtils.build_message("测试一下").send(reply_to=True) +@diuse_farm.got_path("test", "测试一下") +async def _(name: str): + await MessageUtils.build_message(name).send(reply_to=True) diuse_farm.shortcut( diff --git a/database.py b/database.py index 01f208c..b76e191 100644 --- a/database.py +++ b/database.py @@ -375,7 +375,7 @@ class CSqlManager: plantInfo = g_pJsonManager.m_pPlant['plant'][plant] # type: ignore currentTime = datetime.now() - newTime = currentTime + timedelta(minutes=int(plantInfo['time'])) + newTime = currentTime + timedelta(hours=int(plantInfo['time'])) #种子名称,种下时间,预计成熟时间,地状态:0:无 1:长草 2:生虫 3:缺水 4:枯萎,是否被偷 示例:QQ号-偷取数量|QQ号-偷取数量 s = f"{plant},{int(currentTime.timestamp())},{int(newTime.timestamp())},{status}," diff --git a/farm/farm.py b/farm/farm.py index 83c4a17..09c8b43 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -276,15 +276,19 @@ class CFarmManager: # 更新数据库 await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soilName, name) - await g_pSqlManager.updateUserSeedByUid( - uid, - ','.join([f"{k}|{v}" for k, v in plantDict.items()]) - ) + str = "" if num > 0: - return f"播种数量超出开垦土地数量,已将可播种土地成功播种{name}!仓库还剩下{plantDict[name]}个种子" + str = f"播种数量超出开垦土地数量,已将可播种土地成功播种{name}!仓库还剩下{plantDict[name]}个种子" else: - return f"播种{name}成功!仓库还剩下{plantDict[name]}个种子" + str = f"播种{name}成功!仓库还剩下{plantDict[name]}个种子" + + await g_pSqlManager.updateUserSeedByUid( + uid, + ','.join([f"{k}|{v}" for k, v in plantDict.items() if v != 0]) + ) + + return str @classmethod async def harvest(cls, uid: str) -> str: @@ -513,11 +517,11 @@ class CFarmManager: for (soilName, (status, info)) in zip(soilNames, soilStatuses): isStealing = False - if len(info) < 0: + if not info: continue soilInfo = info.split(',') - if soilInfo[3] == 4: + if int(soilInfo[3]) == 4: continue plantId = soilInfo[0] @@ -526,28 +530,33 @@ class CFarmManager: currentTime = datetime.now() matureTime = datetime.fromtimestamp(int(soilInfo[2])) + stealingStatus: list[str] = [] stealingNumber = 0 - if currentTime >= matureTime: - #先获取用户是否偷过该土地 - stealingStatus = soilInfo[4].split('|') - for isUser in stealingStatus: - user = isUser.split('-') - if user[0] == uid: - isStealing = True - break + if soilInfo[4]: + #先获取用户是否偷过该土地 + stealingStatus = soilInfo[4].split('|') - stealingNumber += int(user[1]) + for isUser in stealingStatus: + user = isUser.split('-') + + if user[0] == uid: + isStealing = True + break + + stealingNumber -= int(user[1]) #如果偷过,则跳过该土地 if isStealing: continue - stealingNumber -= plantInfo['harvest'] + stealingNumber += plantInfo['harvest'] randomNumber = random.choice([1, 2]) randomNumber = min(randomNumber, stealingNumber) + logger.info(f"{randomNumber}") + if randomNumber > 0: plant[plantId] = plant.get(plantId, 0) + randomNumber harvestRecords.append(f"成功偷到作物:{plantId},数量为:{randomNumber}") @@ -569,14 +578,15 @@ class CFarmManager: await g_pSqlManager.updateUserPlantByUid(target, ','.join([f"{k}|{v}" for k, v in plant.items()])) userStealing[1] = int(userStealing[1]) - 1 + # 转换所有元素为字符串 + userStealing_str = [str(item) for item in userStealing] - sql = f"UPDATE user SET stealing = {'|'.join(userStealing)} WHERE uid = {uid}" + sql = f"UPDATE user SET stealing = {'|'.join(userStealing_str)} WHERE uid = {uid}" #更新用户每日偷取次数 await g_pSqlManager.executeDB(sql) return "\n".join(harvestRecords) - # @classmethod # async def reclamation(cls, uid: str) -> str: