From ed25299c4bf4e87d73e31586ddbcb22820762d08 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Sat, 1 Nov 2025 13:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=98=9F?= =?UTF-8?q?=E7=BA=A7=E4=BD=9C=E7=89=A9=E7=BB=9F=E8=AE=A1=E6=94=B6=E8=8E=B7?= =?UTF-8?q?=E6=AC=A1=E6=95=B0BUG=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=92=AD?= =?UTF-8?q?=E7=A7=8D=E6=97=B6=E5=8D=87=E6=98=9FBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/userSoil.py | 26 +++++++++++++++++++------- core/farm.py | 10 +++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/database/userSoil.py b/core/database/userSoil.py index 32ab53d..34f8d8a 100644 --- a/core/database/userSoil.py +++ b/core/database/userSoil.py @@ -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( { diff --git a/core/farm.py b/core/farm.py index 019cca2..4e1abd0 100644 --- a/core/farm.py +++ b/core/farm.py @@ -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