🐛 修正作物阶段绘制错误的BUG

🐛 修复偷菜会导致偷自己的BUG
This commit is contained in:
Art_Sakura 2025-05-30 11:22:32 +08:00
parent 1ef506d2fd
commit db294e6998
20 changed files with 64 additions and 51 deletions

View File

@ -68,7 +68,7 @@
| 出售作物 [作物名称] [数量] | 从仓库里向系统售卖作物 | 不填写作物名将售卖仓库种全部作物 填作物名不填数量将指定作物全部出售 | | 出售作物 [作物名称] [数量] | 从仓库里向系统售卖作物 | 不填写作物名将售卖仓库种全部作物 填作物名不填数量将指定作物全部出售 |
| @美波理 偷菜 | 偷别人的菜 | 每人每天只能偷5次 | | @美波理 偷菜 | 偷别人的菜 | 每人每天只能偷5次 |
| 购买农场币 | 将真寻金币兑换成农场币 | 兑换比例默认为1:2 手续费默认20% | | 购买农场币 | 将真寻金币兑换成农场币 | 兑换比例默认为1:2 手续费默认20% |
| 更改农场名 [新的农场名] | 改名 | | 更改农场名 [新的农场名] | 改名 | 农场名称无法存储特殊字符 |
| 农场签到 | 签到 | 需要注意,该项会从服务器拉取签到数据 | | 农场签到 | 签到 | 需要注意,该项会从服务器拉取签到数据 |
--- ---
@ -80,12 +80,14 @@
- 新增签到功能(测试 - 新增签到功能(测试
- 新增农场详述功能,能通过该功能更加详细的观看农场数据 - 新增农场详述功能,能通过该功能更加详细的观看农场数据
- 修复了迁移旧数据库无法正常迁移的BUG - 修复了迁移旧数据库无法正常迁移的BUG
- 修复了偷菜会导致偷自己的BUG
- 修正了作物阶段绘制不正确的BUG
代码方面 代码方面
--- ---
- 修正了多阶段作物成长素材计算逻辑 - 修正了多阶段作物成长素材计算逻辑
- 修正了作物数据库字段错乱的问题 - 修正了作物数据库字段错乱的问题
- 作物新增offset字段用于以后偏移坐标(尚未加入代码 TODO - 作物新增offset字段用于以后偏移坐标和大小(尚未启用,该模式有商议
--- ---
## 待办事宜 `Todo` 列表 ## 待办事宜 `Todo` 列表

View File

@ -92,10 +92,14 @@ async def shutdown():
await g_pDBService.cleanup() await g_pDBService.cleanup()
@scheduler.add_job( @scheduler.scheduled_job(
trigger="cron", trigger="cron",
hour=0, hour=0,
minute=30, minute=30,
id="signInFile"
) )
async def _(): async def signInFile():
await g_pJsonManager.initSignInFile() try:
await g_pJsonManager.initSignInFile()
except:
logger.info("农场签到文件下载失败!")

View File

@ -465,6 +465,10 @@ async def _(session: Uninfo, name: Match[str]):
safeName = sanitize_username(name.result) safeName = sanitize_username(name.result)
if safeName == "神秘农夫":
await MessageUtils.build_message("农场名不支持特殊符号!").send(reply_to=True)
return
result = await g_pDBService.user.updateUserNameByUid(uid, safeName) result = await g_pDBService.user.updateUserNameByUid(uid, safeName)
if result == True: if result == True:

View File

@ -95,7 +95,7 @@ class CPlantManager:
return None return None
@classmethod @classmethod
async def getPlantPhaseByName(cls, name: str) -> list: async def getPlantPhaseByName(cls, name: str) -> list[int]:
"""根据作物名称获取作物各个阶段 """根据作物名称获取作物各个阶段
Args: Args:
@ -119,8 +119,8 @@ class CPlantManager:
result = [] result = []
for x in phase: for x in phase:
if x not in seen: if x not in seen:
seen.add(x) seen.add(int(x))
result.append(x) result.append(int(x))
return result return result
except Exception as e: except Exception as e:

View File

@ -1,5 +1,6 @@
import math import math
from typing import List, Union from typing import List, Union
from unittest import result
from zhenxun.services.log import logger from zhenxun.services.log import logger
@ -18,7 +19,7 @@ class CUserDB(CSqlManager):
"point": "INTEGER DEFAULT 0", #金币 "point": "INTEGER DEFAULT 0", #金币
"vipPoint": "INTEGER DEFAULT 0", #点券 "vipPoint": "INTEGER DEFAULT 0", #点券
"soil": "INTEGER DEFAULT 3", #解锁土地数量 "soil": "INTEGER DEFAULT 3", #解锁土地数量
"stealTime": "TEXT DEFAULT NULL", #偷菜时间字符串 "stealTime": "TEXT DEFAULT ''", #偷菜时间字符串
"stealCount": "INTEGER DEFAULT 0" #剩余偷菜次数 "stealCount": "INTEGER DEFAULT 0" #剩余偷菜次数
} }
await cls.ensureTableSchema("user", userInfo) await cls.ensureTableSchema("user", userInfo)
@ -98,17 +99,13 @@ class CUserDB(CSqlManager):
async with cls.m_pDB.execute( async with cls.m_pDB.execute(
"SELECT * FROM user WHERE uid = ?", (uid,) "SELECT * FROM user WHERE uid = ?", (uid,)
) as cursor: ) as cursor:
async for row in cursor: row = await cursor.fetchone()
return { if not row:
"uid": row[0], return {}
"name": row[1],
"exp": row[2], result = dict(row)
"point": row[3],
"soil": row[4], return result
"stealTime": row[5] or "",
"stealCount": int(row[6])
}
return {}
except Exception as e: except Exception as e:
logger.warning("getUserInfoByUid 查询失败!", e=e) logger.warning("getUserInfoByUid 查询失败!", e=e)
return {} return {}

View File

@ -50,25 +50,30 @@ class CUserSoilDB(CSqlManager):
if not plantInfo: if not plantInfo:
return return
currentTime = g_pToolManager.dateTime().now() currentTime = g_pToolManager.dateTime().now().timestamp()
matureTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['matureTime']))
phase = await g_pDBService.plant.getPlantPhaseNumberByName(soilInfo['plantName'])
phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo['plantName']) phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo['plantName'])
if currentTime >= matureTime: if currentTime >= soilInfo['matureTime']:
return return
plantedTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['plantTime'])) currentStage = 0
elapsedTime = currentTime - soilInfo['plantTime']
elapsedTime = currentTime - plantedTime for idx, thr in enumerate(phaseList, start=1):
elapsedHour = elapsedTime.total_seconds() / 3600 if elapsedTime < thr:
currentStage = idx
currentStage = int(elapsedHour / (plantInfo['time'] / phase)) break
t = int(soilInfo['plantTime']) - phaseList[currentStage] 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 @classmethod
async def getUserFarmByUid(cls, uid: str) -> dict: async def getUserFarmByUid(cls, uid: str) -> dict:

View File

@ -220,7 +220,7 @@ class CFarmManager:
if not planInfo: if not planInfo:
plantNumber = f"None" plantNumber = f"None"
else: else:
plantNumber = f"{planInfo['harvest']}" plantNumber = f"{planInfo['harvest'] - totalNumber}"
dataList.append( dataList.append(
[ [
@ -272,8 +272,8 @@ class CFarmManager:
plant = None plant = None
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex) soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
if not soilInfo or not soilInfo.get("plantName"): if not soilInfo:
return False, None, False #type: ignore return False, None, False, 0, 0 #type: ignore
#是否枯萎 #是否枯萎
if int(soilInfo.get("wiltStatus", 0)) == 1: if int(soilInfo.get("wiltStatus", 0)) == 1:
@ -292,14 +292,12 @@ class CFarmManager:
offsetW = plantInfo.get('officW', 0) offsetW = plantInfo.get('officW', 0)
offsetH = plantInfo.get('officH', 0) offsetH = plantInfo.get('officH', 0)
currentTime = g_pToolManager.dateTime().now() currentTime = g_pToolManager.dateTime().now().timestamp()
matureTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['matureTime'])) phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo['plantName'])
phase = await g_pDBService.plant.getPlantPhaseNumberByName(soilInfo['plantName'])
#如果当前时间大于成熟时间 说明作物成熟 #如果当前时间大于成熟时间 说明作物成熟
if currentTime >= matureTime: if currentTime >= soilInfo['matureTime']:
plant = BuildImage(background = g_sResourcePath / f"plant/{soilInfo['plantName']}/{phase}.png") plant = BuildImage(background = g_sResourcePath / f"plant/{soilInfo['plantName']}/{len(phaseList)}.png")
return True, plant, True, offsetX, offsetY return True, plant, True, offsetX, offsetY
else: else:
@ -310,12 +308,13 @@ class CFarmManager:
# return True, plant, False, offsetX, offsetY # return True, plant, False, offsetX, offsetY
#如果没有成熟 则根据当前阶段进行绘制 #如果没有成熟 则根据当前阶段进行绘制
plantedTime = g_pToolManager.dateTime().fromtimestamp(int(soilInfo['plantTime'])) currentStage = 0
elapsedTime = currentTime - soilInfo['plantTime']
elapsedTime = currentTime - plantedTime for idx, thr in enumerate(phaseList, start=1):
elapsedHour = elapsedTime.total_seconds() / 3600 if elapsedTime < thr:
currentStage = idx
currentStage = int(elapsedHour / (plantInfo['time'] / phase)) break
if currentStage <= 0: if currentStage <= 0:
if plantInfo['general'] == False: if plantInfo['general'] == False:
@ -675,10 +674,10 @@ class CFarmManager:
#用户信息 #用户信息
userInfo = await g_pDBService.user.getUserInfoByUid(uid) userInfo = await g_pDBService.user.getUserInfoByUid(uid)
stealTime = userInfo['stealTime'] stealTime = userInfo.get('stealTime', "")
stealCount = int(userInfo['stealCount']) stealCount = int(userInfo['stealCount'])
if stealTime == '': if stealTime == "" or not stealTime:
stealTime = g_pToolManager.dateTime().date().today().strftime('%Y-%m-%d') stealTime = g_pToolManager.dateTime().date().today().strftime('%Y-%m-%d')
stealCount = 5 stealCount = 5
elif g_pToolManager.dateTime().date().fromisoformat(stealTime) != g_pToolManager.dateTime().date().today(): elif g_pToolManager.dateTime().date().fromisoformat(stealTime) != g_pToolManager.dateTime().date().today():
@ -689,17 +688,17 @@ class CFarmManager:
return "你今天可偷次数到达上限啦,手下留情吧" return "你今天可偷次数到达上限啦,手下留情吧"
#获取用户解锁地块数量 #获取用户解锁地块数量
soilNumber = await g_pDBService.user.getUserSoilByUid(uid) soilNumber = await g_pDBService.user.getUserSoilByUid(target)
harvestRecords: List[str] = [] harvestRecords: List[str] = []
isStealingNumber = 0 isStealingNumber = 0
isStealingPlant = 0 isStealingPlant = 0
for i in range(1, soilNumber + 1): for i in range(1, soilNumber + 1):
#如果没有种植 #如果没有种植
if not await g_pDBService.userSoil.isSoilPlanted(uid, i): if not await g_pDBService.userSoil.isSoilPlanted(target, i):
continue continue
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i) soilInfo = await g_pDBService.userSoil.getUserSoil(target, i)
if not soilInfo: if not soilInfo:
continue continue

View File

@ -7,12 +7,14 @@
- 新增签到功能(测试 - 新增签到功能(测试
- 新增农场详述功能,能通过该功能更加详细的观看农场数据 - 新增农场详述功能,能通过该功能更加详细的观看农场数据
- 修复了迁移旧数据库无法正常迁移的BUG - 修复了迁移旧数据库无法正常迁移的BUG
- 修复了偷菜会导致偷自己的BUG
- 修正了作物阶段绘制不正确的BUG
代码方面 代码方面
--- ---
- 修正了多阶段作物成长素材计算逻辑 - 修正了多阶段作物成长素材计算逻辑
- 修正了作物数据库字段错乱的问题 - 修正了作物数据库字段错乱的问题
- 作物新增offset字段用于以后偏移坐标 - 作物新增offset字段用于以后偏移坐标和大小(尚未启用,该模式有商议
## V1.3 ## V1.3
用户方面 用户方面

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 17 KiB

BIN
resource/plant/水稻/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB