feat✨: 新增种子商店功能
feat✨:移除过多的py文件 fix🐛: 对部分json文件进行修正
This commit is contained in:
+92
-7
@@ -1,5 +1,6 @@
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
from zhenxun.utils.image_utils import ImageTemplate
|
||||
|
||||
from ..config import g_pJsonManager, g_sResourcePath
|
||||
from ..database import g_pSqlManager
|
||||
@@ -8,8 +9,8 @@ from ..database import g_pSqlManager
|
||||
class CFarmManager:
|
||||
|
||||
@classmethod
|
||||
async def drawFarm(cls, uid: str) -> bytes:
|
||||
"""绘制农场
|
||||
async def drawFarmByUid(cls, uid: str) -> bytes:
|
||||
"""绘制用户农场
|
||||
|
||||
Args:
|
||||
uid (str): 用户UID
|
||||
@@ -31,11 +32,95 @@ class CFarmManager:
|
||||
await grass.resize(0, soilSize[0], soilSize[1])
|
||||
|
||||
soilPos = g_pJsonManager.m_pSoil['soil'] # type: ignore
|
||||
soilUnlock = g_pJsonManager.m_pLevel['soil'] # type: ignore
|
||||
|
||||
for key, value in soilPos.items():
|
||||
if soilNumber >= int(key):
|
||||
await img.paste(soil, (value['x'], value['y']))
|
||||
x = 0
|
||||
y = 0
|
||||
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))
|
||||
|
||||
#缺少判断土地上是否有农作物
|
||||
plant = BuildImage(background=g_sResourcePath / "plant/basic/0.png")
|
||||
await plant.resize(0, 35, 58)
|
||||
await img.paste(plant, (x + 3, y + 3))
|
||||
else:
|
||||
await img.paste(grass, (value['x'], value['y']))
|
||||
await img.paste(grass, (x, y))
|
||||
|
||||
return img.pic2bytes()
|
||||
return img.pic2bytes()
|
||||
|
||||
@classmethod
|
||||
async def getUserPlantByUid(cls, uid: str) -> bytes:
|
||||
data_list = []
|
||||
column_name = [
|
||||
"-",
|
||||
"种子名称",
|
||||
"数量"
|
||||
"收获经验",
|
||||
"收获数量",
|
||||
"成熟时间(分钟)",
|
||||
"收获次数",
|
||||
"再次成熟时间(分钟)",
|
||||
"是否可以上架交易行"
|
||||
]
|
||||
|
||||
plant = await g_pSqlManager.getUserPlantByUid(uid)
|
||||
|
||||
if plant == None:
|
||||
result = await ImageTemplate.table_page(
|
||||
"种子仓库",
|
||||
"播种示例:@小真寻 播种 大白菜",
|
||||
column_name,
|
||||
data_list,
|
||||
)
|
||||
|
||||
return result.pic2bytes()
|
||||
|
||||
sell = ""
|
||||
|
||||
for item in plant.split(','):
|
||||
if '|' in item:
|
||||
plant_name, count = item.split('|', 1) # 分割一次,避免多竖线问题
|
||||
try:
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][plant_name] # type: ignore
|
||||
|
||||
icon = ""
|
||||
icon_path = g_sResourcePath / f"plant/{plant_name}/icon.png"
|
||||
if icon_path.exists():
|
||||
icon = (icon_path, 33, 33)
|
||||
|
||||
if plantInfo['again'] == True:
|
||||
sell = "可以"
|
||||
else:
|
||||
sell = "不可以"
|
||||
|
||||
data_list.append(
|
||||
[
|
||||
icon,
|
||||
plant_name,
|
||||
count,
|
||||
plantInfo['experience'],
|
||||
plantInfo['harvest'],
|
||||
plantInfo['time'],
|
||||
plantInfo['crop'],
|
||||
plantInfo['again'],
|
||||
sell
|
||||
]
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
continue
|
||||
|
||||
result = await ImageTemplate.table_page(
|
||||
"种子商店",
|
||||
"购买示例:@小真寻 购买种子 大白菜 5",
|
||||
column_name,
|
||||
data_list,
|
||||
)
|
||||
|
||||
return result.pic2bytes()
|
||||
|
||||
g_pFarmManager = CFarmManager()
|
||||
|
||||
+93
-11
@@ -1,5 +1,6 @@
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
from zhenxun.utils.image_utils import ImageTemplate
|
||||
|
||||
from ..config import g_pJsonManager, g_sResourcePath
|
||||
from ..database import g_pSqlManager
|
||||
@@ -9,23 +10,104 @@ class CShopManager:
|
||||
|
||||
@classmethod
|
||||
async def getPlantShopImage(cls) -> bytes:
|
||||
return bytes()
|
||||
"""by ATTomato
|
||||
|
||||
Returns:
|
||||
bytes: _description_
|
||||
"""
|
||||
|
||||
data_list = []
|
||||
column_name = [
|
||||
"-",
|
||||
"种子名称",
|
||||
"解锁等级",
|
||||
"种子单价",
|
||||
"收获经验",
|
||||
"收获数量",
|
||||
"成熟时间(分钟)",
|
||||
"收获次数",
|
||||
"再次成熟时间(分钟)",
|
||||
"是否可以上架交易行"
|
||||
]
|
||||
|
||||
sell = ""
|
||||
plants = g_pJsonManager.m_pPlant['plant'] # type: ignore
|
||||
for key, plant in plants.items():
|
||||
icon = ""
|
||||
icon_path = g_sResourcePath / f"plant/{key}/icon.png"
|
||||
if icon_path.exists():
|
||||
icon = (icon_path, 33, 33)
|
||||
|
||||
if plant['again'] == True:
|
||||
sell = "可以"
|
||||
else:
|
||||
sell = "不可以"
|
||||
|
||||
data_list.append(
|
||||
[
|
||||
icon,
|
||||
key,
|
||||
plant['level'],
|
||||
plant['price'],
|
||||
plant['experience'],
|
||||
plant['harvest'],
|
||||
plant['time'],
|
||||
plant['crop'],
|
||||
plant['again'],
|
||||
sell
|
||||
]
|
||||
)
|
||||
|
||||
result = await ImageTemplate.table_page(
|
||||
"种子商店",
|
||||
"购买示例:@小真寻 购买种子 大白菜 5",
|
||||
column_name,
|
||||
data_list,
|
||||
)
|
||||
|
||||
return result.pic2bytes()
|
||||
|
||||
@classmethod
|
||||
async def buyPlant(cls, uid: str, name: str, num: int = 1) -> str:
|
||||
if num <= 0:
|
||||
return "请输入购买数量!"
|
||||
|
||||
plants = g_pJsonManager.m_pPlant['plant'] # type: ignore
|
||||
plantInfo = None
|
||||
|
||||
for key, plant in plants.items():
|
||||
if plant['name'] == name:
|
||||
point = g_pSqlManager.getUserPointByUid(uid)
|
||||
total = int(plant['price']) * num
|
||||
try:
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][name] # type: ignore
|
||||
except Exception as e:
|
||||
return "购买出错!请检查需购买的种子名称!"
|
||||
|
||||
if point < total
|
||||
return "你的农场币不够哦~ 快速速氪金吧!"
|
||||
else:
|
||||
await g_pSqlManager.updateUserPointByUid(uid, point - total)
|
||||
userPlants = {}
|
||||
|
||||
pass
|
||||
point = await g_pSqlManager.getUserPointByUid(uid)
|
||||
total = int(plantInfo['price']) * num
|
||||
|
||||
logger.debug(f"用户:{uid}购买{name},数量为{num}。用户农场币为{point},购买需要{total}")
|
||||
|
||||
if point < total:
|
||||
return "你的农场币不够哦~ 快速速氪金吧!"
|
||||
else:
|
||||
p = await g_pSqlManager.getUserPlantByUid(uid)
|
||||
|
||||
if not p == None:
|
||||
for item in p.split(','):
|
||||
if '|' in item:
|
||||
plant_name, count = item.split('|', 1) # 分割一次,避免多竖线问题
|
||||
userPlants[plant_name] = int(count)
|
||||
|
||||
if name in userPlants:
|
||||
userPlants[name] += num
|
||||
else:
|
||||
userPlants[name] = num
|
||||
|
||||
plant_list = [f"{k}|{v}" for k, v in userPlants.items()]
|
||||
|
||||
await g_pSqlManager.updateUserPointByUid(uid, point - total)
|
||||
await g_pSqlManager.updateUserPlantByUid(uid, ','.join(plant_list))
|
||||
|
||||
return f"成功购买{name},当前仓库数量为:{userPlants[name]},花费{total}农场币, 剩余{point - total}农场币"
|
||||
|
||||
|
||||
g_pShopManager = CShopManager()
|
||||
|
||||
Reference in New Issue
Block a user