🐛 修正作物阶段绘制错误的BUG
🐛 修复偷菜会导致偷自己的BUG
This commit is contained in:
+3
-3
@@ -95,7 +95,7 @@ class CPlantManager:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def getPlantPhaseByName(cls, name: str) -> list:
|
||||
async def getPlantPhaseByName(cls, name: str) -> list[int]:
|
||||
"""根据作物名称获取作物各个阶段
|
||||
|
||||
Args:
|
||||
@@ -119,8 +119,8 @@ class CPlantManager:
|
||||
result = []
|
||||
for x in phase:
|
||||
if x not in seen:
|
||||
seen.add(x)
|
||||
result.append(x)
|
||||
seen.add(int(x))
|
||||
result.append(int(x))
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
|
||||
+9
-12
@@ -1,5 +1,6 @@
|
||||
import math
|
||||
from typing import List, Union
|
||||
from unittest import result
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
@@ -18,7 +19,7 @@ class CUserDB(CSqlManager):
|
||||
"point": "INTEGER DEFAULT 0", #金币
|
||||
"vipPoint": "INTEGER DEFAULT 0", #点券
|
||||
"soil": "INTEGER DEFAULT 3", #解锁土地数量
|
||||
"stealTime": "TEXT DEFAULT NULL", #偷菜时间字符串
|
||||
"stealTime": "TEXT DEFAULT ''", #偷菜时间字符串
|
||||
"stealCount": "INTEGER DEFAULT 0" #剩余偷菜次数
|
||||
}
|
||||
await cls.ensureTableSchema("user", userInfo)
|
||||
@@ -98,17 +99,13 @@ class CUserDB(CSqlManager):
|
||||
async with cls.m_pDB.execute(
|
||||
"SELECT * FROM user WHERE uid = ?", (uid,)
|
||||
) as cursor:
|
||||
async for row in cursor:
|
||||
return {
|
||||
"uid": row[0],
|
||||
"name": row[1],
|
||||
"exp": row[2],
|
||||
"point": row[3],
|
||||
"soil": row[4],
|
||||
"stealTime": row[5] or "",
|
||||
"stealCount": int(row[6])
|
||||
}
|
||||
return {}
|
||||
row = await cursor.fetchone()
|
||||
if not row:
|
||||
return {}
|
||||
|
||||
result = dict(row)
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.warning("getUserInfoByUid 查询失败!", e=e)
|
||||
return {}
|
||||
|
||||
+16
-11
@@ -50,25 +50,30 @@ class CUserSoilDB(CSqlManager):
|
||||
if not plantInfo:
|
||||
return
|
||||
|
||||
currentTime = g_pToolManager.dateTime().now()
|
||||
matureTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['matureTime']))
|
||||
|
||||
phase = await g_pDBService.plant.getPlantPhaseNumberByName(soilInfo['plantName'])
|
||||
currentTime = g_pToolManager.dateTime().now().timestamp()
|
||||
phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo['plantName'])
|
||||
|
||||
if currentTime >= matureTime:
|
||||
if currentTime >= soilInfo['matureTime']:
|
||||
return
|
||||
|
||||
plantedTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['plantTime']))
|
||||
currentStage = 0
|
||||
elapsedTime = currentTime - soilInfo['plantTime']
|
||||
|
||||
elapsedTime = currentTime - plantedTime
|
||||
elapsedHour = elapsedTime.total_seconds() / 3600
|
||||
|
||||
currentStage = int(elapsedHour / (plantInfo['time'] / phase))
|
||||
for idx, thr in enumerate(phaseList, start=1):
|
||||
if elapsedTime < thr:
|
||||
currentStage = idx
|
||||
break
|
||||
|
||||
t = int(soilInfo['plantTime']) - phaseList[currentStage]
|
||||
s = int(soilInfo['matureTime']) - phaseList[currentStage]
|
||||
|
||||
await cls.updateUserSoil(uid, soilIndex, "plantTime", t)
|
||||
await cls.updateUserSoilFields(uid, soilIndex,
|
||||
{
|
||||
"plantTime": t,
|
||||
"matureTime": s
|
||||
})
|
||||
|
||||
logger.debug(f"当前阶段{currentStage}, 阶段时间{phaseList[currentStage]}, 播种时间{t}, 收获时间{s}")
|
||||
|
||||
@classmethod
|
||||
async def getUserFarmByUid(cls, uid: str) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user