📝 新增农场详述功能
This commit is contained in:
parent
ff5b446b52
commit
6d3eb5d48f
@ -37,7 +37,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="Art_Sakura",
|
||||
version="1.2",
|
||||
version="1.3",
|
||||
commands=[Command(command="我的农场")],
|
||||
menu_type="群内小游戏",
|
||||
configs=[
|
||||
|
||||
24
command.py
24
command.py
@ -6,6 +6,7 @@ from nonebot_plugin_alconna import (Alconna, AlconnaMatch, AlconnaQuery, Args,
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
from nonebot_plugin_waiter import waiter
|
||||
|
||||
from zhenxun.configs.config import BotConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
@ -41,7 +42,6 @@ async def handle_register(session: Uninfo):
|
||||
return
|
||||
|
||||
try:
|
||||
# 获取原始用户名并安全处理
|
||||
raw_name = str(session.user.name)
|
||||
safe_name = sanitize_username(raw_name)
|
||||
|
||||
@ -120,6 +120,7 @@ diuse_farm = on_alconna(
|
||||
Alconna(
|
||||
"我的农场",
|
||||
Option("--all", action=store_true),
|
||||
Subcommand("detail", help_text="农场详述"),
|
||||
Subcommand("my-point", help_text="我的农场币"),
|
||||
Subcommand("seed-shop", Args["num?", int], help_text="种子商店"),
|
||||
Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"),
|
||||
@ -148,6 +149,27 @@ async def _(session: Uninfo):
|
||||
image = await g_pFarmManager.drawFarmByUid(uid)
|
||||
await MessageUtils.build_message(image).send(reply_to=True)
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"农场详述",
|
||||
command="我的农场",
|
||||
arguments=["detail"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
@diuse_farm.assign("detail")
|
||||
async def _(session: Uninfo):
|
||||
uid = str(session.user.id)
|
||||
|
||||
if await isRegisteredByUid(uid) == False:
|
||||
return
|
||||
|
||||
info = await g_pFarmManager.drawDetailFarmByUid(uid)
|
||||
|
||||
a = await MessageUtils.alc_forward_msg(info, session.self_id, BotConfig.self_nickname).send(reply_to=True)
|
||||
|
||||
logger.info(f"{a}")
|
||||
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"我的农场币",
|
||||
command="我的农场",
|
||||
|
||||
@ -18,7 +18,7 @@ class CUserSoilDB(CSqlManager):
|
||||
#matureTime: 成熟时间
|
||||
#soilLevel: 土地等级 0=普通地,1=红土地,2=黑土地,3=金土地
|
||||
#wiltStatus: 枯萎状态 0=未枯萎,1=枯萎
|
||||
#fertilizerStatus: 施肥状态 0=未施肥,1=施肥
|
||||
#fertilizerStatus: 施肥状态 0=未施肥,1=施肥 2=增肥
|
||||
#bugStatus: 虫害状态 0=无虫害,1=有虫害
|
||||
#weedStatus: 杂草状态 0=无杂草,1=有杂草
|
||||
#waterStatus: 缺水状态 0=不缺水,1=缺水
|
||||
@ -349,3 +349,30 @@ class CUserSoilDB(CSqlManager):
|
||||
except Exception as e:
|
||||
logger.error(f"播种失败!", e=e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def getUserSoilStatus(cls, uid: str, soilIndex: int) -> str:
|
||||
status = []
|
||||
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
|
||||
|
||||
if not soilInfo:
|
||||
return ""
|
||||
|
||||
if soilInfo.get("wiltStatus", 0) == 1:
|
||||
return "枯萎"
|
||||
|
||||
if soilInfo.get("fertilizerStatus", 0) == 1:
|
||||
status.append("施肥")
|
||||
elif soilInfo.get("fertilizerStatus", 0) == 2:
|
||||
status.append("增肥")
|
||||
|
||||
if soilInfo.get("bugStatus", 0) == 1:
|
||||
status.append("虫害")
|
||||
|
||||
if soilInfo.get("weedStatus", 0) == 1:
|
||||
status.append("杂草")
|
||||
|
||||
if soilInfo.get("waterStatus", 0) == 1:
|
||||
status.append("缺水")
|
||||
|
||||
return ",".join(status)
|
||||
|
||||
87
farm/farm.py
87
farm/farm.py
@ -170,6 +170,93 @@ class CFarmManager:
|
||||
|
||||
return img.pic2bytes()
|
||||
|
||||
@classmethod
|
||||
async def drawDetailFarmByUid(cls, uid: str) -> list:
|
||||
info = []
|
||||
|
||||
farm = await cls.drawFarmByUid(uid)
|
||||
|
||||
info.append(BuildImage.open(farm))
|
||||
|
||||
dataList = []
|
||||
columnName = [
|
||||
"-",
|
||||
"土地ID",
|
||||
"作物名称",
|
||||
"成熟时间",
|
||||
"土地状态",
|
||||
"剩余产出",
|
||||
]
|
||||
|
||||
icon = ""
|
||||
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
||||
|
||||
for i in range(1, soilNumber + 1):
|
||||
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
|
||||
|
||||
if not soilInfo:
|
||||
continue
|
||||
|
||||
if soilInfo["soilLevel"] == 1:
|
||||
iconPath = g_sResourcePath / f"soil/TODO.png"
|
||||
else:
|
||||
iconPath = g_sResourcePath / f"soil/普通土地.png"
|
||||
|
||||
if iconPath.exists():
|
||||
icon = (iconPath, 33, 33)
|
||||
|
||||
plantName = soilInfo.get("plantName", "-")
|
||||
|
||||
if plantName == "-":
|
||||
matureTime = "-"
|
||||
soilStatus = "-"
|
||||
plantNumber = "-"
|
||||
else:
|
||||
matureTime = datetime.fromtimestamp(int(soilInfo.get("matureTime", 0))).strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||
soilStatus = await g_pDBService.userSoil.getUserSoilStatus(uid, i)
|
||||
|
||||
num = await g_pDBService.userSteal.getTotalStolenCount(uid, i)
|
||||
planInfo = await g_pDBService.plant.getPlantByName(plantName)
|
||||
|
||||
if not planInfo:
|
||||
plantNumber = f"None / {num}"
|
||||
else:
|
||||
plantNumber = f"{planInfo['harvest']} / {num}"
|
||||
|
||||
dataList.append(
|
||||
[
|
||||
icon,
|
||||
i,
|
||||
plantName,
|
||||
matureTime,
|
||||
soilStatus,
|
||||
plantNumber,
|
||||
])
|
||||
|
||||
if len(dataList) >= 15:
|
||||
result = await ImageTemplate.table_page(
|
||||
"土地详细信息",
|
||||
"测试N\n测试2",
|
||||
columnName,
|
||||
dataList,
|
||||
)
|
||||
|
||||
info.append(result)
|
||||
dataList.clear()
|
||||
|
||||
if i >= 30:
|
||||
result = await ImageTemplate.table_page(
|
||||
"土地详细信息",
|
||||
"测试N\n测试2",
|
||||
columnName,
|
||||
dataList,
|
||||
)
|
||||
|
||||
info.append(result)
|
||||
dataList.clear()
|
||||
|
||||
return info
|
||||
|
||||
@classmethod
|
||||
async def drawSoilPlant(cls, uid: str, soilIndex: int) -> tuple[bool, BuildImage, bool]:
|
||||
"""绘制植物资源
|
||||
|
||||
16
farm/shop.py
16
farm/shop.py
@ -21,8 +21,8 @@ class CShopManager:
|
||||
bytes: 返回商店图片bytes
|
||||
"""
|
||||
|
||||
data_list = []
|
||||
column_name = [
|
||||
dataList = []
|
||||
columnName = [
|
||||
"-",
|
||||
"种子名称",
|
||||
"种子单价",
|
||||
@ -48,16 +48,16 @@ class CShopManager:
|
||||
continue
|
||||
|
||||
icon = ""
|
||||
icon_path = g_sResourcePath / f"plant/{plant['name']}/icon.png"
|
||||
if icon_path.exists():
|
||||
icon = (icon_path, 33, 33)
|
||||
iconPath = g_sResourcePath / f"plant/{plant['name']}/icon.png"
|
||||
if iconPath.exists():
|
||||
icon = (iconPath, 33, 33)
|
||||
|
||||
if plant['again'] == True:
|
||||
sell = "可以"
|
||||
else:
|
||||
sell = "不可以"
|
||||
|
||||
data_list.append(
|
||||
dataList.append(
|
||||
[
|
||||
icon,
|
||||
plant['name'],
|
||||
@ -79,8 +79,8 @@ class CShopManager:
|
||||
result = await ImageTemplate.table_page(
|
||||
title,
|
||||
"购买示例:@小真寻 购买种子 大白菜 5",
|
||||
column_name,
|
||||
data_list,
|
||||
columnName,
|
||||
dataList,
|
||||
)
|
||||
|
||||
return result.pic2bytes()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user