✨ 新增我的种子指令

✨ 对部分资源进行补充
✨ 新增播种功能
This commit is contained in:
2025-03-20 00:45:05 +08:00
parent 13ddcf2a58
commit b1788f42c2
6 changed files with 141 additions and 14 deletions
+67 -8
View File
@@ -1,3 +1,5 @@
from numpy import arange
from zhenxun.services.log import logger
from zhenxun.utils._build_image import BuildImage
from zhenxun.utils.image_utils import ImageTemplate
@@ -36,29 +38,48 @@ class CFarmManager:
x = 0
y = 0
isFirst = True
for index, level in enumerate(soilUnlock):
x = soilPos[str(index + 1)]['x']
y = soilPos[str(index + 1)]['y']
#如果土地已经到达对应等级
if soilNumber >= int(level):
await img.paste(soil, (x, y))
#缺少判断土地上是否有农作物
#TODO 缺少判断土地上是否有农作物
plant = BuildImage(background=g_sResourcePath / "plant/basic/0.png")
await plant.resize(0, 35, 58)
await img.paste(plant, (x + 3, y + 3))
await img.paste(plant, (x + 100, y + 50))
else:
await img.paste(grass, (x, y))
if isFirst:
isFirst = False
#首次添加扩建图片
expansion = BuildImage(background=g_sResourcePath / "background/expansion.png")
await expansion.resize(0, 69, 69)
await img.paste(expansion, (x + 85, y + 20))
return img.pic2bytes()
@classmethod
async def getUserPlantByUid(cls, uid: str) -> bytes:
"""获取用户种子仓库
Args:
uid (str): 用户Uid
Returns:
bytes: 返回图片
"""
data_list = []
column_name = [
"-",
"种子名称",
"数量"
"数量",
"收获经验",
"收获数量",
"成熟时间(分钟)",
@@ -80,15 +101,14 @@ class CFarmManager:
return result.pic2bytes()
sell = ""
for item in plant.split(','):
if '|' in item:
plant_name, count = item.split('|', 1) # 分割一次,避免多竖线问题
plantName, count = item.split('|', 1) # 分割一次,避免多竖线问题
try:
plantInfo = g_pJsonManager.m_pPlant['plant'][plant_name] # type: ignore
plantInfo = g_pJsonManager.m_pPlant['plant'][plantName] # type: ignore
icon = ""
icon_path = g_sResourcePath / f"plant/{plant_name}/icon.png"
icon_path = g_sResourcePath / f"plant/{plantName}/icon.png"
if icon_path.exists():
icon = (icon_path, 33, 33)
@@ -100,7 +120,7 @@ class CFarmManager:
data_list.append(
[
icon,
plant_name,
plantName,
count,
plantInfo['experience'],
plantInfo['harvest'],
@@ -123,4 +143,43 @@ class CFarmManager:
return result.pic2bytes()
@classmethod
async def sowing(cls, uid: str, name: str, num: int = 1) -> str:
"""播种
Args:
uid (str): 用户Uid
name (str): 播种种子名称
num (int, optional): 播种数量
Returns:
str:
"""
plant = await g_pSqlManager.getUserPlantByUid(uid)
if plant == None:
return "你的种子仓库是空的,快去买点吧!"
for item in plant.split(','):
if '|' in item:
plantName, count = item.split('|', 1) # 分割一次,避免多竖线问题
#判断仓库是否有当前播种种子
if plantName == name:
count = int(count)
#获取用户解锁多少块地
soilName = ""
soilNumber = await g_pSqlManager.getUserSoilByUid(uid)
#遍历地块,查看地块是否可以播种
for i in arange(1, soilNumber + 1):
if count > 0:
soilName = f"soil{str(i)}"
#如果可以播种
if await g_pSqlManager.getUserSoilStatusBySoilID(uid, soilName):
count -= 1
await g_pSqlManager.updateUserSoilStatusBySowing(uid, soilName, plantName)
return f"播种{plantName}成功!"
return "播种失败"
g_pFarmManager = CFarmManager()