diff --git a/README.md b/README.md index 1b42dc8..3662fa0 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ | 出售作物 [作物名称] [数量] | 从仓库里向系统售卖作物 | 不填写作物名将售卖仓库种全部作物 填作物名不填数量将指定作物全部出售 | | @美波理 偷菜 | 偷别人的菜 | 每人每天只能偷5次 | | 购买农场币 | 将真寻金币兑换成农场币 | 兑换比例默认为1:2 手续费默认20% | -| 更改农场名 [新的农场名] | 改名 | +| 更改农场名 [新的农场名] | 改名 | 农场名称无法存储特殊字符 | | 农场签到 | 签到 | 需要注意,该项会从服务器拉取签到数据 | --- @@ -80,12 +80,14 @@ - 新增签到功能(测试 - 新增农场详述功能,能通过该功能更加详细的观看农场数据 - 修复了迁移旧数据库无法正常迁移的BUG +- 修复了偷菜会导致偷自己的BUG +- 修正了作物阶段绘制不正确的BUG 代码方面 --- - 修正了多阶段作物成长素材计算逻辑 - 修正了作物数据库字段错乱的问题 -- 作物新增offset字段,用于以后偏移坐标(尚未加入代码 TODO +- 作物新增offset字段,用于以后偏移坐标和大小(尚未启用,该模式有商议 --- ## 待办事宜 `Todo` 列表 diff --git a/__init__.py b/__init__.py index ff68aba..1c40f66 100644 --- a/__init__.py +++ b/__init__.py @@ -92,10 +92,14 @@ async def shutdown(): await g_pDBService.cleanup() -@scheduler.add_job( +@scheduler.scheduled_job( trigger="cron", hour=0, minute=30, + id="signInFile" ) -async def _(): - await g_pJsonManager.initSignInFile() +async def signInFile(): + try: + await g_pJsonManager.initSignInFile() + except: + logger.info("农场签到文件下载失败!") diff --git a/command.py b/command.py index a024076..d5055a3 100644 --- a/command.py +++ b/command.py @@ -465,6 +465,10 @@ async def _(session: Uninfo, name: Match[str]): safeName = sanitize_username(name.result) + if safeName == "神秘农夫": + await MessageUtils.build_message("农场名不支持特殊符号!").send(reply_to=True) + return + result = await g_pDBService.user.updateUserNameByUid(uid, safeName) if result == True: diff --git a/database/plant.py b/database/plant.py index b562f9c..8ed48fb 100644 --- a/database/plant.py +++ b/database/plant.py @@ -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: diff --git a/database/user.py b/database/user.py index ea201d5..43ace85 100644 --- a/database/user.py +++ b/database/user.py @@ -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 {} diff --git a/database/userSoil.py b/database/userSoil.py index 3330b71..291d4d1 100644 --- a/database/userSoil.py +++ b/database/userSoil.py @@ -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: diff --git a/farm/farm.py b/farm/farm.py index d773344..5d6978d 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -220,7 +220,7 @@ class CFarmManager: if not planInfo: plantNumber = f"None" else: - plantNumber = f"{planInfo['harvest']}" + plantNumber = f"{planInfo['harvest'] - totalNumber}" dataList.append( [ @@ -272,8 +272,8 @@ class CFarmManager: plant = None soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex) - if not soilInfo or not soilInfo.get("plantName"): - return False, None, False #type: ignore + if not soilInfo: + return False, None, False, 0, 0 #type: ignore #是否枯萎 if int(soilInfo.get("wiltStatus", 0)) == 1: @@ -292,14 +292,12 @@ class CFarmManager: offsetW = plantInfo.get('officW', 0) offsetH = plantInfo.get('officH', 0) - 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: - plant = BuildImage(background = g_sResourcePath / f"plant/{soilInfo['plantName']}/{phase}.png") + if currentTime >= soilInfo['matureTime']: + plant = BuildImage(background = g_sResourcePath / f"plant/{soilInfo['plantName']}/{len(phaseList)}.png") return True, plant, True, offsetX, offsetY else: @@ -310,12 +308,13 @@ class CFarmManager: # return True, plant, False, offsetX, offsetY #如果没有成熟 则根据当前阶段进行绘制 - 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 if currentStage <= 0: if plantInfo['general'] == False: @@ -675,10 +674,10 @@ class CFarmManager: #用户信息 userInfo = await g_pDBService.user.getUserInfoByUid(uid) - stealTime = userInfo['stealTime'] + stealTime = userInfo.get('stealTime', "") stealCount = int(userInfo['stealCount']) - if stealTime == '': + if stealTime == "" or not stealTime: stealTime = g_pToolManager.dateTime().date().today().strftime('%Y-%m-%d') stealCount = 5 elif g_pToolManager.dateTime().date().fromisoformat(stealTime) != g_pToolManager.dateTime().date().today(): @@ -689,17 +688,17 @@ class CFarmManager: return "你今天可偷次数到达上限啦,手下留情吧" #获取用户解锁地块数量 - soilNumber = await g_pDBService.user.getUserSoilByUid(uid) + soilNumber = await g_pDBService.user.getUserSoilByUid(target) harvestRecords: List[str] = [] isStealingNumber = 0 isStealingPlant = 0 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 - soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i) + soilInfo = await g_pDBService.userSoil.getUserSoil(target, i) if not soilInfo: continue diff --git a/log/log.md b/log/log.md index 27560ff..f2c2218 100644 --- a/log/log.md +++ b/log/log.md @@ -7,12 +7,14 @@ - 新增签到功能(测试 - 新增农场详述功能,能通过该功能更加详细的观看农场数据 - 修复了迁移旧数据库无法正常迁移的BUG +- 修复了偷菜会导致偷自己的BUG +- 修正了作物阶段绘制不正确的BUG 代码方面 --- - 修正了多阶段作物成长素材计算逻辑 - 修正了作物数据库字段错乱的问题 -- 作物新增offset字段,用于以后偏移坐标 +- 作物新增offset字段,用于以后偏移坐标和大小(尚未启用,该模式有商议 ## V1.3 用户方面 diff --git a/resource/plant/水稻/0.png b/resource/plant/水稻/0.png deleted file mode 100644 index 3e4c81e..0000000 Binary files a/resource/plant/水稻/0.png and /dev/null differ diff --git a/resource/plant/水稻/1.png b/resource/plant/水稻/1.png index 60f5139..3e4c81e 100644 Binary files a/resource/plant/水稻/1.png and b/resource/plant/水稻/1.png differ diff --git a/resource/plant/水稻/2.png b/resource/plant/水稻/2.png index f7e4230..60f5139 100644 Binary files a/resource/plant/水稻/2.png and b/resource/plant/水稻/2.png differ diff --git a/resource/plant/水稻/3.png b/resource/plant/水稻/3.png index d0185c0..f7e4230 100644 Binary files a/resource/plant/水稻/3.png and b/resource/plant/水稻/3.png differ diff --git a/resource/plant/水稻/4.png b/resource/plant/水稻/4.png index 9f7f0c2..d0185c0 100644 Binary files a/resource/plant/水稻/4.png and b/resource/plant/水稻/4.png differ diff --git a/resource/plant/水稻/5.png b/resource/plant/水稻/5.png new file mode 100644 index 0000000..9f7f0c2 Binary files /dev/null and b/resource/plant/水稻/5.png differ diff --git a/resource/plant/香粽龙舟/0.png b/resource/plant/香粽龙舟/0.png deleted file mode 100644 index 2feafb4..0000000 Binary files a/resource/plant/香粽龙舟/0.png and /dev/null differ diff --git a/resource/plant/香粽龙舟/1.png b/resource/plant/香粽龙舟/1.png index 64b9a2a..2feafb4 100644 Binary files a/resource/plant/香粽龙舟/1.png and b/resource/plant/香粽龙舟/1.png differ diff --git a/resource/plant/香粽龙舟/2.png b/resource/plant/香粽龙舟/2.png index e090a79..64b9a2a 100644 Binary files a/resource/plant/香粽龙舟/2.png and b/resource/plant/香粽龙舟/2.png differ diff --git a/resource/plant/香粽龙舟/3.png b/resource/plant/香粽龙舟/3.png index 8619dec..e090a79 100644 Binary files a/resource/plant/香粽龙舟/3.png and b/resource/plant/香粽龙舟/3.png differ diff --git a/resource/plant/香粽龙舟/4.png b/resource/plant/香粽龙舟/4.png index f857a33..8619dec 100644 Binary files a/resource/plant/香粽龙舟/4.png and b/resource/plant/香粽龙舟/4.png differ diff --git a/resource/plant/香粽龙舟/5.png b/resource/plant/香粽龙舟/5.png new file mode 100644 index 0000000..f857a33 Binary files /dev/null and b/resource/plant/香粽龙舟/5.png differ