🐛 修复星级作物统计收获次数BUG;修复播种时升星BUG

This commit is contained in:
Mualamx
2025-11-01 13:53:05 +08:00
parent 90f08187c5
commit ed25299c4b
2 changed files with 24 additions and 12 deletions
+19 -7
View File
@@ -1,4 +1,5 @@
import math
import re
from zhenxun.services.log import logger
@@ -405,18 +406,29 @@ class CUserSoilDB(CSqlManager):
prev = soilInfo or {}
await cls._deleteUserSoil(uid, soilIndex)
# 根据此植物收获次数对其星级进行升级
if g_pDBService.plant.existsPlant("一星" + plantName):
# 为避免对已带星级前缀的作物重复添加前缀,先提取基础名称
base_name = plantName
m = re.match(r"^(?:一星|二星|三星|四星|五星)", plantName)
if m:
base_name = plantName[len(m.group(0)) :]
# 只有当存在一星升级配置时才尝试按收获次数升级
if await g_pDBService.plant.existsPlant("一星" + base_name):
harvestCounts = (
await g_pDBService.userPlantCount.getUserPlantCountByPlantName(
uid, plantName
uid, base_name
)
)
if harvestCounts >= 350:
plantName = "一星" + plantName
if harvestCounts >= 700:
plantName = "二星" + plantName
# 根据阈值设定最高星级(避免重复拼接)
prefix = ""
if harvestCounts >= 1200:
plantName = "三星" + plantName
prefix = "三星"
elif harvestCounts >= 700:
prefix = "二星"
elif harvestCounts >= 350:
prefix = "一星"
plantName = prefix + base_name if prefix else base_name
await cls._insertUserSoil(
{
+5 -5
View File
@@ -1,5 +1,6 @@
import math
import random
import re
from zhenxun.configs.config import Config
from zhenxun.models.user_console import UserConsole
@@ -631,12 +632,11 @@ class CFarmManager:
# 统计收获次数
try:
# 统一处理星级植物名称
# 处理星级前缀(只在前两字为 一星/二星/三星/四星/五星 时去掉前缀)
plant_name = soilInfo["plantName"]
# 简单判断是否包含"星",如果包含则分割取后半部分
if "星" in plant_name:
plant_name = plant_name.split("星", 1)[-1]
m = re.match(r"^(?:一星|二星|三星|四星|五星)", plant_name)
if m:
plant_name = plant_name[len(m.group(0)) :]
await g_pDBService.userPlantCount.addUserPlantCountByUid(
uid, plant_name