🐛 修复农场图片异常BUG
✨ 新增部分功能和指令 📝 初步完善部分资源文件
30
__init__.py
@ -1,7 +1,7 @@
|
||||
from nonebot import get_driver
|
||||
from nonebot.plugin import PluginMetadata
|
||||
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.configs.utils import Command, PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
@ -11,19 +11,31 @@ from .database import g_pSqlManager
|
||||
from .farm.farm import g_pFarmManager
|
||||
from .farm.shop import g_pShopManager
|
||||
|
||||
__plugin_meta = PluginMetadata(
|
||||
name="真寻的农场",
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="真寻农场",
|
||||
description="快乐的农场时光",
|
||||
usage="""
|
||||
农场快乐时光
|
||||
你也要种地?
|
||||
指令:
|
||||
我的农场
|
||||
我的农场币
|
||||
种子商店
|
||||
购买种子 [作物/种子名称] [数量]
|
||||
我的种子
|
||||
播种 [作物/种子名称] [数量]
|
||||
收获
|
||||
铲除
|
||||
我的作物
|
||||
出售作物 [作物/种子名称] [数量]
|
||||
购买农场币 [数量]
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="molanp",
|
||||
author="Art_Sakura",
|
||||
version="1.0",
|
||||
menu_type="群内小游戏",
|
||||
).dict(),
|
||||
commands=[Command(command="我的农场")],
|
||||
menu_type="群内小游戏"
|
||||
).to_dict(),
|
||||
)
|
||||
|
||||
driver = get_driver()
|
||||
|
||||
|
||||
@ -36,8 +48,6 @@ async def start():
|
||||
# 初始化读取Json
|
||||
await g_pJsonManager.init()
|
||||
|
||||
# await g_pFarmManager.harvest("1754798088")
|
||||
|
||||
# 析构函数
|
||||
@driver.on_shutdown
|
||||
async def shutdown():
|
||||
|
||||
76
command.py
@ -40,7 +40,10 @@ diuse_farm = on_alconna(
|
||||
Subcommand("my-seed", help_text="我的种子"),
|
||||
Subcommand("sowing", Args["name?", str]["num?", int], help_text="播种"),
|
||||
Subcommand("harvest", help_text="收获"),
|
||||
Subcommand("my-plant", help_text="我的作物")
|
||||
Subcommand("eradicate", help_text="铲除"),
|
||||
Subcommand("my-plant", help_text="我的作物"),
|
||||
Subcommand("sell-plant", Args["name?", str]["num?", int], help_text="出售作物"),
|
||||
Subcommand("buy-point", Args["num?", int], help_text="购买农场币")
|
||||
),
|
||||
priority=5,
|
||||
rule=to_me(),
|
||||
@ -183,6 +186,26 @@ async def _(session: Uninfo):
|
||||
result = await g_pFarmManager.harvest(uid)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"铲除",
|
||||
command="我的农场",
|
||||
arguments=["eradicate"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
@diuse_farm.assign("eradicate")
|
||||
async def _(session: Uninfo):
|
||||
uid = str(session.user.id)
|
||||
point = await g_pSqlManager.getUserPointByUid(uid)
|
||||
|
||||
if point < 0:
|
||||
await MessageUtils.build_message("尚未开通农场").send()
|
||||
return None
|
||||
|
||||
result = await g_pFarmManager.eradicate(uid)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"我的作物",
|
||||
command="我的农场",
|
||||
@ -201,3 +224,54 @@ async def _(session: Uninfo):
|
||||
|
||||
result = await g_pFarmManager.getUserPlantByUid(uid)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"出售作物(?P<name>.*?)",
|
||||
command="我的农场",
|
||||
arguments=["sell-plant", "{name}"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
@diuse_farm.assign("sell-plant")
|
||||
async def _(session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("num", 1),):
|
||||
if not name.available:
|
||||
await MessageUtils.build_message(
|
||||
"请在指令后跟需要出售的作物名称"
|
||||
).finish(reply_to=True)
|
||||
|
||||
uid = str(session.user.id)
|
||||
point = await g_pSqlManager.getUserPointByUid(uid)
|
||||
|
||||
if point < 0:
|
||||
await MessageUtils.build_message("尚未开通农场").send()
|
||||
return None
|
||||
|
||||
result = await g_pFarmManager.sellPlantByUid(uid, name.result, num.result)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"购买农场币(.*?)",
|
||||
command="我的农场",
|
||||
arguments=["buy-point"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
@diuse_farm.assign("sell-plant")
|
||||
async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)):
|
||||
if num.result <= 0:
|
||||
await MessageUtils.build_message(
|
||||
"请在指令后跟需要购买农场币的数量"
|
||||
).finish(reply_to=True)
|
||||
|
||||
uid = str(session.user.id)
|
||||
point = await g_pSqlManager.getUserPointByUid(uid)
|
||||
|
||||
if point < 0:
|
||||
await MessageUtils.build_message("尚未开通农场").send()
|
||||
return None
|
||||
|
||||
result = await g_pFarmManager.buyPointByUid(uid, num.result)
|
||||
await MessageUtils.build_message(result).send(reply_to=True)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,23 +6,23 @@
|
||||
"experience: 收获经验",
|
||||
"harvest: 收获数量",
|
||||
"price: 单价",
|
||||
"time: 成熟时间 单位:分钟",
|
||||
"time: 成熟时间 小时",
|
||||
"crop: 作物可以收几次",
|
||||
"again: 再次成熟时间 单位:分钟",
|
||||
"again: 再次成熟时间 单位:小时",
|
||||
"phase: 阶段 目前为 成熟时间 / 阶段 来显示每阶段图片",
|
||||
"general: 第一阶段是否为通用阶段素材",
|
||||
"sell: 是否可以上架交易行"
|
||||
],
|
||||
"plant":
|
||||
{
|
||||
"大白菜":
|
||||
"胡萝卜":
|
||||
{
|
||||
"level": 0,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 780,
|
||||
"experience": 18,
|
||||
"harvest": 17,
|
||||
"price": 21,
|
||||
"time": 13,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
@ -33,24 +33,10 @@
|
||||
{
|
||||
"level": 0,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 600,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"胡萝卜":
|
||||
{
|
||||
"level": 0,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 15,
|
||||
"harvest": 16,
|
||||
"price": 17,
|
||||
"time": 10,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
@ -61,10 +47,24 @@
|
||||
{
|
||||
"level": 0,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 10,
|
||||
"harvest": 25,
|
||||
"price": 6,
|
||||
"time": 8,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"大白菜":
|
||||
{
|
||||
"level": 1,
|
||||
"limit": 0,
|
||||
"experience": 19,
|
||||
"harvest": 17,
|
||||
"price": 22,
|
||||
"time": 14,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
@ -73,68 +73,68 @@
|
||||
},
|
||||
"大蒜":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 1,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 19,
|
||||
"harvest": 17,
|
||||
"price": 22,
|
||||
"time": 14,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"phase": 6,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"水稻":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 2,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 19,
|
||||
"harvest": 18,
|
||||
"price": 21,
|
||||
"time": 14,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"phase": 6,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"小麦":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 2,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 19,
|
||||
"harvest": 18,
|
||||
"price": 21,
|
||||
"time": 14,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"phase": 6,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"玉米":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 3,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 19,
|
||||
"harvest": 17,
|
||||
"price": 23,
|
||||
"time": 14,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"phase": 6,
|
||||
"general": true,
|
||||
"sell": false
|
||||
},
|
||||
"油菜":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 4,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 29,
|
||||
"harvest": 23,
|
||||
"price": 24,
|
||||
"time": 17,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
@ -143,15 +143,15 @@
|
||||
},
|
||||
"生菜":
|
||||
{
|
||||
"level": 0,
|
||||
"level": 4,
|
||||
"limit": 0,
|
||||
"experience": 5,
|
||||
"harvest": 30,
|
||||
"price": 5,
|
||||
"time": 5,
|
||||
"experience": 25,
|
||||
"harvest": 21,
|
||||
"price": 24,
|
||||
"time": 19,
|
||||
"crop": 1,
|
||||
"again": 0,
|
||||
"phase": 5,
|
||||
"phase": 6,
|
||||
"general": true,
|
||||
"sell": false
|
||||
}
|
||||
|
||||
@ -34,123 +34,123 @@
|
||||
},
|
||||
"7":
|
||||
{
|
||||
"x": 1242,
|
||||
"y": 611
|
||||
"x": 1237,
|
||||
"y": 606
|
||||
},
|
||||
"8":
|
||||
{
|
||||
"x": 1343,
|
||||
"y": 670
|
||||
"x": 1350,
|
||||
"y": 665
|
||||
},
|
||||
"9":
|
||||
{
|
||||
"x": 1462,
|
||||
"y": 729
|
||||
"x": 1457,
|
||||
"y": 724
|
||||
},
|
||||
"10":
|
||||
{
|
||||
"x": 1572,
|
||||
"y": 788
|
||||
"x": 1567,
|
||||
"y": 783
|
||||
},
|
||||
"11":
|
||||
{
|
||||
"x": 1682,
|
||||
"y": 847
|
||||
"x": 1677,
|
||||
"y": 842
|
||||
},
|
||||
"12":
|
||||
{
|
||||
"x": 1792,
|
||||
"y": 906
|
||||
"x": 1787,
|
||||
"y": 901
|
||||
},
|
||||
"13":
|
||||
{
|
||||
"x": 1123,
|
||||
"y": 670
|
||||
"x": 1116,
|
||||
"y": 663
|
||||
},
|
||||
"14":
|
||||
{
|
||||
"x": 1233,
|
||||
"y": 729
|
||||
"x": 1226,
|
||||
"y": 722
|
||||
},
|
||||
"15":
|
||||
{
|
||||
"x": 1343,
|
||||
"y": 788
|
||||
"x": 1336,
|
||||
"y": 782
|
||||
},
|
||||
"16":
|
||||
{
|
||||
"x": 1462,
|
||||
"y": 847
|
||||
"x": 1455,
|
||||
"y": 840
|
||||
},
|
||||
"17":
|
||||
{
|
||||
"x": 1572,
|
||||
"y": 906
|
||||
"x": 1565,
|
||||
"y": 899
|
||||
},
|
||||
"18":
|
||||
{
|
||||
"x": 1678,
|
||||
"y": 965
|
||||
"x": 1671,
|
||||
"y": 958
|
||||
},
|
||||
"19":
|
||||
{
|
||||
"x": 1013,
|
||||
"y": 729
|
||||
"x": 1002,
|
||||
"y": 720
|
||||
},
|
||||
"20":
|
||||
{
|
||||
"x": 1114,
|
||||
"y": 788
|
||||
"x": 1105,
|
||||
"y": 779
|
||||
},
|
||||
"21":
|
||||
{
|
||||
"x": 1233,
|
||||
"y": 847
|
||||
"x": 1224,
|
||||
"y": 838
|
||||
},
|
||||
"22":
|
||||
{
|
||||
"x": 1352,
|
||||
"y": 906
|
||||
"x": 1343,
|
||||
"y": 897
|
||||
},
|
||||
"23":
|
||||
{
|
||||
"x": 1458,
|
||||
"y": 965
|
||||
"x": 1449,
|
||||
"y": 956
|
||||
},
|
||||
"24":
|
||||
{
|
||||
"x": 1572,
|
||||
"y": 1024
|
||||
"x": 1563,
|
||||
"y": 1015
|
||||
},
|
||||
"25":
|
||||
{
|
||||
"x": 894,
|
||||
"y": 788
|
||||
"x": 883,
|
||||
"y": 777
|
||||
},
|
||||
"26":
|
||||
{
|
||||
"x": 1004,
|
||||
"y": 847
|
||||
"x": 995,
|
||||
"y": 836
|
||||
},
|
||||
"27":
|
||||
{
|
||||
"x": 1123,
|
||||
"y": 906
|
||||
"x": 1112,
|
||||
"y": 895
|
||||
},
|
||||
"28":
|
||||
{
|
||||
"x": 1233,
|
||||
"y": 965
|
||||
"x": 1222,
|
||||
"y": 954
|
||||
},
|
||||
"29":
|
||||
{
|
||||
"x": 1347,
|
||||
"y": 1024
|
||||
"x": 1336,
|
||||
"y": 1013
|
||||
},
|
||||
"30":
|
||||
{
|
||||
"x": 1462,
|
||||
"y": 1083
|
||||
"x": 1451,
|
||||
"y": 1072
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
database.py
@ -236,6 +236,46 @@ class CSqlManager:
|
||||
logger.error(f"更新失败: {e}")
|
||||
return -1
|
||||
|
||||
@classmethod
|
||||
async def getUserExpByUid(cls, uid: str) -> int:
|
||||
"""根据用户Uid获取用户经验
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
|
||||
Returns:
|
||||
int: 用户经验值
|
||||
"""
|
||||
if len(uid) <= 0:
|
||||
return -1
|
||||
|
||||
try:
|
||||
async with cls.m_pDB.execute(f"SELECT exp FROM user WHERE uid = '{uid}'") as cursor:
|
||||
async for row in cursor:
|
||||
return int(row[0])
|
||||
|
||||
return -1
|
||||
except Exception as e:
|
||||
logger.warning(f"getUserLevelByUid查询失败: {e}")
|
||||
return -1
|
||||
|
||||
@classmethod
|
||||
async def UpdateUserExpByUid(cls, uid: str, exp: int) -> bool:
|
||||
"""根据用户Uid刷新用户经验
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
|
||||
Returns:
|
||||
bool: 是否成功
|
||||
"""
|
||||
if len(uid) <= 0:
|
||||
return False
|
||||
|
||||
sql = f"UPDATE user SET exp = '{exp}' WHERE uid = '{uid}'"
|
||||
|
||||
return await cls.executeDB(sql)
|
||||
|
||||
@classmethod
|
||||
async def getUserLevelByUid(cls, uid: str) -> int:
|
||||
"""根据用户Uid获取用户等级
|
||||
@ -330,8 +370,10 @@ class CSqlManager:
|
||||
if len(uid) <= 0:
|
||||
return False
|
||||
|
||||
if len(plant) <= 0:
|
||||
if len(plant) <= 0 and status == 4:
|
||||
s = f",,,{status}"
|
||||
elif len(plant) <= 0 and status != 4:
|
||||
s = ""
|
||||
else:
|
||||
#获取种子信息 这里能崩我吃
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][plant] # type: ignore
|
||||
|
||||
177
farm/farm.py
@ -1,11 +1,13 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from io import StringIO
|
||||
from math import exp
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from zhenxun.models.user_console import UserConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
from zhenxun.utils.enum import GoldHandle
|
||||
from zhenxun.utils.image_utils import ImageTemplate
|
||||
|
||||
from ..config import g_pJsonManager, g_sResourcePath
|
||||
@ -13,6 +15,26 @@ from ..database import g_pSqlManager
|
||||
|
||||
|
||||
class CFarmManager:
|
||||
@classmethod
|
||||
async def buyPointByUid(cls, uid: str, num: int) -> str:
|
||||
if num <= 0:
|
||||
return "你是怎么做到购买不是正数的农场币的"
|
||||
|
||||
user = await UserConsole.get_user(uid)
|
||||
|
||||
point = num // 2
|
||||
|
||||
if user.gold < point:
|
||||
return "你的金币不足"
|
||||
|
||||
await UserConsole.reduce_gold(uid, point, GoldHandle.BUY , 'zhenxun_plugin_farm')
|
||||
|
||||
p = await g_pSqlManager.getUserPointByUid(uid)
|
||||
|
||||
await g_pSqlManager.updateUserPointByUid(uid, point + p)
|
||||
|
||||
return f"充值{num}农场币成功,当前农场币:{point + p}"
|
||||
|
||||
|
||||
@classmethod
|
||||
async def drawFarmByUid(cls, uid: str) -> bytes:
|
||||
@ -101,13 +123,14 @@ class CFarmManager:
|
||||
return False, None, False
|
||||
else:
|
||||
soilInfo = soilInfo.split(',')
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][soilInfo[0]] # type: ignore
|
||||
|
||||
if int(soilInfo[3]) == 4:
|
||||
plant = BuildImage(background = g_sResourcePath / f"plant/basic/9.png")
|
||||
|
||||
await plant.resize(0, 150, 212)
|
||||
return True, plant, False
|
||||
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][soilInfo[0]] # type: ignore
|
||||
|
||||
currentTime = datetime.now()
|
||||
matureTime = datetime.fromtimestamp(int(soilInfo[2]))
|
||||
|
||||
@ -120,9 +143,9 @@ class CFarmManager:
|
||||
plantedTime = datetime.fromtimestamp(int(soilInfo[1]))
|
||||
|
||||
elapsedTime = currentTime - plantedTime
|
||||
elapsedMinutes = elapsedTime.total_seconds() / 60
|
||||
elapsedHour = elapsedTime.total_seconds() / 60 / 60
|
||||
|
||||
currentStage = int(elapsedMinutes / (plantInfo['time'] / (plantInfo['phase'] - 1)))
|
||||
currentStage = int(elapsedHour / (plantInfo['time'] / (plantInfo['phase'] - 1)))
|
||||
|
||||
#TODO 缺少判断部分种子是否是通用0阶段图片
|
||||
if currentStage <= 0:
|
||||
@ -151,9 +174,9 @@ class CFarmManager:
|
||||
"数量",
|
||||
"收获经验",
|
||||
"收获数量",
|
||||
"成熟时间(分钟)",
|
||||
"成熟时间(小时)",
|
||||
"收获次数",
|
||||
"再次成熟时间(分钟)",
|
||||
"再次成熟时间(小时)",
|
||||
"是否可以上架交易行"
|
||||
]
|
||||
|
||||
@ -290,23 +313,30 @@ class CFarmManager:
|
||||
|
||||
plant: Dict[str, int] = {}
|
||||
harvest_records: List[str] = []
|
||||
experience = 0
|
||||
|
||||
for (soil_name, (status, info)) in zip(soilNames, soilStatuses):
|
||||
if not status:
|
||||
soil_info = info.split(',')
|
||||
plant_id = soil_info[0]
|
||||
plant_info = g_pJsonManager.m_pPlant['plant'][plant_id] # type: ignore
|
||||
soilInfo = info.split(',')
|
||||
plantId = soilInfo[0]
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][plantId] # type: ignore
|
||||
|
||||
current_time = datetime.now()
|
||||
mature_time = datetime.fromtimestamp(int(soil_info[2]))
|
||||
currentTime = datetime.now()
|
||||
matureTime = datetime.fromtimestamp(int(soilInfo[2]))
|
||||
|
||||
if current_time >= mature_time:
|
||||
plant[plant_id] = plant.get(plant_id, 0) + plant_info['harvest']
|
||||
harvest_records.append(f"收获作物:{plant_id},数量为:{plant_info['harvest']}")
|
||||
if currentTime >= matureTime:
|
||||
plant[plantId] = plant.get(plantId, 0) + plantInfo['harvest']
|
||||
experience += plantInfo['experience']
|
||||
harvest_records.append(f"收获作物:{plantId},数量为:{plantInfo['harvest']},经验为:{plantInfo['experience']}")
|
||||
|
||||
# 批量更新数据库操作
|
||||
await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soil_name, "", 4)
|
||||
|
||||
if experience > 0:
|
||||
harvest_records.append(f"\t累计获得经验:{experience}")
|
||||
exp = await g_pSqlManager.getUserExpByUid(uid)
|
||||
await g_pSqlManager.UpdateUserExpByUid(uid, exp + experience)
|
||||
|
||||
if not plant:
|
||||
return "可收获作物为0哦~ 不要试图拔苗助长"
|
||||
else:
|
||||
@ -318,6 +348,44 @@ class CFarmManager:
|
||||
|
||||
return "\n".join(harvest_records)
|
||||
|
||||
@classmethod
|
||||
async def eradicate(cls, uid: str) -> str:
|
||||
"""铲除作物
|
||||
TODO 缺少随意铲除作物 目前只能铲除荒废作物
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
|
||||
Returns:
|
||||
str: 返回
|
||||
"""
|
||||
|
||||
soilNumber = await g_pSqlManager.getUserLevelByUid(uid)
|
||||
soilUnlock = g_pJsonManager.m_pLevel['soil'] # type: ignore
|
||||
|
||||
soilNames = [f"soil{i + 1}" for i, level in enumerate(soilUnlock) if soilNumber >= level]
|
||||
soilStatuses = await asyncio.gather(*[
|
||||
g_pSqlManager.getUserSoilStatusBySoilID(uid, name)
|
||||
for name in soilNames
|
||||
])
|
||||
|
||||
experience = 0
|
||||
for (soil_name, (status, info)) in zip(soilNames, soilStatuses):
|
||||
if not status:
|
||||
soilInfo = info.split(',')
|
||||
if int(soilInfo[3]) == 4:
|
||||
experience += 3
|
||||
|
||||
# 批量更新数据库操作
|
||||
await g_pSqlManager.updateUserSoilStatusByPlantName(uid, soil_name, "", 0)
|
||||
|
||||
if experience > 0:
|
||||
exp = await g_pSqlManager.getUserExpByUid(uid)
|
||||
await g_pSqlManager.UpdateUserExpByUid(uid, exp + experience)
|
||||
|
||||
return f"成功铲除荒废作物,累计获得经验:{experience}"
|
||||
else:
|
||||
return "没有可以铲除的作物"
|
||||
|
||||
@classmethod
|
||||
async def getUserPlantByUid(cls, uid: str) -> bytes:
|
||||
"""获取用户作物仓库
|
||||
@ -391,4 +459,83 @@ class CFarmManager:
|
||||
|
||||
return result.pic2bytes()
|
||||
|
||||
@classmethod
|
||||
async def sellPlantByUid(cls, uid: str, name: str = "", num: int = 1) -> str:
|
||||
"""出售作物
|
||||
|
||||
Args:
|
||||
uid (str): 用户Uid
|
||||
|
||||
Returns:
|
||||
str:
|
||||
"""
|
||||
|
||||
plant = await g_pSqlManager.getUserPlantByUid(uid)
|
||||
|
||||
if plant == None:
|
||||
return "你仓库没有可以出售的作物"
|
||||
|
||||
point = 0
|
||||
totalSold = 0
|
||||
remainingItems = []
|
||||
|
||||
items = plant.split(',')
|
||||
if len(name) <= 0:
|
||||
#出售全部
|
||||
for item in items:
|
||||
if '|' in item:
|
||||
plant_name, count_str = item.split('|', 1)
|
||||
try:
|
||||
count = int(count_str)
|
||||
plant_info = g_pJsonManager.m_pPlant['plant'][plant_name] # type: ignore
|
||||
point += plant_info['price'] * count
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
await g_pSqlManager.updateUserPlantByUid(uid, "") # 清空仓库
|
||||
else:
|
||||
for item in items:
|
||||
if '|' in item:
|
||||
plantName, countStr = item.split('|', 1)
|
||||
try:
|
||||
count = int(countStr)
|
||||
if plantName == name:
|
||||
sellAmount = min(num, count)
|
||||
totalSold += sellAmount
|
||||
remaining = count - sellAmount
|
||||
|
||||
if remaining > 0:
|
||||
remainingItems.append(f"{plantName}|{remaining}")
|
||||
|
||||
num -= sellAmount
|
||||
if num == 0:
|
||||
break
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
if num > 0:
|
||||
return f"出售作物{name}出错:数量不足"
|
||||
|
||||
#计算收益
|
||||
try:
|
||||
plantInfo = g_pJsonManager.m_pPlant['plant'][name] # type: ignore
|
||||
totalPoint = plantInfo['price'] * totalSold
|
||||
except KeyError:
|
||||
return f"出售作物{name}出错:作物不存在"
|
||||
|
||||
#更新剩余作物
|
||||
remainingPlant = ','.join(remainingItems) if remainingItems else ""
|
||||
await g_pSqlManager.updateUserPlantByUid(uid, remainingPlant)
|
||||
|
||||
#更新农场币
|
||||
p = await g_pSqlManager.getUserPointByUid(uid)
|
||||
await g_pSqlManager.updateUserPointByUid(uid, p + totalPoint)
|
||||
|
||||
if name:
|
||||
return f"成功出售{name},获得农场币:{totalPoint}"
|
||||
else:
|
||||
return f"成功出售所有作物,获得农场币:{totalPoint}"
|
||||
|
||||
|
||||
|
||||
g_pFarmManager = CFarmManager()
|
||||
|
||||
@ -26,9 +26,9 @@ class CShopManager:
|
||||
"种子单价",
|
||||
"收获经验",
|
||||
"收获数量",
|
||||
"成熟时间(分钟)",
|
||||
"成熟时间(小时)",
|
||||
"收获次数",
|
||||
"再次成熟时间(分钟)",
|
||||
"再次成熟时间(小时)",
|
||||
"是否可以上架交易行"
|
||||
]
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 17 KiB |
BIN
resource/plant/大白菜/1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
resource/plant/大白菜/2.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
resource/plant/大白菜/3.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
BIN
resource/plant/大蒜/1.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
resource/plant/大蒜/2.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
resource/plant/大蒜/3.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
resource/plant/大蒜/4.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
resource/plant/大蒜/5.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
resource/plant/小麦/1.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
resource/plant/小麦/2.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
resource/plant/小麦/3.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
resource/plant/小麦/4.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
resource/plant/小麦/5.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resource/plant/水稻/1.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
resource/plant/水稻/2.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
resource/plant/水稻/3.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resource/plant/水稻/4.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
resource/plant/水稻/5.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
resource/plant/油菜/1.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
resource/plant/油菜/2.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
resource/plant/油菜/3.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
resource/plant/油菜/4.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resource/plant/牧草/1.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
resource/plant/牧草/2.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
resource/plant/牧草/3.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
resource/plant/牧草/4.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resource/plant/玉米/1.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
resource/plant/玉米/2.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
resource/plant/玉米/3.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
resource/plant/玉米/4.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resource/plant/玉米/5.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
resource/plant/生菜/1.png
Normal file
|
After Width: | Height: | Size: 899 B |
BIN
resource/plant/生菜/2.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
resource/plant/生菜/3.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
resource/plant/生菜/4.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
resource/plant/生菜/5.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
resource/plant/白萝卜/1.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
resource/plant/白萝卜/2.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
resource/plant/白萝卜/3.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
resource/plant/白萝卜/4.png
Normal file
|
After Width: | Height: | Size: 28 KiB |