🚑 修复了用户不能正常偷菜、收菜的问题
This commit is contained in:
parent
43b2184597
commit
16c801bcb6
@ -295,7 +295,7 @@ async def _(session: Uninfo, target: Match[At]):
|
|||||||
point = await g_pSqlManager.getUserPointByUid(tar.target)
|
point = await g_pSqlManager.getUserPointByUid(tar.target)
|
||||||
|
|
||||||
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.stealing(uid, tar.target)
|
result = await g_pFarmManager.stealing(uid, tar.target)
|
||||||
|
|||||||
130
farm/farm.py
130
farm/farm.py
@ -301,7 +301,7 @@ class CFarmManager:
|
|||||||
|
|
||||||
plant = {}
|
plant = {}
|
||||||
|
|
||||||
soilNames = [f"soil{i}" for i in range(soilUnlock)]
|
soilNames = [f"soil{i + 1}" for i in range(soilUnlock)]
|
||||||
soilStatuses = await asyncio.gather(*[
|
soilStatuses = await asyncio.gather(*[
|
||||||
g_pSqlManager.getUserSoilStatusBySoilID(uid, name)
|
g_pSqlManager.getUserSoilStatusBySoilID(uid, name)
|
||||||
for name in soilNames
|
for name in soilNames
|
||||||
@ -312,30 +312,35 @@ class CFarmManager:
|
|||||||
experience = 0
|
experience = 0
|
||||||
|
|
||||||
for (soil_name, (status, info)) in zip(soilNames, soilStatuses):
|
for (soil_name, (status, info)) in zip(soilNames, soilStatuses):
|
||||||
if not status:
|
if len(info) <= 0:
|
||||||
soilInfo = info.split(',')
|
continue
|
||||||
plantId = soilInfo[0]
|
|
||||||
plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore
|
|
||||||
|
|
||||||
currentTime = datetime.now()
|
soilInfo = info.split(',')
|
||||||
matureTime = datetime.fromtimestamp(int(soilInfo[2]))
|
if soilInfo[3] == 4:
|
||||||
|
continue
|
||||||
|
|
||||||
if currentTime >= matureTime:
|
plantId = soilInfo[0]
|
||||||
number = plantInfo['harvest']
|
plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore
|
||||||
|
|
||||||
#判断该土地作物是否被透过
|
currentTime = datetime.now()
|
||||||
if len(soilInfo[4]) > 0:
|
matureTime = datetime.fromtimestamp(int(soilInfo[2]))
|
||||||
stealingStatus = soilInfo[4].split('|')
|
|
||||||
for isUser in stealingStatus:
|
|
||||||
user = isUser.split('-')
|
|
||||||
number -= user[1]
|
|
||||||
|
|
||||||
plant[plantId] = plant.get(plantId, 0) + number
|
if currentTime >= matureTime:
|
||||||
experience += plantInfo['experience']
|
number = plantInfo['harvest']
|
||||||
harvestRecords.append(f"收获作物:{plantId},数量为:{number},经验为:{plantInfo['experience']}")
|
|
||||||
|
|
||||||
#批量更新数据库操作
|
#判断该土地作物是否被透过
|
||||||
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:
|
if experience > 0:
|
||||||
harvestRecords.append(f"\t累计获得经验:{experience}")
|
harvestRecords.append(f"\t累计获得经验:{experience}")
|
||||||
@ -495,7 +500,7 @@ class CFarmManager:
|
|||||||
plant = {}
|
plant = {}
|
||||||
|
|
||||||
#根据解锁土地,获取每块土地状态信息
|
#根据解锁土地,获取每块土地状态信息
|
||||||
soilNames = [f"soil{i}" for i in range(soilUnlock)]
|
soilNames = [f"soil{i + 1}" for i in range(soilUnlock)]
|
||||||
soilStatuses = await asyncio.gather(*[
|
soilStatuses = await asyncio.gather(*[
|
||||||
g_pSqlManager.getUserSoilStatusBySoilID(target, name)
|
g_pSqlManager.getUserSoilStatusBySoilID(target, name)
|
||||||
for name in soilNames
|
for name in soilNames
|
||||||
@ -508,53 +513,54 @@ class CFarmManager:
|
|||||||
for (soilName, (status, info)) in zip(soilNames, soilStatuses):
|
for (soilName, (status, info)) in zip(soilNames, soilStatuses):
|
||||||
isStealing = False
|
isStealing = False
|
||||||
|
|
||||||
if not info:
|
if len(info) < 0:
|
||||||
soilInfo = info.split(',')
|
continue
|
||||||
if soilInfo[3] == 4:
|
|
||||||
|
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
|
continue
|
||||||
|
|
||||||
plantId = soilInfo[0]
|
stealingNumber -= plantInfo['harvest']
|
||||||
plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore
|
randomNumber = random.choice([1, 2])
|
||||||
|
randomNumber = min(randomNumber, stealingNumber)
|
||||||
|
|
||||||
currentTime = datetime.now()
|
if randomNumber > 0:
|
||||||
matureTime = datetime.fromtimestamp(int(soilInfo[2]))
|
plant[plantId] = plant.get(plantId, 0) + randomNumber
|
||||||
|
harvestRecords.append(f"成功偷到作物:{plantId},数量为:{randomNumber}")
|
||||||
|
|
||||||
stealingNumber = 0
|
stealingStatus.append(f"|{uid}-{randomNumber}")
|
||||||
|
|
||||||
if currentTime >= matureTime:
|
#如果将作物偷完,就直接更新状态 并记录用户偷取过
|
||||||
#先获取用户是否偷过该土地
|
if plantInfo['harvest'] - randomNumber + stealingNumber == 0:
|
||||||
stealingStatus = soilInfo[4].split('|')
|
sql = f"UPDATE soil SET {soilName} = ',,,4,{stealingStatus}' WHERE uid = '{target}'"
|
||||||
for isUser in stealingStatus:
|
else:
|
||||||
user = isUser.split('-')
|
sql = f"UPDATE soil SET {soilName} = '{soilInfo[0]},{soilInfo[1]},{soilInfo[2]},{soilInfo[3]},{stealingStatus}' WHERE uid = '{target}'"
|
||||||
|
|
||||||
if user[0] == uid:
|
await g_pSqlManager.executeDB(sql)
|
||||||
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)
|
|
||||||
|
|
||||||
if not plant:
|
if not plant:
|
||||||
return "目标没有作物可以被偷"
|
return "目标没有作物可以被偷"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user