🐛 解决了BUG,但是忘了解决啥了
This commit is contained in:
parent
b1f25f1268
commit
f85ab9758c
40
command.py
40
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(
|
||||
|
||||
@ -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},"
|
||||
|
||||
50
farm/farm.py
50
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:
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user