🐛 解决了BUG,但是忘了解决啥了

This commit is contained in:
Art_Sakura 2025-03-23 23:41:27 +08:00
parent b1f25f1268
commit f85ab9758c
3 changed files with 51 additions and 41 deletions

View File

@ -43,7 +43,7 @@ diuse_farm = on_alconna(
Subcommand("harvest", help_text="收获"), Subcommand("harvest", help_text="收获"),
Subcommand("eradicate", help_text="铲除"), Subcommand("eradicate", help_text="铲除"),
Subcommand("my-plant", 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("sell-plant", Args["name?", str]["num?", int], help_text="出售作物"),
Subcommand("stealing", Args["target?", At], help_text="偷菜"), Subcommand("stealing", Args["target?", At], help_text="偷菜"),
Subcommand("buy-point", Args["num?", int], help_text="购买农场币"), Subcommand("buy-point", Args["num?", int], help_text="购买农场币"),
@ -228,31 +228,31 @@ async def _(session: Uninfo):
result = await g_pFarmManager.getUserPlantByUid(uid) result = await g_pFarmManager.getUserPlantByUid(uid)
await MessageUtils.build_message(result).send(reply_to=True) await MessageUtils.build_message(result).send(reply_to=True)
# diuse_farm.shortcut( diuse_farm.shortcut(
# "开垦", "开垦",
# command="我的农场", command="我的农场",
# arguments=["reclamation"], arguments=["reclamation"],
# prefix=True, prefix=True,
# ) )
# @diuse_farm.assign("reclamation") @diuse_farm.assign("reclamation")
# async def _(session: Uninfo): async def _(session: Uninfo):
# uid = str(session.user.id) uid = str(session.user.id)
# point = await g_pSqlManager.getUserPointByUid(uid) point = await g_pSqlManager.getUserPointByUid(uid)
# if point < 0: if point < 0:
# await MessageUtils.build_message("尚未开通农场快at我发送 开通农场 开通吧").send() await MessageUtils.build_message("尚未开通农场快at我发送 开通农场 开通吧").send()
# return None return None
# result = await g_pFarmManager.getUserPlantByUid(uid) result = await g_pFarmManager.getUserPlantByUid(uid)
# await MessageUtils.build_message(result).send(reply_to=True) 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") @diuse_farm.got_path("test", "测试一下")
# async def _(session: Uninfo, flag: str = ArgStr("flag")): async def _(name: str):
# await MessageUtils.build_message("测试一下").send(reply_to=True) await MessageUtils.build_message(name).send(reply_to=True)
diuse_farm.shortcut( diuse_farm.shortcut(

View File

@ -375,7 +375,7 @@ class CSqlManager:
plantInfo = g_pJsonManager.m_pPlant['plant'][plant] # type: ignore plantInfo = g_pJsonManager.m_pPlant['plant'][plant] # type: ignore
currentTime = datetime.now() currentTime = datetime.now()
newTime = currentTime + timedelta(minutes=int(plantInfo['time'])) newTime = currentTime + timedelta(hours=int(plantInfo['time']))
#种子名称种下时间预计成熟时间地状态0无 1长草 2生虫 3缺水 4枯萎是否被偷 示例QQ号-偷取数量|QQ号-偷取数量 #种子名称种下时间预计成熟时间地状态0无 1长草 2生虫 3缺水 4枯萎是否被偷 示例QQ号-偷取数量|QQ号-偷取数量
s = f"{plant},{int(currentTime.timestamp())},{int(newTime.timestamp())},{status}," s = f"{plant},{int(currentTime.timestamp())},{int(newTime.timestamp())},{status},"

View File

@ -276,15 +276,19 @@ class CFarmManager:
# 更新数据库 # 更新数据库
await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soilName, name) await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soilName, name)
await g_pSqlManager.updateUserSeedByUid( str = ""
uid,
','.join([f"{k}|{v}" for k, v in plantDict.items()])
)
if num > 0: if num > 0:
return f"播种数量超出开垦土地数量,已将可播种土地成功播种{name}!仓库还剩下{plantDict[name]}个种子" str = f"播种数量超出开垦土地数量,已将可播种土地成功播种{name}!仓库还剩下{plantDict[name]}个种子"
else: 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 @classmethod
async def harvest(cls, uid: str) -> str: async def harvest(cls, uid: str) -> str:
@ -513,11 +517,11 @@ class CFarmManager:
for (soilName, (status, info)) in zip(soilNames, soilStatuses): for (soilName, (status, info)) in zip(soilNames, soilStatuses):
isStealing = False isStealing = False
if len(info) < 0: if not info:
continue continue
soilInfo = info.split(',') soilInfo = info.split(',')
if soilInfo[3] == 4: if int(soilInfo[3]) == 4:
continue continue
plantId = soilInfo[0] plantId = soilInfo[0]
@ -526,28 +530,33 @@ class CFarmManager:
currentTime = datetime.now() currentTime = datetime.now()
matureTime = datetime.fromtimestamp(int(soilInfo[2])) matureTime = datetime.fromtimestamp(int(soilInfo[2]))
stealingStatus: list[str] = []
stealingNumber = 0 stealingNumber = 0
if currentTime >= matureTime: if currentTime >= matureTime:
#先获取用户是否偷过该土地
stealingStatus = soilInfo[4].split('|')
for isUser in stealingStatus:
user = isUser.split('-')
if user[0] == uid: if soilInfo[4]:
isStealing = True #先获取用户是否偷过该土地
break 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: if isStealing:
continue continue
stealingNumber -= plantInfo['harvest'] stealingNumber += plantInfo['harvest']
randomNumber = random.choice([1, 2]) randomNumber = random.choice([1, 2])
randomNumber = min(randomNumber, stealingNumber) randomNumber = min(randomNumber, stealingNumber)
logger.info(f"{randomNumber}")
if randomNumber > 0: if randomNumber > 0:
plant[plantId] = plant.get(plantId, 0) + randomNumber plant[plantId] = plant.get(plantId, 0) + randomNumber
harvestRecords.append(f"成功偷到作物:{plantId},数量为:{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()])) await g_pSqlManager.updateUserPlantByUid(target, ','.join([f"{k}|{v}" for k, v in plant.items()]))
userStealing[1] = int(userStealing[1]) - 1 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) await g_pSqlManager.executeDB(sql)
return "\n".join(harvestRecords) return "\n".join(harvestRecords)
# @classmethod # @classmethod
# async def reclamation(cls, uid: str) -> str: # async def reclamation(cls, uid: str) -> str: