diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index 9f721291f..5461c88b3 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -404,7 +404,7 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s int level = encounter.LevelMin; int location = encounter.Location; - int minlvl = Legal.GetLowestLevel(pk, encounter.LevelMin); + int minlvl = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin); pk.Met_Level = level; pk.Met_Location = location; diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index c1e85a196..9d57b29b3 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -577,23 +577,6 @@ internal static bool GetCanInheritMoves(int species) return false; } - public static int GetLowestLevel(PKM pkm, int startLevel) - { - if (startLevel == -1) - startLevel = 100; - - var table = EvolutionTree.GetEvolutionTree(pkm, pkm.Format); - int count = 1; - for (int i = 100; i >= startLevel; i--) - { - var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks: true); - if (evos.Count < count) // lost an evolution, prior level was minimum current level - return evos.Max(evo => evo.Level) + 1; - count = evos.Count; - } - return startLevel; - } - internal static bool GetCanLearnMachineMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any) { return GetValidMoves(pkm, version, EvolutionChain.GetValidPreEvolutions(pkm), generation, Machine: true).Contains(move); diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs index 5d798cc41..eded38b00 100644 --- a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs +++ b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs @@ -166,6 +166,40 @@ public static int GetSuggestedTransferLocation(PKM pkm) return Legal.GetTransfer45MetLocation(pkm); return -1; } + + public static int GetLowestLevel(PKM pkm, int startLevel) + { + if (startLevel == -1) + startLevel = 100; + + var table = EvolutionTree.GetEvolutionTree(pkm, pkm.Format); + int count = 1; + for (int i = 100; i >= startLevel; i--) + { + var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks: true); + if (evos.Count < count) // lost an evolution, prior level was minimum current level + return evos.Max(evo => evo.Level) + 1; + count = evos.Count; + } + return startLevel; + } + + + public static int GetSuggestedMetLevel(PKM pkm, int minLevel) + { + var clone = pkm.Clone(); + int minMove = -1; + for (int i = clone.CurrentLevel; i >= minLevel; i--) + { + clone.Met_Level = i; + var la = new LegalityAnalysis(clone); + if (la.Valid) + return i; + if (la.Info.Moves.All(z => z.Valid)) + minMove = i; + } + return Math.Max(minMove, minLevel); + } } public sealed class EncounterSuggestionData : IRelearn @@ -202,17 +236,6 @@ public EncounterSuggestionData(PKM pkm, int met, int lvl) public int LevelMin { get; } public int LevelMax { get; } - public int GetSuggestedMetLevel(PKM pkm) - { - var clone = pkm.Clone(); - for (int i = clone.CurrentLevel; i > LevelMin; i--) - { - clone.Met_Level = i; - var la = new LegalityAnalysis(clone); - if (la.Info.Moves.All(z => z.Valid)) - return i; - } - return LevelMin; - } + public int GetSuggestedMetLevel(PKM pkm) => EncounterSuggestion.GetSuggestedMetLevel(pkm, LevelMin); } } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index a26b75292..46ea2e3ba 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -744,7 +744,7 @@ private bool SetSuggestedMetLocation(bool silent = false) int level = encounter.LevelMin; int location = encounter.Location; - int minlvl = Legal.GetLowestLevel(Entity, encounter.LevelMin); + int minlvl = EncounterSuggestion.GetLowestLevel(Entity, encounter.LevelMin); if (minlvl == 0) minlvl = level;