From 58b2c31a66b2cc2e08c53ec3f8588c025abe9ba8 Mon Sep 17 00:00:00 2001 From: Makio <33434804+ilmakio@users.noreply.github.com> Date: Thu, 18 Dec 2025 06:05:16 +0100 Subject: [PATCH] Implement flavor score and star calculation for donuts (#4661) * Implement flavor score and star calculation for donuts Added logic to compute the flavor score and assign star ratings based on defined thresholds in the RecalculateDonutStats method. This enhances donut stat recalculation by including flavor and star values. 120 Points: 1 star 240 Points: 2 stars 360 Points: 3 stars 700 Points: 4 stars 960 Points: 5 stars --- .../Substructures/Gen9/ZA/DonutPocket9a.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/Saves/Substructures/Gen9/ZA/DonutPocket9a.cs b/PKHeX.Core/Saves/Substructures/Gen9/ZA/DonutPocket9a.cs index af86cf9a0..18f8366cc 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/ZA/DonutPocket9a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/ZA/DonutPocket9a.cs @@ -210,20 +210,31 @@ public static void RecalculateDonutStats(this Donut9a donut) var boost = 1; var calories = 0; var berries = donut.GetBerries(); + var flavorScore = 0; foreach (var berry in berries) { if (!TryGetBerry(berry, out var detail)) continue; calories += detail.Calories; boost += detail.Boost; + flavorScore += detail.FlavorScore; } - donut.Calories = (ushort)((calories > 9999) ? 9999 : (ushort)calories); + donut.Calories = (ushort)Math.Min(calories, 9999); donut.LevelBoost = (byte)boost; - // Stars?? - // Flavors?? + donut.Stars = GetDonutStarCount(flavorScore); } + public static byte GetDonutStarCount(int flavorScore) => flavorScore switch + { + >= 960 => 5, + >= 700 => 4, + >= 360 => 3, + >= 240 => 2, + >= 120 => 1, + _ => 0 + }; + public static void RecalculateDonutFlavors(this Donut9a donut, Span flavors) { var berries = donut.GetBerries(); @@ -555,7 +566,10 @@ public static bool TryGetFlavorName(ulong hash, [NotNullWhen(true)] out string? public static ulong GetFlavorHash(string text) => FnvHash.HashFnv1a_64(text); } -public readonly record struct DonutBerryDetail(ushort Item, byte Donut, byte Spicy, byte Fresh, byte Sweet, byte Bitter, byte Sour, byte Boost, ushort Calories); +public readonly record struct DonutBerryDetail(ushort Item, byte Donut, byte Spicy, byte Fresh, byte Sweet, byte Bitter, byte Sour, byte Boost, ushort Calories) +{ + public int FlavorScore => Spicy + Fresh + Sweet + Bitter + Sour; +} public readonly record struct Donut9a(Memory Raw) {