2025-04-10 18:25:20 +08:00
|
|
|
|
import math
|
2025-03-21 18:14:50 +08:00
|
|
|
|
import random
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-04-08 19:00:17 +08:00
|
|
|
|
from zhenxun.configs.config import Config
|
2025-03-21 00:25:20 +08:00
|
|
|
|
from zhenxun.models.user_console import UserConsole
|
2025-03-19 01:16:08 +08:00
|
|
|
|
from zhenxun.services.log import logger
|
|
|
|
|
|
from zhenxun.utils._build_image import BuildImage
|
2025-03-21 00:25:20 +08:00
|
|
|
|
from zhenxun.utils.enum import GoldHandle
|
2025-03-19 18:00:50 +08:00
|
|
|
|
from zhenxun.utils.image_utils import ImageTemplate
|
2025-04-15 18:35:36 +08:00
|
|
|
|
from zhenxun.utils.platform import PlatformUtils
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
from ..config import g_bIsDebug, g_iSoilLevelMax, g_sResourcePath, g_sTranslation
|
2025-04-28 19:27:16 +08:00
|
|
|
|
from ..dbService import g_pDBService
|
|
|
|
|
|
from ..event.event import g_pEventManager
|
2025-05-07 17:04:08 +08:00
|
|
|
|
from ..json import g_pJsonManager
|
2025-05-27 18:15:11 +08:00
|
|
|
|
from ..tool import g_pToolManager
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CFarmManager:
|
2025-03-21 00:25:20 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def buyPointByUid(cls, uid: str, num: int) -> str:
|
|
|
|
|
|
if num <= 0:
|
|
|
|
|
|
return "你是怎么做到购买不是正数的农场币的"
|
|
|
|
|
|
|
|
|
|
|
|
user = await UserConsole.get_user(uid)
|
|
|
|
|
|
|
2025-04-10 18:25:20 +08:00
|
|
|
|
pro = float(Config.get_config("zhenxun_plugin_farm", "兑换倍数"))
|
|
|
|
|
|
tax = float(Config.get_config("zhenxun_plugin_farm", "手续费"))
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 计算手续费
|
2025-04-10 18:25:20 +08:00
|
|
|
|
fee = math.floor(num * tax)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 实际扣费金额
|
2025-04-10 18:25:20 +08:00
|
|
|
|
deduction = num + fee
|
2025-04-08 19:00:17 +08:00
|
|
|
|
|
2025-04-10 18:25:20 +08:00
|
|
|
|
if user.gold < deduction:
|
|
|
|
|
|
return f"你的金币不足或不足承担手续费。当前手续费为{fee}"
|
2025-04-08 19:00:17 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await UserConsole.reduce_gold(
|
|
|
|
|
|
uid, num, GoldHandle.PLUGIN, "zhenxun_plugin_farm"
|
2025-06-29 01:45:24 +08:00
|
|
|
|
)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await UserConsole.reduce_gold(
|
|
|
|
|
|
uid, fee, GoldHandle.PLUGIN, "zhenxun_plugin_farm"
|
|
|
|
|
|
) # type: ignore
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
point = num * pro
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
p = await g_pDBService.user.getUserPointByUid(uid)
|
2025-04-08 19:00:17 +08:00
|
|
|
|
number = point + p
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
await g_pDBService.user.updateUserPointByUid(uid, int(number))
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-10 18:25:20 +08:00
|
|
|
|
return f"充值{point}农场币成功,手续费{tax}金币,当前农场币:{number}"
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2025-04-27 17:00:58 +08:00
|
|
|
|
async def drawFarmByUid(cls, uid: str) -> bytes:
|
2025-03-19 18:00:50 +08:00
|
|
|
|
"""绘制用户农场
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户UID
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
bytes: 返回绘制结果
|
|
|
|
|
|
"""
|
2025-06-06 10:56:22 +08:00
|
|
|
|
img = BuildImage(background=g_sResourcePath / "background/background.jpg")
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
soilSize = g_pJsonManager.m_pSoil["size"]
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
grass = BuildImage(background=g_sResourcePath / "soil/草土地.png")
|
2025-03-19 01:16:08 +08:00
|
|
|
|
await grass.resize(0, soilSize[0], soilSize[1])
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
soilPos = g_pJsonManager.m_pSoil["soil"]
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
userInfo = await g_pDBService.user.getUserInfoByUid(uid)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
soilUnlock = int(userInfo["soil"])
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
x = 0
|
|
|
|
|
|
y = 0
|
2025-06-06 10:56:22 +08:00
|
|
|
|
isFirstExpansion = True # 首次添加扩建图片
|
2025-03-20 18:06:38 +08:00
|
|
|
|
isFirstRipe = True
|
|
|
|
|
|
plant = None
|
2025-03-21 18:14:50 +08:00
|
|
|
|
for index in range(0, 30):
|
2025-06-06 10:56:22 +08:00
|
|
|
|
x = soilPos[str(index + 1)]["x"]
|
|
|
|
|
|
y = soilPos[str(index + 1)]["y"]
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果土地已经到达对应等级
|
2025-04-07 18:52:27 +08:00
|
|
|
|
if index < soilUnlock:
|
2025-06-29 01:45:24 +08:00
|
|
|
|
soilUrl = ""
|
|
|
|
|
|
# TODO 缺少判断用户土地资源状况
|
2025-06-29 21:31:09 +08:00
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, index + 1)
|
2025-06-29 01:45:24 +08:00
|
|
|
|
|
|
|
|
|
|
if not soilInfo:
|
|
|
|
|
|
soilUrl = "soil/普通土地.png"
|
|
|
|
|
|
else:
|
|
|
|
|
|
soilLevel = soilInfo.get("soilLevel", 0)
|
|
|
|
|
|
|
|
|
|
|
|
if soilLevel == 1:
|
|
|
|
|
|
soilUrl = "soil/红土地.png"
|
|
|
|
|
|
elif soilLevel == 2:
|
|
|
|
|
|
soilUrl = "soil/黑土地.png"
|
|
|
|
|
|
elif soilLevel == 3:
|
|
|
|
|
|
soilUrl = "soil/金土地.png"
|
|
|
|
|
|
else:
|
|
|
|
|
|
soilUrl = "soil/普通土地.png"
|
|
|
|
|
|
|
|
|
|
|
|
soil = BuildImage(background=g_sResourcePath / soilUrl)
|
|
|
|
|
|
await soil.resize(0, soilSize[0], soilSize[1])
|
|
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await img.paste(soil, (x, y))
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
isPlant, plant, isRipe, offsetX, offsetY = await cls.drawSoilPlant(
|
|
|
|
|
|
uid, index + 1
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
if isPlant:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await img.paste(
|
|
|
|
|
|
plant,
|
|
|
|
|
|
(
|
|
|
|
|
|
x + soilSize[0] // 2 - plant.width // 2 + offsetX,
|
|
|
|
|
|
y + soilSize[1] // 2 - plant.height // 2 + offsetY,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 1700 275
|
|
|
|
|
|
# 首次添加可收获图片
|
2025-03-20 18:06:38 +08:00
|
|
|
|
if isRipe and isFirstRipe:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
ripe = BuildImage(
|
|
|
|
|
|
background=g_sResourcePath / "background/ripe.png"
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await img.paste(
|
|
|
|
|
|
ripe,
|
|
|
|
|
|
(x + soilSize[0] // 2 - ripe.width // 2, y - ripe.height // 2),
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
isFirstRipe = False
|
2025-03-19 01:16:08 +08:00
|
|
|
|
else:
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await img.paste(grass, (x, y))
|
|
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
if isFirstExpansion:
|
|
|
|
|
|
isFirstExpansion = False
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 首次添加扩建图片
|
|
|
|
|
|
expansion = BuildImage(
|
|
|
|
|
|
background=g_sResourcePath / "background/expansion.png"
|
|
|
|
|
|
)
|
2025-03-20 00:45:05 +08:00
|
|
|
|
await expansion.resize(0, 69, 69)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await img.paste(
|
|
|
|
|
|
expansion,
|
|
|
|
|
|
(
|
|
|
|
|
|
x + soilSize[0] // 2 - expansion.width // 2,
|
|
|
|
|
|
y + soilSize[1] // 2 - expansion.height,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 左上角绘制用户信息
|
|
|
|
|
|
# 头像
|
2025-04-15 18:35:36 +08:00
|
|
|
|
image = await PlatformUtils.get_user_avatar(uid, "qq")
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-04-15 18:35:36 +08:00
|
|
|
|
if image:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
avatar = BuildImage(background=image)
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-04-15 18:35:36 +08:00
|
|
|
|
await img.paste(avatar, (125, 85))
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 头像框
|
|
|
|
|
|
frame = BuildImage(background=g_sResourcePath / "background/frame.png")
|
2025-04-15 18:35:36 +08:00
|
|
|
|
await img.paste(frame, (75, 44))
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 用户名
|
|
|
|
|
|
nameImg = await BuildImage.build_text_image(
|
|
|
|
|
|
userInfo["name"], size=24, font_color=(77, 35, 4)
|
|
|
|
|
|
)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
await img.paste(nameImg, (300, 92))
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 经验值
|
2025-04-28 19:27:16 +08:00
|
|
|
|
level = await g_pDBService.user.getUserLevelByUid(uid)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
|
|
|
|
|
|
beginX = 309
|
|
|
|
|
|
endX = 627
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 绘制宽度计算公式为 (当前经验值 / 经验值上限) * 宽度
|
2025-04-16 11:53:30 +08:00
|
|
|
|
width = int((level[2] / level[1]) * (endX - beginX))
|
|
|
|
|
|
await img.rectangle((beginX, 188, beginX + width, 222), (171, 194, 41))
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
expImg = await BuildImage.build_text_image(
|
|
|
|
|
|
f"{level[2]} / {level[1]}", size=24, font_color=(102, 120, 19)
|
|
|
|
|
|
)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
await img.paste(expImg, (390, 193))
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 等级
|
|
|
|
|
|
levelImg = await BuildImage.build_text_image(
|
|
|
|
|
|
str(level[0]), size=32, font_color=(214, 111, 1)
|
|
|
|
|
|
)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
await img.paste(levelImg, (660, 187))
|
2025-04-10 18:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 金币
|
|
|
|
|
|
pointImg = await BuildImage.build_text_image(
|
|
|
|
|
|
str(userInfo["point"]), size=24, font_color=(253, 253, 253)
|
|
|
|
|
|
)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
await img.paste(pointImg, (330, 255))
|
2025-04-15 18:35:36 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 点券 TODO
|
|
|
|
|
|
bondsImg = await BuildImage.build_text_image(
|
|
|
|
|
|
"0", size=24, font_color=(253, 253, 253)
|
|
|
|
|
|
)
|
2025-04-16 11:53:30 +08:00
|
|
|
|
await img.paste(bondsImg, (570, 255))
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 清晰度
|
2025-04-16 11:53:30 +08:00
|
|
|
|
definition = Config.get_config("zhenxun_plugin_farm", "绘制农场清晰度")
|
|
|
|
|
|
if definition == "medium":
|
|
|
|
|
|
await img.resize(0.6)
|
|
|
|
|
|
elif definition == "hight":
|
|
|
|
|
|
await img.resize(0.8)
|
|
|
|
|
|
elif definition == "original":
|
|
|
|
|
|
pass
|
|
|
|
|
|
else:
|
|
|
|
|
|
await img.resize(0.4)
|
2025-04-15 18:35:36 +08:00
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
return img.pic2bytes()
|
|
|
|
|
|
|
2025-05-12 17:28:33 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def drawDetailFarmByUid(cls, uid: str) -> list:
|
|
|
|
|
|
info = []
|
|
|
|
|
|
|
|
|
|
|
|
farm = await cls.drawFarmByUid(uid)
|
|
|
|
|
|
|
|
|
|
|
|
info.append(BuildImage.open(farm))
|
|
|
|
|
|
|
|
|
|
|
|
dataList = []
|
|
|
|
|
|
columnName = [
|
|
|
|
|
|
"-",
|
|
|
|
|
|
"土地ID",
|
2025-06-29 01:45:24 +08:00
|
|
|
|
"土地等级",
|
2025-05-12 17:28:33 +08:00
|
|
|
|
"作物名称",
|
|
|
|
|
|
"成熟时间",
|
|
|
|
|
|
"土地状态",
|
2025-05-29 01:27:46 +08:00
|
|
|
|
"被偷数量",
|
2025-05-12 17:28:33 +08:00
|
|
|
|
"剩余产出",
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
icon = ""
|
|
|
|
|
|
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(1, soilNumber + 1):
|
|
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
|
|
|
|
|
|
|
2025-05-29 01:27:46 +08:00
|
|
|
|
if soilInfo:
|
2025-06-29 22:38:51 +08:00
|
|
|
|
match soilInfo.get("soilLevel", 0):
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
name = "红土地.png"
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
name = "黑土地.png"
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
name = "金土地.png"
|
|
|
|
|
|
case _:
|
|
|
|
|
|
name = "普通土地.png"
|
|
|
|
|
|
iconPath = g_sResourcePath / "soil" / name
|
2025-05-12 17:28:33 +08:00
|
|
|
|
|
2025-05-29 01:27:46 +08:00
|
|
|
|
if iconPath.exists():
|
|
|
|
|
|
icon = (iconPath, 33, 33)
|
2025-05-12 17:28:33 +08:00
|
|
|
|
|
2025-05-29 01:27:46 +08:00
|
|
|
|
plantName = soilInfo.get("plantName", "-")
|
2025-05-12 17:28:33 +08:00
|
|
|
|
|
2025-05-29 01:27:46 +08:00
|
|
|
|
if plantName == "-":
|
|
|
|
|
|
matureTime = "-"
|
|
|
|
|
|
soilStatus = "-"
|
|
|
|
|
|
totalNumber = "-"
|
|
|
|
|
|
plantNumber = "-"
|
2025-05-12 17:28:33 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
matureTime = (
|
|
|
|
|
|
g_pToolManager.dateTime()
|
|
|
|
|
|
.fromtimestamp(int(soilInfo.get("matureTime", 0)))
|
|
|
|
|
|
.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
)
|
2025-05-29 01:27:46 +08:00
|
|
|
|
soilStatus = await g_pDBService.userSoil.getUserSoilStatus(uid, i)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
totalNumber = await g_pDBService.userSteal.getTotalStolenCount(
|
|
|
|
|
|
uid, i
|
|
|
|
|
|
)
|
2025-05-29 01:27:46 +08:00
|
|
|
|
planInfo = await g_pDBService.plant.getPlantByName(plantName)
|
|
|
|
|
|
|
|
|
|
|
|
if not planInfo:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plantNumber = "None"
|
2025-05-29 01:27:46 +08:00
|
|
|
|
else:
|
2025-05-30 11:22:32 +08:00
|
|
|
|
plantNumber = f"{planInfo['harvest'] - totalNumber}"
|
2025-05-29 01:27:46 +08:00
|
|
|
|
|
|
|
|
|
|
dataList.append(
|
2025-06-06 10:56:22 +08:00
|
|
|
|
[
|
|
|
|
|
|
icon,
|
|
|
|
|
|
i,
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pDBService.userSoil.getSoilLevelText(
|
|
|
|
|
|
soilInfo["soilLevel"]
|
|
|
|
|
|
),
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plantName,
|
|
|
|
|
|
matureTime,
|
|
|
|
|
|
soilStatus,
|
|
|
|
|
|
totalNumber,
|
|
|
|
|
|
plantNumber,
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2025-05-29 01:27:46 +08:00
|
|
|
|
|
|
|
|
|
|
if len(dataList) >= 15:
|
|
|
|
|
|
result = await ImageTemplate.table_page(
|
|
|
|
|
|
"土地详细信息",
|
|
|
|
|
|
"",
|
|
|
|
|
|
columnName,
|
|
|
|
|
|
dataList,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
info.append(result.copy())
|
|
|
|
|
|
dataList.clear()
|
|
|
|
|
|
|
|
|
|
|
|
if i >= soilNumber:
|
2025-05-12 17:28:33 +08:00
|
|
|
|
result = await ImageTemplate.table_page(
|
|
|
|
|
|
"土地详细信息",
|
2025-05-29 01:27:46 +08:00
|
|
|
|
"",
|
2025-05-12 17:28:33 +08:00
|
|
|
|
columnName,
|
|
|
|
|
|
dataList,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-29 01:27:46 +08:00
|
|
|
|
info.append(result.copy())
|
2025-05-12 17:28:33 +08:00
|
|
|
|
dataList.clear()
|
|
|
|
|
|
|
|
|
|
|
|
return info
|
|
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
@classmethod
|
2025-06-06 10:56:22 +08:00
|
|
|
|
async def drawSoilPlant(
|
|
|
|
|
|
cls, uid: str, soilIndex: int
|
|
|
|
|
|
) -> tuple[bool, BuildImage, bool, int, int]:
|
2025-03-20 18:06:38 +08:00
|
|
|
|
"""绘制植物资源
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilIndex (int): 土地索引 从1开始
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
tuple[bool, BuildImage]: [绘制是否成功,资源图片, 是否成熟]
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
plant = None
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-05-30 11:22:32 +08:00
|
|
|
|
if not soilInfo:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return False, None, False, 0, 0 # type: ignore
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 是否枯萎
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if int(soilInfo.get("wiltStatus", 0)) == 1:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plant = BuildImage(background=g_sResourcePath / "plant/basic/9.png")
|
2025-04-28 19:27:16 +08:00
|
|
|
|
await plant.resize(0, 150, 212)
|
2025-05-29 18:20:03 +08:00
|
|
|
|
return True, plant, False, 0, 0
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 获取作物详细信息
|
|
|
|
|
|
plantInfo = await g_pDBService.plant.getPlantByName(soilInfo["plantName"])
|
2025-05-08 17:56:45 +08:00
|
|
|
|
if not plantInfo:
|
|
|
|
|
|
logger.error(f"绘制植物资源失败: {soilInfo['plantName']}")
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return False, None, False, 0, 0 # type: ignore
|
2025-05-29 18:20:03 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
offsetX = plantInfo.get("officX", 0)
|
|
|
|
|
|
offsetY = plantInfo.get("officY", 0)
|
|
|
|
|
|
offsetW = plantInfo.get("officW", 0)
|
|
|
|
|
|
offsetH = plantInfo.get("officH", 0)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-05-30 11:22:32 +08:00
|
|
|
|
currentTime = g_pToolManager.dateTime().now().timestamp()
|
2025-06-06 10:56:22 +08:00
|
|
|
|
phaseList = await g_pDBService.plant.getPlantPhaseByName(soilInfo["plantName"])
|
2025-05-28 19:48:12 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果当前时间大于成熟时间 说明作物成熟
|
|
|
|
|
|
if currentTime >= soilInfo["matureTime"]:
|
|
|
|
|
|
plant = BuildImage(
|
|
|
|
|
|
background=g_sResourcePath
|
|
|
|
|
|
/ f"plant/{soilInfo['plantName']}/{len(phaseList)}.png"
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
return True, plant, True, offsetX, offsetY
|
2025-04-28 19:27:16 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果是多阶段作物 且没有成熟 #早期思路 多阶段作物 直接是倒数第二阶段图片
|
2025-06-29 01:45:24 +08:00
|
|
|
|
# if soilInfo["harvestCount"] >= 1:
|
|
|
|
|
|
# plant = BuildImage(
|
|
|
|
|
|
# background=g_sResourcePath
|
|
|
|
|
|
# / f"plant/{soilInfo['plantName']}/{plantInfo['phase'] - 1}.png"
|
|
|
|
|
|
# )
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
# return True, plant, False, offsetX, offsetY
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果没有成熟 则根据当前阶段进行绘制
|
|
|
|
|
|
elapsedTime = currentTime - soilInfo["plantTime"]
|
|
|
|
|
|
currentStage = currentStage = sum(
|
|
|
|
|
|
1 for thr in phaseList if elapsedTime >= thr
|
|
|
|
|
|
)
|
2025-04-27 10:52:28 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if currentStage <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not plantInfo["general"]:
|
|
|
|
|
|
plant = BuildImage(
|
|
|
|
|
|
background=g_sResourcePath
|
|
|
|
|
|
/ f"plant/{soilInfo['plantName']}/0.png"
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plant = BuildImage(background=g_sResourcePath / "plant/basic/0.png")
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
await plant.resize(0, 35 + offsetW, 58 + offsetH)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plant = BuildImage(
|
|
|
|
|
|
background=g_sResourcePath
|
|
|
|
|
|
/ f"plant/{soilInfo['plantName']}/{currentStage}.png"
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
return True, plant, False, offsetX, offsetY
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
async def getUserSeedByUid(cls, uid: str) -> bytes:
|
2025-04-22 19:42:09 +08:00
|
|
|
|
"""获取用户种子仓库"""
|
|
|
|
|
|
dataList = []
|
|
|
|
|
|
columnNames = [
|
2025-03-19 18:00:50 +08:00
|
|
|
|
"-",
|
|
|
|
|
|
"种子名称",
|
2025-03-20 00:45:05 +08:00
|
|
|
|
"数量",
|
2025-03-19 18:00:50 +08:00
|
|
|
|
"收获经验",
|
|
|
|
|
|
"收获数量",
|
2025-03-21 00:25:20 +08:00
|
|
|
|
"成熟时间(小时)",
|
2025-03-19 18:00:50 +08:00
|
|
|
|
"收获次数",
|
2025-06-06 10:56:22 +08:00
|
|
|
|
"是否可以上架交易行",
|
2025-03-19 18:00:50 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 从数据库获取结构化数据
|
2025-04-28 19:27:16 +08:00
|
|
|
|
seedRecords = await g_pDBService.userSeed.getUserSeedByUid(uid) or {}
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if not seedRecords:
|
2025-03-19 18:00:50 +08:00
|
|
|
|
result = await ImageTemplate.table_page(
|
|
|
|
|
|
"种子仓库",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
"播种示例:@小真寻 播种 大白菜 [数量]",
|
2025-04-22 19:42:09 +08:00
|
|
|
|
columnNames,
|
|
|
|
|
|
dataList,
|
2025-03-19 18:00:50 +08:00
|
|
|
|
)
|
|
|
|
|
|
return result.pic2bytes()
|
|
|
|
|
|
|
2025-04-22 19:42:09 +08:00
|
|
|
|
for seedName, count in seedRecords.items():
|
|
|
|
|
|
try:
|
2025-05-08 17:56:45 +08:00
|
|
|
|
plantInfo = await g_pDBService.plant.getPlantByName(seedName)
|
|
|
|
|
|
if not plantInfo:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
2025-04-22 19:42:09 +08:00
|
|
|
|
iconPath = g_sResourcePath / f"plant/{seedName}/icon.png"
|
|
|
|
|
|
icon = (iconPath, 33, 33) if iconPath.exists() else ""
|
2025-06-06 10:56:22 +08:00
|
|
|
|
sellable = "可以" if plantInfo["sell"] else "不可以"
|
|
|
|
|
|
|
|
|
|
|
|
dataList.append(
|
|
|
|
|
|
[
|
|
|
|
|
|
icon,
|
|
|
|
|
|
seedName,
|
|
|
|
|
|
count,
|
|
|
|
|
|
plantInfo["experience"],
|
|
|
|
|
|
plantInfo["harvest"],
|
|
|
|
|
|
plantInfo["time"],
|
|
|
|
|
|
plantInfo["crop"],
|
|
|
|
|
|
sellable,
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
except KeyError:
|
|
|
|
|
|
continue
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
|
|
|
|
|
result = await ImageTemplate.table_page(
|
2025-03-20 18:06:38 +08:00
|
|
|
|
"种子仓库",
|
|
|
|
|
|
"播种示例:@小真寻 播种 大白菜 [数量]",
|
2025-04-22 19:42:09 +08:00
|
|
|
|
columnNames,
|
|
|
|
|
|
dataList,
|
2025-03-19 18:00:50 +08:00
|
|
|
|
)
|
|
|
|
|
|
return result.pic2bytes()
|
2025-03-19 01:16:08 +08:00
|
|
|
|
|
2025-03-20 00:45:05 +08:00
|
|
|
|
@classmethod
|
2025-03-20 18:06:38 +08:00
|
|
|
|
async def sowing(cls, uid: str, name: str, num: int = -1) -> str:
|
2025-03-20 00:45:05 +08:00
|
|
|
|
"""播种
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
name (str): 播种种子名称
|
|
|
|
|
|
num (int, optional): 播种数量
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
2025-04-22 19:42:09 +08:00
|
|
|
|
str: 返回结果
|
2025-03-20 00:45:05 +08:00
|
|
|
|
"""
|
2025-04-22 19:42:09 +08:00
|
|
|
|
try:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 获取用户的种子数量
|
2025-04-28 19:27:16 +08:00
|
|
|
|
count = await g_pDBService.userSeed.getUserSeedByName(uid, name)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if count is None:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
count = 0 # 如果返回 None,则视为没有种子
|
2025-04-22 19:42:09 +08:00
|
|
|
|
|
|
|
|
|
|
if count <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["sowing"]["noSeed"].format(name=name)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果播种数量超过仓库种子数量
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if count < num and num != -1:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["sowing"]["noNum"].format(name=name, num=count)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 获取用户土地数量
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果播种数量为 -1,表示播种所有可播种的土地
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if num == -1:
|
|
|
|
|
|
num = count
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 发送播种前信号
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_beforePlant.emit(uid=uid, name=name, num=num) # type: ignore
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 记录是否成功播种
|
2025-04-22 19:42:09 +08:00
|
|
|
|
successCount = 0
|
|
|
|
|
|
for i in range(1, soilNumber + 1):
|
|
|
|
|
|
if count > 0 and num > 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
success = await g_pDBService.userSoil.sowingByPlantName(
|
|
|
|
|
|
uid, i, name
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
if success:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 更新种子数量
|
2025-03-20 18:06:38 +08:00
|
|
|
|
num -= 1
|
2025-04-10 18:25:20 +08:00
|
|
|
|
count -= 1
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 记录种子消耗数量
|
2025-04-22 19:42:09 +08:00
|
|
|
|
successCount += 1
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 发送播种后信号
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_afterPlant.emit( # type: ignore
|
2025-06-06 10:56:22 +08:00
|
|
|
|
uid=uid, name=name, soilIndex=i
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 确保用户仓库数量更新
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if successCount > 0:
|
2025-04-28 19:27:16 +08:00
|
|
|
|
await g_pDBService.userSeed.updateUserSeedByName(uid, name, count)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 根据播种结果给出反馈
|
2025-04-22 19:42:09 +08:00
|
|
|
|
if num == 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["sowing"]["success"].format(name=name, num=count)
|
2025-04-22 19:42:09 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["sowing"]["success2"].format(name=name, num=count)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-22 19:42:09 +08:00
|
|
|
|
except Exception as e:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
logger.warning("播种操作失败!", e=e)
|
|
|
|
|
|
return g_sTranslation["sowing"]["error"]
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
async def harvest(cls, uid: str) -> str:
|
|
|
|
|
|
"""收获作物
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str: 返回
|
|
|
|
|
|
"""
|
2025-04-28 19:27:16 +08:00
|
|
|
|
try:
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_beforeHarvest.emit(uid=uid) # type: ignore
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
harvestRecords = [] # 收获日志记录
|
|
|
|
|
|
experience = 0 # 总经验值
|
|
|
|
|
|
harvestCount = 0 # 成功收获数量
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
for i in range(1, soilNumber + 1):
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果没有种植
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if not await g_pDBService.userSoil.isSoilPlanted(uid, i):
|
|
|
|
|
|
continue
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
|
|
|
|
|
|
if not soilInfo:
|
|
|
|
|
|
continue
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
level = soilInfo.get("soilLevel", 0)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果是枯萎状态
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if soilInfo.get("wiltStatus", 1) == 1:
|
|
|
|
|
|
continue
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plantInfo = await g_pDBService.plant.getPlantByName(
|
|
|
|
|
|
soilInfo["plantName"]
|
|
|
|
|
|
)
|
2025-05-08 17:56:45 +08:00
|
|
|
|
if not plantInfo:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
currentTime = g_pToolManager.dateTime().now()
|
2025-06-06 10:56:22 +08:00
|
|
|
|
matureTime = g_pToolManager.dateTime().fromtimestamp(
|
|
|
|
|
|
int(soilInfo["matureTime"])
|
|
|
|
|
|
)
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if currentTime >= matureTime:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
number = plantInfo["harvest"]
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 处理偷菜扣除数量
|
2025-04-29 18:11:09 +08:00
|
|
|
|
stealNum = await g_pDBService.userSteal.getTotalStolenCount(uid, i)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
number -= stealNum
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
# 处理土地等级带来的数量增长 向下取整
|
|
|
|
|
|
percent = await g_pDBService.userSoil.getSoilLevelHarvestNumber(
|
|
|
|
|
|
level
|
|
|
|
|
|
)
|
2025-06-29 21:31:09 +08:00
|
|
|
|
number = math.floor(number * (100 + percent) // 100)
|
2025-06-29 01:45:24 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if number <= 0:
|
|
|
|
|
|
continue
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
harvestCount += 1
|
2025-06-06 10:56:22 +08:00
|
|
|
|
experience += plantInfo["experience"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
# 处理土地等级带来的经验增长 向下取整
|
|
|
|
|
|
percent = await g_pDBService.userSoil.getSoilLevelHarvestExp(level)
|
2025-06-29 21:31:09 +08:00
|
|
|
|
experience = math.floor(experience * (100 + percent) // 100)
|
2025-06-29 01:45:24 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
harvestRecords.append(
|
|
|
|
|
|
g_sTranslation["harvest"]["append"].format(
|
|
|
|
|
|
name=soilInfo["plantName"],
|
|
|
|
|
|
num=number,
|
2025-06-29 21:31:09 +08:00
|
|
|
|
exp=plantInfo["experience"],
|
2025-06-06 10:56:22 +08:00
|
|
|
|
)
|
|
|
|
|
|
)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userPlant.addUserPlantByUid(
|
|
|
|
|
|
uid, soilInfo["plantName"], number
|
|
|
|
|
|
)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果到达收获次数上限
|
|
|
|
|
|
if soilInfo["harvestCount"] + 1 >= plantInfo["crop"]:
|
|
|
|
|
|
await g_pDBService.userSoil.updateUserSoil(
|
|
|
|
|
|
uid, i, "wiltStatus", 1
|
|
|
|
|
|
)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
phase = await g_pDBService.plant.getPlantPhaseByName(
|
|
|
|
|
|
soilInfo["plantName"]
|
|
|
|
|
|
)
|
2025-05-28 19:48:12 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
ts, hc = (
|
|
|
|
|
|
int(currentTime.timestamp()),
|
|
|
|
|
|
soilInfo["harvestCount"] + 1,
|
|
|
|
|
|
)
|
2025-05-28 19:48:12 +08:00
|
|
|
|
p1, p2, *rest = phase
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userSoil.updateUserSoilFields(
|
|
|
|
|
|
uid,
|
|
|
|
|
|
i,
|
2025-05-28 19:48:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
"harvestCount": hc,
|
2025-06-06 10:56:22 +08:00
|
|
|
|
"plantTime": ts - p1 - p2,
|
|
|
|
|
|
"matureTime": ts + p2 + sum(rest),
|
|
|
|
|
|
},
|
2025-05-28 19:48:12 +08:00
|
|
|
|
)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_afterHarvest.emit( # type: ignore
|
2025-06-06 10:56:22 +08:00
|
|
|
|
uid=uid, name=soilInfo["plantName"], num=number, soilIndex=i
|
|
|
|
|
|
)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
|
|
|
|
|
if experience > 0:
|
|
|
|
|
|
exp = await g_pDBService.user.getUserExpByUid(uid)
|
|
|
|
|
|
await g_pDBService.user.updateUserExpByUid(uid, exp + experience)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
harvestRecords.append(
|
|
|
|
|
|
g_sTranslation["harvest"]["exp"].format(
|
|
|
|
|
|
exp=experience,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
|
|
|
|
|
if harvestCount <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["harvest"]["no"]
|
2025-04-28 19:27:16 +08:00
|
|
|
|
else:
|
|
|
|
|
|
return "\n".join(harvestRecords)
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
logger.warning("收获操作失败!", e=e)
|
|
|
|
|
|
return g_sTranslation["harvest"]["error"]
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-03-21 00:25:20 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def eradicate(cls, uid: str) -> str:
|
|
|
|
|
|
"""铲除作物
|
|
|
|
|
|
TODO 缺少随意铲除作物 目前只能铲除荒废作物
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str: 返回
|
|
|
|
|
|
"""
|
2025-04-28 19:27:16 +08:00
|
|
|
|
soilNumber = await g_pDBService.user.getUserSoilByUid(uid)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_beforeEradicate.emit(uid=uid) # type: ignore
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
experience = 0
|
2025-04-28 19:27:16 +08:00
|
|
|
|
for i in range(1, soilNumber + 1):
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果没有种植
|
|
|
|
|
|
if not await g_pDBService.userSoil.isSoilPlanted(uid, i):
|
|
|
|
|
|
continue
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, i)
|
|
|
|
|
|
if not soilInfo:
|
|
|
|
|
|
continue
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果不是枯萎状态
|
|
|
|
|
|
if soilInfo.get("wiltStatus", 0) == 0:
|
|
|
|
|
|
continue
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
experience += 3
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if g_bIsDebug:
|
|
|
|
|
|
experience += 999
|
2025-05-29 18:20:03 +08:00
|
|
|
|
|
2025-06-29 21:31:09 +08:00
|
|
|
|
# 更新数据库操作
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userSoil.deleteUserSoil(uid, i)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-29 21:31:09 +08:00
|
|
|
|
await g_pDBService.userSoil.updateUserSoilFields(
|
|
|
|
|
|
uid,
|
|
|
|
|
|
i,
|
|
|
|
|
|
{
|
|
|
|
|
|
"plantName": "",
|
|
|
|
|
|
"plantTime": 0,
|
|
|
|
|
|
"matureTime": 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 铲除作物会将偷菜记录清空
|
|
|
|
|
|
await g_pDBService.userSteal.deleteStealRecord(uid, i)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
await g_pEventManager.m_afterEradicate.emit(uid=uid, soilIndex=i) # type: ignore
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
if experience > 0:
|
2025-04-28 19:27:16 +08:00
|
|
|
|
exp = await g_pDBService.user.getUserExpByUid(uid)
|
|
|
|
|
|
await g_pDBService.user.updateUserExpByUid(uid, exp + experience)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["eradicate"]["success"].format(exp=experience)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["eradicate"]["error"]
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def getUserPlantByUid(cls, uid: str) -> bytes:
|
|
|
|
|
|
"""获取用户作物仓库
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
bytes: 返回图片
|
|
|
|
|
|
"""
|
|
|
|
|
|
data_list = []
|
2025-06-06 10:56:22 +08:00
|
|
|
|
column_name = ["-", "作物名称", "数量", "单价", "总价", "是否可以上架交易行"]
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
plant = await g_pDBService.userPlant.getUserPlantByUid(uid)
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
2025-04-27 10:52:28 +08:00
|
|
|
|
if plant is None:
|
2025-03-20 18:06:38 +08:00
|
|
|
|
result = await ImageTemplate.table_page(
|
|
|
|
|
|
"作物仓库",
|
2025-04-27 17:00:58 +08:00
|
|
|
|
"出售示例:@小真寻 出售作物 大白菜 [数量]",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
column_name,
|
|
|
|
|
|
data_list,
|
|
|
|
|
|
)
|
|
|
|
|
|
return result.pic2bytes()
|
|
|
|
|
|
|
|
|
|
|
|
sell = ""
|
2025-04-27 17:00:58 +08:00
|
|
|
|
for name, count in plant.items():
|
2025-05-08 17:56:45 +08:00
|
|
|
|
plantInfo = await g_pDBService.plant.getPlantByName(name)
|
|
|
|
|
|
if not plantInfo:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
2025-04-27 10:52:28 +08:00
|
|
|
|
icon = ""
|
|
|
|
|
|
icon_path = g_sResourcePath / f"plant/{name}/icon.png"
|
|
|
|
|
|
if icon_path.exists():
|
|
|
|
|
|
icon = (icon_path, 33, 33)
|
|
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
if plantInfo["sell"]:
|
2025-04-27 10:52:28 +08:00
|
|
|
|
sell = "可以"
|
|
|
|
|
|
else:
|
|
|
|
|
|
sell = "不可以"
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
number = int(count) * plantInfo["price"]
|
|
|
|
|
|
|
|
|
|
|
|
data_list.append([icon, name, count, plantInfo["price"], number, sell])
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
result = await ImageTemplate.table_page(
|
|
|
|
|
|
"作物仓库",
|
2025-04-27 17:00:58 +08:00
|
|
|
|
"出售示例:@小真寻 出售作物 大白菜 [数量]",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
column_name,
|
|
|
|
|
|
data_list,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return result.pic2bytes()
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-03-21 00:25:20 +08:00
|
|
|
|
@classmethod
|
2025-03-21 18:14:50 +08:00
|
|
|
|
async def stealing(cls, uid: str, target: str) -> str:
|
|
|
|
|
|
"""偷菜
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
2025-03-21 18:14:50 +08:00
|
|
|
|
target (str): 被偷用户Uid
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
Returns:
|
2025-03-21 18:14:50 +08:00
|
|
|
|
str: 返回
|
2025-03-21 00:25:20 +08:00
|
|
|
|
"""
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 用户信息
|
2025-04-28 19:27:16 +08:00
|
|
|
|
userInfo = await g_pDBService.user.getUserInfoByUid(uid)
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
stealTime = userInfo.get("stealTime", "")
|
|
|
|
|
|
stealCount = int(userInfo["stealCount"])
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-05-30 11:22:32 +08:00
|
|
|
|
if stealTime == "" or not stealTime:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
stealTime = g_pToolManager.dateTime().date().today().strftime("%Y-%m-%d")
|
2025-04-28 19:27:16 +08:00
|
|
|
|
stealCount = 5
|
2025-06-06 10:56:22 +08:00
|
|
|
|
elif (
|
|
|
|
|
|
g_pToolManager.dateTime().date().fromisoformat(stealTime)
|
|
|
|
|
|
!= g_pToolManager.dateTime().date().today()
|
|
|
|
|
|
):
|
|
|
|
|
|
stealTime = g_pToolManager.dateTime().date().today().strftime("%Y-%m-%d")
|
2025-04-28 19:27:16 +08:00
|
|
|
|
stealCount = 5
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if stealCount <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["stealing"]["max"]
|
2025-04-28 19:27:16 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 获取用户解锁地块数量
|
2025-05-30 11:22:32 +08:00
|
|
|
|
soilNumber = await g_pDBService.user.getUserSoilByUid(target)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
harvestRecords: list[str] = []
|
2025-04-07 18:52:27 +08:00
|
|
|
|
isStealingNumber = 0
|
|
|
|
|
|
isStealingPlant = 0
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-04-28 19:27:16 +08:00
|
|
|
|
for i in range(1, soilNumber + 1):
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果没有种植
|
2025-05-30 11:22:32 +08:00
|
|
|
|
if not await g_pDBService.userSoil.isSoilPlanted(target, i):
|
2025-04-28 19:27:16 +08:00
|
|
|
|
continue
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-05-30 11:22:32 +08:00
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(target, i)
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if not soilInfo:
|
2025-04-07 18:52:27 +08:00
|
|
|
|
continue
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果是枯萎状态
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if soilInfo.get("wiltStatus", 1) == 1:
|
2025-04-07 18:52:27 +08:00
|
|
|
|
continue
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 作物信息
|
|
|
|
|
|
plantInfo = await g_pDBService.plant.getPlantByName(soilInfo["plantName"])
|
2025-05-08 17:56:45 +08:00
|
|
|
|
if not plantInfo:
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
currentTime = g_pToolManager.dateTime().now()
|
2025-06-06 10:56:22 +08:00
|
|
|
|
matureTime = g_pToolManager.dateTime().fromtimestamp(
|
|
|
|
|
|
int(soilInfo["matureTime"])
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
if currentTime >= matureTime:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果偷过,则跳过该土地
|
2025-04-28 19:27:16 +08:00
|
|
|
|
if await g_pDBService.userSteal.hasStealed(target, i, uid):
|
2025-06-06 10:56:22 +08:00
|
|
|
|
isStealingNumber += 1
|
2025-04-07 18:52:27 +08:00
|
|
|
|
continue
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
stealingNumber = plantInfo[
|
|
|
|
|
|
"harvest"
|
|
|
|
|
|
] - await g_pDBService.userSteal.getTotalStolenCount(target, i)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
randomNumber = random.choice([1, 2])
|
|
|
|
|
|
randomNumber = min(randomNumber, stealingNumber)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
if randomNumber > 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userPlant.addUserPlantByUid(
|
|
|
|
|
|
uid, soilInfo["plantName"], randomNumber
|
|
|
|
|
|
)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
harvestRecords.append(
|
|
|
|
|
|
g_sTranslation["stealing"]["info"].format(
|
|
|
|
|
|
name=soilInfo["plantName"], num=randomNumber
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
isStealingPlant += 1
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果将作物偷完,就直接更新状态 并记录用户偷取过
|
|
|
|
|
|
if plantInfo["harvest"] - randomNumber + stealingNumber == 0:
|
|
|
|
|
|
# 如果作物 是最后一阶段作物且偷完 则直接枯萎
|
|
|
|
|
|
if soilInfo["harvestCount"] + 1 >= plantInfo["crop"]:
|
|
|
|
|
|
await g_pDBService.userSoil.updateUserSoil(
|
|
|
|
|
|
target, i, "wiltStatus", 1
|
|
|
|
|
|
)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
phase = await g_pDBService.plant.getPlantPhaseByName(
|
|
|
|
|
|
soilInfo["plantName"]
|
|
|
|
|
|
)
|
2025-05-28 19:48:12 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
ts, hc = (
|
|
|
|
|
|
int(currentTime.timestamp()),
|
|
|
|
|
|
soilInfo["harvestCount"] + 1,
|
|
|
|
|
|
)
|
2025-05-28 19:48:12 +08:00
|
|
|
|
p1, p2, *rest = phase
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userSoil.updateUserSoilFields(
|
|
|
|
|
|
uid,
|
|
|
|
|
|
i,
|
2025-05-28 19:48:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
"harvestCount": hc,
|
2025-06-06 10:56:22 +08:00
|
|
|
|
"plantTime": ts - p1 - p2,
|
|
|
|
|
|
"matureTime": ts + p2 + sum(rest),
|
|
|
|
|
|
},
|
2025-05-28 19:48:12 +08:00
|
|
|
|
)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userSteal.addStealRecord(
|
|
|
|
|
|
target,
|
|
|
|
|
|
i,
|
|
|
|
|
|
uid,
|
|
|
|
|
|
randomNumber,
|
|
|
|
|
|
int(g_pToolManager.dateTime().now().timestamp()),
|
|
|
|
|
|
)
|
2025-05-09 18:20:00 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.userSteal.addStealRecord(
|
|
|
|
|
|
target,
|
|
|
|
|
|
i,
|
|
|
|
|
|
uid,
|
|
|
|
|
|
randomNumber,
|
|
|
|
|
|
int(g_pToolManager.dateTime().now().timestamp()),
|
|
|
|
|
|
)
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
if isStealingPlant <= 0 and isStealingNumber <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["stealing"]["noPlant"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
elif isStealingPlant <= 0 and isStealingNumber > 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["stealing"]["repeat"]
|
2025-03-21 00:25:20 +08:00
|
|
|
|
else:
|
2025-04-28 19:27:16 +08:00
|
|
|
|
stealCount -= 1
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await g_pDBService.user.updateStealCountByUid(uid, stealTime, stealCount)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-03-21 18:14:50 +08:00
|
|
|
|
return "\n".join(harvestRecords)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def reclamationCondition(cls, uid: str) -> str:
|
2025-06-29 01:45:24 +08:00
|
|
|
|
"""获取开垦条件
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str: 返回条件文本信息
|
|
|
|
|
|
"""
|
2025-04-28 19:27:16 +08:00
|
|
|
|
userInfo = await g_pDBService.user.getUserInfoByUid(uid)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
rec = g_pJsonManager.m_pLevel["reclamation"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
try:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if userInfo["soil"] >= 30:
|
|
|
|
|
|
return g_sTranslation["reclamation"]["perfect"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
rec = rec[f"{userInfo['soil'] + 1}"]
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
level = rec["level"]
|
|
|
|
|
|
point = rec["point"]
|
|
|
|
|
|
item = rec["item"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
str = ""
|
|
|
|
|
|
if len(item) == 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
str = g_sTranslation["reclamation"]["next"].format(
|
|
|
|
|
|
level=level, num=point
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
str = g_sTranslation["reclamation"]["next2"].format(
|
|
|
|
|
|
level=level, num=point, item=item
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
return str
|
2025-06-06 10:56:22 +08:00
|
|
|
|
except Exception:
|
|
|
|
|
|
return g_sTranslation["reclamation"]["error"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
async def reclamation(cls, uid: str) -> str:
|
2025-06-29 01:45:24 +08:00
|
|
|
|
"""开垦
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str: _description_
|
|
|
|
|
|
"""
|
2025-04-28 19:27:16 +08:00
|
|
|
|
userInfo = await g_pDBService.user.getUserInfoByUid(uid)
|
|
|
|
|
|
level = await g_pDBService.user.getUserLevelByUid(uid)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
rec = g_pJsonManager.m_pLevel["reclamation"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
try:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if userInfo["soil"] >= 30:
|
|
|
|
|
|
return g_sTranslation["reclamation"]["perfect"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
rec = rec[f"{userInfo['soil'] + 1}"]
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
levelFileter = rec["level"]
|
|
|
|
|
|
point = rec["point"]
|
2025-06-29 01:45:24 +08:00
|
|
|
|
# item = rec["item"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
if level[0] < levelFileter:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
return g_sTranslation["reclamation"]["nextLevel"].format(
|
|
|
|
|
|
level=level[0], next=levelFileter
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if userInfo["point"] < point:
|
|
|
|
|
|
return g_sTranslation["reclamation"]["noNum"].format(num=point)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# TODO 缺少判断消耗的item
|
|
|
|
|
|
await g_pDBService.user.updateUserPointByUid(uid, userInfo["point"] - point)
|
|
|
|
|
|
await g_pDBService.user.updateUserSoilByUid(uid, userInfo["soil"] + 1)
|
|
|
|
|
|
|
|
|
|
|
|
return g_sTranslation["reclamation"]["success"]
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
return g_sTranslation["reclamation"]["error1"]
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
@classmethod
|
|
|
|
|
|
async def soilUpgradeCondition(cls, uid: str, soilIndex: int) -> str:
|
|
|
|
|
|
"""获取土地升级条件
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
soilIndex (str): 土地索引
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str: 返回土地升级条件
|
|
|
|
|
|
"""
|
|
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
|
|
|
|
|
|
|
|
|
|
|
|
if not soilInfo:
|
|
|
|
|
|
return g_sTranslation["soilInfo"]["error"]
|
|
|
|
|
|
|
|
|
|
|
|
soilLevel = soilInfo.get("soilLevel", 0) + 1
|
|
|
|
|
|
if soilLevel >= g_iSoilLevelMax:
|
|
|
|
|
|
return g_sTranslation["soilInfo"]["error1"]
|
|
|
|
|
|
|
|
|
|
|
|
# 获取用户当前土地 的下一级土地 数量
|
|
|
|
|
|
countSoil = await g_pDBService.userSoil.countSoilByLevel(uid, soilLevel)
|
|
|
|
|
|
|
|
|
|
|
|
# 获取升级所需
|
|
|
|
|
|
soilLevelText = await g_pDBService.userSoil.getSoilLevel(soilLevel)
|
|
|
|
|
|
fileter = g_pJsonManager.m_pSoil["upgrade"][soilLevelText][countSoil]
|
|
|
|
|
|
|
2025-06-29 21:31:09 +08:00
|
|
|
|
nextLevel = await g_pDBService.userSoil.getSoilLevelText(soilLevel)
|
|
|
|
|
|
|
|
|
|
|
|
lines = ["将土地升级至:" + nextLevel + "。", "所需:"]
|
2025-06-29 01:45:24 +08:00
|
|
|
|
fields = [
|
|
|
|
|
|
("level", "等级"),
|
|
|
|
|
|
("point", "金币"),
|
|
|
|
|
|
("vipPoint", "点券"),
|
|
|
|
|
|
]
|
|
|
|
|
|
for key, label in fields:
|
|
|
|
|
|
value = fileter.get(key, 0)
|
|
|
|
|
|
if value > 0:
|
|
|
|
|
|
lines.append(f"{label}:{value}")
|
|
|
|
|
|
|
|
|
|
|
|
items = fileter.get("item", {})
|
|
|
|
|
|
for name, qty in items.items():
|
|
|
|
|
|
if qty:
|
|
|
|
|
|
lines.append(f"{name}:{qty}")
|
|
|
|
|
|
|
|
|
|
|
|
lines.append("回复“是”将执行升级")
|
|
|
|
|
|
|
|
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
async def soilUpgrade(cls, uid: str, soilIndex: int) -> str:
|
|
|
|
|
|
"""土地升级
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
uid (str): 用户Uid
|
|
|
|
|
|
soilIndex (int): 土地索引
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
str:
|
|
|
|
|
|
"""
|
|
|
|
|
|
userInfo = await g_pDBService.user.getUserInfoByUid(uid)
|
|
|
|
|
|
soilInfo = await g_pDBService.userSoil.getUserSoil(uid, soilIndex)
|
|
|
|
|
|
|
|
|
|
|
|
if not soilInfo:
|
|
|
|
|
|
return g_sTranslation["soilInfo"]["error"]
|
|
|
|
|
|
|
|
|
|
|
|
soilLevel = soilInfo.get("soilLevel", 0) + 1
|
|
|
|
|
|
if soilLevel >= g_iSoilLevelMax:
|
|
|
|
|
|
return g_sTranslation["soilInfo"]["error1"]
|
|
|
|
|
|
|
|
|
|
|
|
countSoil = await g_pDBService.userSoil.countSoilByLevel(uid, soilLevel)
|
|
|
|
|
|
|
|
|
|
|
|
soilLevelText = await g_pDBService.userSoil.getSoilLevel(soilLevel)
|
|
|
|
|
|
fileter = g_pJsonManager.m_pSoil["upgrade"][soilLevelText][countSoil]
|
|
|
|
|
|
|
|
|
|
|
|
getters = {
|
|
|
|
|
|
"level": (await g_pDBService.user.getUserLevelByUid(uid))[0],
|
|
|
|
|
|
"point": userInfo.get("point", 0),
|
|
|
|
|
|
"vipPoint": userInfo.get("vipPoint", 0),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
requirements = {
|
|
|
|
|
|
"level": "等级",
|
|
|
|
|
|
"point": "金币",
|
|
|
|
|
|
"vipPoint": "点券",
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for key, val in getters.items():
|
|
|
|
|
|
need = fileter.get(key, 0)
|
|
|
|
|
|
if val < need:
|
|
|
|
|
|
return f"你的{requirements[key]}不够哦~"
|
|
|
|
|
|
|
|
|
|
|
|
# 缺少item判断
|
|
|
|
|
|
|
|
|
|
|
|
# 更新数据库字段
|
|
|
|
|
|
await g_pDBService.userSoil.updateUserSoil(
|
|
|
|
|
|
uid, soilIndex, "soilLevel", soilLevel
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# 如果有作物的话直接成熟
|
|
|
|
|
|
await g_pDBService.userSoil.matureNow(uid, soilIndex)
|
|
|
|
|
|
|
|
|
|
|
|
# 更新数据库字段
|
2025-06-29 21:31:09 +08:00
|
|
|
|
point = userInfo.get("point", 0) - fileter.get("point", 0)
|
|
|
|
|
|
await g_pDBService.user.updateUserPointByUid(uid, point)
|
2025-06-29 01:45:24 +08:00
|
|
|
|
|
2025-06-29 21:31:09 +08:00
|
|
|
|
vipPoint = userInfo.get("vipPoint", 0) - fileter.get("vipPoint", 0)
|
|
|
|
|
|
await g_pDBService.user.updateUserVipPointByUid(uid, vipPoint)
|
2025-06-29 01:45:24 +08:00
|
|
|
|
|
|
|
|
|
|
return g_sTranslation["soilInfo"]["success"].format(
|
|
|
|
|
|
name=await g_pDBService.userSoil.getSoilLevelText(soilLevel),
|
|
|
|
|
|
text=g_sTranslation["soilInfo"][soilLevelText],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
g_pFarmManager = CFarmManager()
|