修复偷菜后收获果实数不会减少的错误

This commit is contained in:
2025-11-13 23:15:02 +08:00
parent 26bea6eef3
commit 5a8eb6cbd8
3 changed files with 37 additions and 3 deletions

View File

@@ -187,7 +187,10 @@ class GardenService:
crop = GARDEN_CROPS.get(plot["seed_id"])
if not crop:
raise ValueError("未知作物")
base_yield = int(plot["base_yield"])
initial_yield = int(plot["base_yield"])
remaining_fruit = int(plot["remaining_fruit"])
if remaining_fruit < 0:
remaining_fruit = 0
extra_reward = None
if crop.extra_reward:
base_rate = crop.extra_reward.base_rate
@@ -199,7 +202,7 @@ class GardenService:
if crop.extra_reward.kind == "points":
data = crop.extra_reward.payload
max_points = min(
data.get("max", base_yield * crop.seed_price),
data.get("max", initial_yield * crop.seed_price),
crop.seed_price * self._config.sale_multiplier,
)
min_points = data.get("min", 0)
@@ -219,9 +222,10 @@ class GardenService:
}
result = {
"crop": crop,
"base_yield": base_yield,
"base_yield": remaining_fruit,
"extra": extra_reward,
}
result["initial_yield"] = initial_yield
cursor = self._db.conn.cursor()
cursor.execute(
"DELETE FROM garden_plots WHERE user_id = ? AND plot_index = ?",