From 2e0a2ed7ebcbef5155f5e9af05b54b2c158fa8dc Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 9 Jul 2023 21:06:47 -0700 Subject: [PATCH] Adjust head evo max level for 345 vc7 transfers https://projectpokemon.org/home/forums/topic/63635-pkhex-230709-bugs/ --- .../Evolutions/EvolutionGroup/EvolutionGroup2.cs | 4 ++-- .../Evolutions/EvolutionGroup/EvolutionGroup3.cs | 4 ++-- .../Evolutions/EvolutionGroup/EvolutionGroup4.cs | 6 +++--- .../Evolutions/EvolutionGroup/EvolutionGroup5.cs | 2 +- .../Evolutions/EvolutionGroup/EvolutionGroup7.cs | 2 +- .../Evolutions/EvolutionGroup/EvolutionUtil.cs | 14 +++++++++----- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup2.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup2.cs index 0912ca47c..5b5d7c943 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup2.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup2.cs @@ -17,9 +17,9 @@ public int Devolve(Span result, PKM pk, EvolutionOrigin enc) { if (pk.Format > Generation && !enc.SkipChecks) { - var max = pk.Met_Level; + byte max = (byte)pk.Met_Level; EvolutionUtil.UpdateCeiling(result, max); - enc = enc with { LevelMin = 2, LevelMax = (byte)max }; + enc = enc with { LevelMin = 2, LevelMax = max }; } int present = 1; diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup3.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup3.cs index 42d0ac29f..b13807b96 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup3.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup3.cs @@ -17,9 +17,9 @@ public int Devolve(Span result, PKM pk, EvolutionOrigin enc) { if (pk.Format == 4 && !enc.SkipChecks) // 5+ already have been revised { - var max = pk.Met_Level; + byte max = (byte)pk.Met_Level; EvolutionUtil.UpdateCeiling(result, max); - enc = enc with { LevelMin = 1, LevelMax = (byte)max }; + enc = enc with { LevelMin = 1, LevelMax = max }; } int present = 1; diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup4.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup4.cs index 35020e8f4..765ca4fc3 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup4.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup4.cs @@ -17,9 +17,9 @@ public int Devolve(Span result, PKM pk, EvolutionOrigin enc) { if (pk.Format > Generation && !enc.SkipChecks) { - var max = pk.Met_Level; + byte max = (byte)pk.Met_Level; EvolutionUtil.UpdateCeiling(result, max); - enc = enc with { LevelMin = 1, LevelMax = (byte)max }; + enc = enc with { LevelMin = 1, LevelMax = max }; } int present = 1; @@ -47,7 +47,7 @@ public int Evolve(Span result, PKM pk, EvolutionOrigin enc, Evoluti if (pk.Format > Generation) enc = enc with { LevelMax = (byte)pk.Met_Level }; else if (enc.Generation < Generation) - EvolutionUtil.UpdateFloor(result, pk.Met_Level); + EvolutionUtil.UpdateFloor(result, (byte)pk.Met_Level, enc.LevelMax); int present = 1; for (int i = result.Length - 1; i >= 1; i--) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup5.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup5.cs index 3c50a4898..c09b74906 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup5.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup5.cs @@ -38,7 +38,7 @@ public bool TryDevolve(ISpeciesForm head, PKM pk, byte currentMaxLevel, byte lev public int Evolve(Span result, PKM pk, EvolutionOrigin enc, EvolutionHistory history) { if (enc.Generation < Generation) - EvolutionUtil.UpdateFloor(result, pk.Met_Level); + EvolutionUtil.UpdateFloor(result, (byte)pk.Met_Level, enc.LevelMax); int present = 1; for (int i = result.Length - 1; i >= 1; i--) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup7.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup7.cs index d6671f87c..c66a1e8ee 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup7.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionGroup7.cs @@ -51,7 +51,7 @@ private static void RevertMutatedForms(ref EvoCriteria evo) public int Evolve(Span result, PKM pk, EvolutionOrigin enc, EvolutionHistory history) { if (enc.Generation <= 2) // VC Transfer - EvolutionUtil.UpdateFloor(result, pk.Met_Level); + EvolutionUtil.UpdateFloor(result, (byte)pk.Met_Level, enc.LevelMax); int present = 1; for (int i = result.Length - 1; i >= 1; i--) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionUtil.cs b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionUtil.cs index 0ebeda606..6c0651dcf 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionUtil.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionGroup/EvolutionUtil.cs @@ -86,26 +86,30 @@ public static int IndexOf(Span result, ushort species) /// /// Revises the to account for a new maximum . /// - public static void UpdateCeiling(Span result, int level) + public static void UpdateCeiling(Span result, byte level) { foreach (ref var evo in result) { if (evo.Species == 0) break; - evo = evo with { LevelMax = (byte)Math.Min(evo.LevelMax, level) }; + evo = evo with { LevelMax = Math.Min(evo.LevelMax, level) }; } } /// - /// Revises the to account for a new minimum . + /// Revises the to account for a new minimum . /// - public static void UpdateFloor(Span result, int level) + public static void UpdateFloor(Span result, byte levelMin, byte levelMax) { + // Reset the head to the new levelMax, then clamp every entry's minimum to the min. + // Evolving non-head evolutions will pick up the new ranges later. + ref var head = ref result[0]; + head = head with { LevelMax = levelMax }; foreach (ref var evo in result) { if (evo.Species == 0) break; - evo = evo with { LevelMin = (byte)Math.Max(evo.LevelMin, level) }; + evo = evo with { LevelMin = Math.Max(evo.LevelMin, levelMin) }; } }