From d0f2b6eeb53567bc8a39bea431eb23d19aeed013 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 4 Mar 2022 22:33:53 -0800 Subject: [PATCH] Add .CurrentLevel=$suggest for min legal level --- PKHeX.Core/Editing/Bulk/BatchMods.cs | 1 + .../Bulk/Suggestion/BatchModifications.cs | 6 ++++ .../Information/EncounterSuggestion.cs | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/PKHeX.Core/Editing/Bulk/BatchMods.cs b/PKHeX.Core/Editing/Bulk/BatchMods.cs index 00100ac34..bc711c100 100644 --- a/PKHeX.Core/Editing/Bulk/BatchMods.cs +++ b/PKHeX.Core/Editing/Bulk/BatchMods.cs @@ -41,6 +41,7 @@ namespace PKHeX.Core new ComplexSuggestion(nameof(PKM.RelearnMoves), (_, value, info) => BatchModifications.SetSuggestedRelearnData(info, value)), new ComplexSuggestion(PROP_RIBBONS, (_, value, info) => BatchModifications.SetSuggestedRibbons(info, value)), new ComplexSuggestion(nameof(PKM.Met_Location), (_, _, info) => BatchModifications.SetSuggestedMetData(info)), + new ComplexSuggestion(nameof(PKM.CurrentLevel), (_, _, info) => BatchModifications.SetMinimumCurrentLevel(info)), new ComplexSuggestion(PROP_CONTESTSTATS, p => p is IContestStatsMutable, (_, value, info) => BatchModifications.SetContestStats(info.Entity, info.Legality.EncounterMatch, value)), new ComplexSuggestion(PROP_MOVEMASTERY, (_, value, info) => BatchModifications.SetSuggestedMasteryData(info, value)), }; diff --git a/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs b/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs index 2a3fae00a..f9b8568ef 100644 --- a/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs +++ b/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs @@ -80,6 +80,12 @@ namespace PKHeX.Core return ModifyResult.Modified; } + public static ModifyResult SetMinimumCurrentLevel(BatchInfo info) + { + var result = EncounterSuggestion.IterateMinimumCurrentLevel(info.Entity, info.Legal); + return result ? ModifyResult.Modified : ModifyResult.Filtered; + } + /// /// Sets the provided moves in a random order. /// diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs index b44aef585..852b30d8f 100644 --- a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs +++ b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs @@ -115,6 +115,38 @@ namespace PKHeX.Core return startLevel; } + public static bool IterateMinimumCurrentLevel(PKM pk, bool isLegal, int max = 100) + { + var original = pk.CurrentLevel; + var originalEXP = pk.EXP; + if (isLegal) + { + if (original == 1) + return false; + max = original - 1; + } + + for (int i = max; i != 0; i--) + { + pk.CurrentLevel = i; + var la = new LegalityAnalysis(pk); + var valid = la.Valid; + if (valid) + continue; + + var revert = Math.Min(100, i + 1); + if (revert == original) + { + pk.EXP = originalEXP; + return false; + } + + pk.CurrentLevel = revert; + return true; + } + return true; // 1 + } + /// /// Gets the suggested based on a baseline and the 's current moves. ///