完善显示用户农场图片,优化部分JSON
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
|
||||
from ..config import g_pJsonManager, g_sResourcePath
|
||||
from ..database import g_pSqlManager
|
||||
|
||||
|
||||
class CFarmManager:
|
||||
|
||||
@classmethod
|
||||
async def drawFarm(cls, uid: str) -> bytes:
|
||||
"""绘制农场
|
||||
|
||||
Args:
|
||||
uid (str): 用户UID
|
||||
|
||||
Returns:
|
||||
bytes: 返回绘制结果
|
||||
"""
|
||||
soilNumber = await g_pSqlManager.getUserLevelByUid(uid)
|
||||
|
||||
img = BuildImage(background=g_sResourcePath / "background/background.jpg")
|
||||
|
||||
soilSize = g_pJsonManager.m_pSoil['size'] # type: ignore
|
||||
|
||||
#TODO 缺少判断用户土地资源状况
|
||||
soil = BuildImage(background=g_sResourcePath / "soil/普通土地.png")
|
||||
await soil.resize(0, soilSize[0], soilSize[1])
|
||||
|
||||
grass = BuildImage(background=g_sResourcePath / "soil/草土地.png")
|
||||
await grass.resize(0, soilSize[0], soilSize[1])
|
||||
|
||||
soilPos = g_pJsonManager.m_pSoil['soil'] # type: ignore
|
||||
|
||||
for key, value in soilPos.items():
|
||||
if soilNumber >= int(key):
|
||||
await img.paste(soil, (value['x'], value['y']))
|
||||
else:
|
||||
await img.paste(grass, (value['x'], value['y']))
|
||||
|
||||
return img.pic2bytes()
|
||||
@@ -1,3 +1,8 @@
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
|
||||
from ..config import g_pJsonManager, g_sResourcePath
|
||||
from ..database import g_pSqlManager
|
||||
|
||||
|
||||
class CShopManager:
|
||||
@@ -5,3 +10,22 @@ class CShopManager:
|
||||
@classmethod
|
||||
async def getPlantShopImage(cls) -> bytes:
|
||||
return bytes()
|
||||
|
||||
@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
|
||||
|
||||
for key, plant in plants.items():
|
||||
if plant['name'] == name:
|
||||
point = g_pSqlManager.getUserPointByUid(uid)
|
||||
total = int(plant['price']) * num
|
||||
|
||||
if point < total
|
||||
return "你的农场币不够哦~ 快速速氪金吧!"
|
||||
else:
|
||||
await g_pSqlManager.updateUserPointByUid(uid, point - total)
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user