新增多阶段作物特性

🐛 修复偷菜BUG
📝 新增部分作物
This commit is contained in:
Art_Sakura 2025-05-09 18:20:00 +08:00
parent 55394e3590
commit ff5b446b52
97 changed files with 111 additions and 52 deletions

View File

@ -135,7 +135,7 @@ class CPlantManager:
async def listPlants(cls) -> list[dict]:
"""查询所有作物记录"""
try:
async with cls.m_pDB.execute("SELECT * FROM plant") as cursor:
async with cls.m_pDB.execute("SELECT * FROM plant ORDER BY level") as cursor:
rows = await cursor.fetchall()
return [dict(r) for r in rows]
except Exception as e:

View File

@ -11,13 +11,13 @@ class CUserDB(CSqlManager):
@classmethod
async def initDB(cls):
"""初始化用户表结构确保user表存在且字段完整"""
# 用户Uid
# 农场名称
# 经验值
# 金币
# 解锁土地数量
# 偷菜时间字符串
# 剩余偷菜次数
#uid: 用户Uid
#name: 农场名称
#exp: 经验值
#point: 金币
#soil: 解锁土地数量
#stealTime: 偷菜时间字符串
#stealCount: 剩余偷菜次数
userInfo = {
"uid": "INTEGER PRIMARY KEY AUTOINCREMENT",
"name": "TEXT NOT NULL",

View File

@ -11,17 +11,18 @@ from .database import CSqlManager
class CUserSoilDB(CSqlManager):
@classmethod
async def initDB(cls):
# 用户Uid
# 地块索引从1开始
# 作物名称
# 播种时间
# 成熟时间
# 土地等级 0=普通地1=红土地2=黑土地3=金土地
# 枯萎状态 0=未枯萎1=枯萎
# 施肥状态 0=未施肥1=施肥
# 虫害状态 0=无虫害1=有虫害
# 杂草状态 0=无杂草1=有杂草
# 缺水状态 0=不缺水1=缺水
#uid: 用户Uid
#soilIndex: 地块索引从1开始
#plantName: 作物名称
#plantTime: 播种时间
#matureTime: 成熟时间
#soilLevel: 土地等级 0=普通地1=红土地2=黑土地3=金土地
#wiltStatus: 枯萎状态 0=未枯萎1=枯萎
#fertilizerStatus: 施肥状态 0=未施肥1=施肥
#bugStatus: 虫害状态 0=无虫害1=有虫害
#weedStatus: 杂草状态 0=无杂草1=有杂草
#waterStatus: 缺水状态 0=不缺水1=缺水
#harvestCount: 收获次数
userSoil = {
"uid": "TEXT NOT NULL",
"soilIndex": "INTEGER NOT NULL",
@ -34,6 +35,7 @@ class CUserSoilDB(CSqlManager):
"bugStatus": "INTEGER DEFAULT 0",
"weedStatus": "INTEGER DEFAULT 0",
"waterStatus": "INTEGER DEFAULT 0",
"harvestCount": "INTEGER DEFAULT 0",
"PRIMARY KEY": "(uid, soilIndex)",
}
@ -64,7 +66,7 @@ class CUserSoilDB(CSqlManager):
Returns:
bool: 如果旧表不存在则返回 False否则迁移并删除后返回 True
"""
# 检查旧表是否存在
#检查旧表是否存在
cursor = await cls.m_pDB.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='soil'"
)
@ -89,8 +91,12 @@ class CUserSoilDB(CSqlManager):
mt = int(parts[2])
await cls.m_pDB.execute(
"INSERT INTO userSoil (uid,soilIndex,plantName,plantTime,matureTime) VALUES (?,?,?,?,?)",
(uid, i, name, pt, mt),
"""
INSERT INTO userSoil
(uid,soilIndex,plantName,plantTime,matureTime,harvestCount,)
VALUES (?,?,?,?,?,?)
""",
(uid, i, name, pt, mt, 0),
)
await cls.m_pDB.execute("DROP TABLE soil")
@ -108,7 +114,13 @@ class CUserSoilDB(CSqlManager):
"""
async with cls._transaction():
await cls.m_pDB.execute(
"INSERT INTO userSoil (uid, soilIndex, plantName, plantTime, matureTime, soilLevel, fertilizerStatus, bugStatus, weedStatus, waterStatus) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"""
INSERT INTO userSoil
(uid, soilIndex, plantName, plantTime, matureTime,
soilLevel, wiltStatus, fertilizerStatus, bugStatus,
weedStatus, waterStatus, harvestCount)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
""",
(
soilInfo["uid"],
soilInfo["soilIndex"],
@ -116,10 +128,12 @@ class CUserSoilDB(CSqlManager):
soilInfo.get("plantTime", 0),
soilInfo.get("matureTime", 0),
soilInfo.get("soilLevel", 0),
soilInfo.get("wiltStatus", 0),
soilInfo.get("fertilizerStatus", 0),
soilInfo.get("bugStatus", 0),
soilInfo.get("weedStatus", 0),
soilInfo.get("waterStatus", 0),
soilInfo.get("harvestCount", 0),
),
)
@ -134,7 +148,13 @@ class CUserSoilDB(CSqlManager):
None
"""
await cls.m_pDB.execute(
"INSERT INTO userSoil (uid, soilIndex, plantName, plantTime, matureTime, soilLevel, fertilizerStatus, bugStatus, weedStatus, waterStatus) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"""
INSERT INTO userSoil
(uid, soilIndex, plantName, plantTime, matureTime,
soilLevel, wiltStatus, fertilizerStatus, bugStatus,
weedStatus, waterStatus, harvestCount)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
""",
(
soilInfo["uid"],
soilInfo["soilIndex"],
@ -142,10 +162,12 @@ class CUserSoilDB(CSqlManager):
soilInfo.get("plantTime", 0),
soilInfo.get("matureTime", 0),
soilInfo.get("soilLevel", 0),
soilInfo.get("wiltStatus", 0),
soilInfo.get("fertilizerStatus", 0),
soilInfo.get("bugStatus", 0),
soilInfo.get("weedStatus", 0),
soilInfo.get("waterStatus", 0),
soilInfo.get("harvestCount", 0),
),
)
@ -289,12 +311,12 @@ class CUserSoilDB(CSqlManager):
Returns:
bool: 播种成功返回 True否则返回 False
"""
# 校验土地区是否已种植
#校验土地区是否已种植
soilRecord = await cls.getUserSoil(uid, soilIndex)
if soilRecord and soilRecord.get("plantName"):
return False
# 获取植物配置
#获取植物配置
plantCfg = await g_pDBService.plant.getPlantByName(plantName)
if not plantCfg:
logger.error(f"未知植物: {plantName}")
@ -305,7 +327,6 @@ class CUserSoilDB(CSqlManager):
try:
async with cls._transaction():
# 复用原有记录字段,保留土壤状态等信息
prev = soilRecord or {}
await cls._deleteUserSoil(uid, soilIndex)
await cls._insertUserSoil(
@ -315,13 +336,13 @@ class CUserSoilDB(CSqlManager):
"plantName": plantName,
"plantTime": nowTs,
"matureTime": matureTs,
# 保留之前的土壤等级和状态字段,避免数据丢失
"soilLevel": prev.get("soilLevel", 0),
"wiltStatus": prev.get("wiltStatus", 0),
"fertilizerStatus": prev.get("fertilizerStatus", 0),
"bugStatus": prev.get("bugStatus", 0),
"weedStatus": prev.get("weedStatus", 0),
"waterStatus": prev.get("waterStatus", 0),
"harvestCount": 0
}
)
return True

View File

@ -6,11 +6,11 @@ from .database import CSqlManager
class CUserStealDB(CSqlManager):
@classmethod
async def initDB(cls):
# 被偷用户Uid
# 被偷的地块索引 从1开始
# 偷菜用户Uid
# 被偷数量
# 被偷时间
#uid: 被偷用户Uid
#soilIndex: 被偷的地块索引 从1开始
#stealerUid: 偷菜用户Uid
#stealCount: 被偷数量
#stealTime: 被偷时间
userSteal = {
"uid": "TEXT NOT NULL",
"soilIndex": "INTEGER NOT NULL",
@ -205,13 +205,12 @@ class CUserStealDB(CSqlManager):
return False
@classmethod
async def deleteStealRecord(cls, uid: str, soilIndex: int, stealerUid: str) -> bool:
"""删除指定偷菜记录
async def deleteStealRecord(cls, uid: str, soilIndex: int) -> bool:
"""删除指定偷菜记录只需被偷用户Uid和地块索引
Args:
uid (str): 被偷用户Uid
soilIndex (int): 被偷地块索引
stealerUid (str): 偷菜用户Uid
Returns:
bool: 删除是否成功
@ -219,8 +218,8 @@ class CUserStealDB(CSqlManager):
try:
async with cls._transaction():
await cls.m_pDB.execute(
'DELETE FROM "userSteal" WHERE uid=? AND soilIndex=? AND stealerUid=?;',
(uid, soilIndex, stealerUid)
'DELETE FROM "userSteal" WHERE uid=? AND soilIndex=?;',
(uid, soilIndex)
)
return True
except Exception as e:

View File

@ -210,6 +210,12 @@ class CFarmManager:
return True, plant, True
else:
#如果是多阶段作物 且没有成熟
if soilInfo['harvestCount'] >= 1:
plant = BuildImage(background = g_sResourcePath / f"plant/{soilInfo['plantName']}/{plantInfo['phase'] - 2}.png")
return True, plant, False
#如果没有成熟 则根据当前阶段进行绘制
plantedTime = datetime.fromtimestamp(int(soilInfo['plantTime']))
@ -412,7 +418,16 @@ class CFarmManager:
harvestRecords.append(f"收获作物:{soilInfo['plantName']},数量为:{number},经验为:{plantInfo['experience']}")
await g_pDBService.userPlant.addUserPlantByUid(uid, soilInfo['plantName'], number)
#如果到达收获次数上限
if soilInfo['harvestCount'] + 1 >= plantInfo['crop']:
await g_pDBService.userSoil.updateUserSoil(uid, i, "wiltStatus", 1)
else:
matureTs = int(currentTime.timestamp()) + int(plantInfo.get("again", 0)) * 3600
await g_pDBService.userSoil.updateUserSoil(uid, i, "harvestCount", soilInfo['harvestCount'] + 1)
await g_pDBService.userSoil.updateUserSoil(uid, i, "lastResetTime", int(currentTime.timestamp()))
await g_pDBService.userSoil.updateUserSoil(uid, i, "matureTime", matureTs)
await g_pEventManager.m_afterHarvest.emit(uid=uid, name=soilInfo['plantName'], num=number, soilIndex=i)
@ -463,6 +478,9 @@ class CFarmManager:
#批量更新数据库操作
await g_pDBService.userSoil.deleteUserSoil(uid, i)
#铲除作物会将偷菜记录清空
await g_pDBService.userSteal.deleteStealRecord(uid, i)
await g_pEventManager.m_afterEradicate.emit(uid=uid, soilIndex=i)
if experience > 0:
@ -614,7 +632,18 @@ class CFarmManager:
#如果将作物偷完,就直接更新状态 并记录用户偷取过
if plantInfo['harvest'] - randomNumber + stealingNumber == 0:
#如果作物 是最后一阶段作物且偷完 则直接枯萎
if soilInfo['harvestCount'] + 1 >= plantInfo['crop']:
await g_pDBService.userSoil.updateUserSoil(target, i, "wiltStatus", 1)
else:
matureTs = int(currentTime.timestamp()) + int(plantInfo.get("again", 0)) * 3600
await g_pDBService.userSoil.updateUserSoil(uid, i, "harvestCount", soilInfo['harvestCount'] + 1)
await g_pDBService.userSoil.updateUserSoil(uid, i, "lastResetTime", int(currentTime.timestamp()))
await g_pDBService.userSoil.updateUserSoil(uid, i, "matureTime", matureTs)
await g_pDBService.userSteal.addStealRecord(target, i, uid, randomNumber, int(datetime.now().timestamp()))
else:
await g_pDBService.userSteal.addStealRecord(target, i, uid, randomNumber, int(datetime.now().timestamp()))

View File

@ -1,5 +1,15 @@
# 真寻农场更新日志
## V1.3
用户方面
---
- 新增部分作物
- 修复一个严重BUG, 该BUG会导致无法重复偷别人菜的问题
代码方面
---
- 将作物数据从plant.json迁移至resource/db/plant.db中并将操作json改为操作数据库
## V1.2
用户方面
---

Binary file not shown.

BIN
resource/plant/南瓜/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
resource/plant/南瓜/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
resource/plant/南瓜/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
resource/plant/南瓜/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
resource/plant/南瓜/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
resource/plant/核桃/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
resource/plant/核桃/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
resource/plant/核桃/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
resource/plant/核桃/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
resource/plant/核桃/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
resource/plant/桃子/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
resource/plant/桃子/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
resource/plant/桃子/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
resource/plant/桃子/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
resource/plant/桃子/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
resource/plant/橙子/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
resource/plant/橙子/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
resource/plant/橙子/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
resource/plant/橙子/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
resource/plant/橙子/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
resource/plant/甘蔗/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
resource/plant/甘蔗/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
resource/plant/甘蔗/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
resource/plant/甘蔗/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
resource/plant/甘蔗/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resource/plant/竹笋/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
resource/plant/竹笋/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
resource/plant/竹笋/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

BIN
resource/plant/竹笋/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
resource/plant/竹笋/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resource/plant/芹菜/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

BIN
resource/plant/芹菜/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
resource/plant/芹菜/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
resource/plant/芹菜/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resource/plant/芹菜/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
resource/plant/苹果/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
resource/plant/苹果/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
resource/plant/苹果/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
resource/plant/苹果/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
resource/plant/苹果/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
resource/plant/草莓/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
resource/plant/草莓/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
resource/plant/草莓/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
resource/plant/草莓/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
resource/plant/草莓/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
resource/plant/西瓜/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
resource/plant/西瓜/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
resource/plant/西瓜/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
resource/plant/西瓜/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
resource/plant/西瓜/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resource/plant/辣椒/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
resource/plant/辣椒/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
resource/plant/辣椒/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
resource/plant/辣椒/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
resource/plant/辣椒/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
resource/plant/香蕉/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
resource/plant/香蕉/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
resource/plant/香蕉/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
resource/plant/香蕉/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
resource/plant/香蕉/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
resource/plant/黄瓜/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
resource/plant/黄瓜/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

BIN
resource/plant/黄瓜/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
resource/plant/黄瓜/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
resource/plant/黄瓜/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
resource/plant/黄豆/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

BIN
resource/plant/黄豆/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
resource/plant/黄豆/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

BIN
resource/plant/黄豆/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
resource/plant/黄豆/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB