Add .CurrentLevel=$suggest for min legal level

This commit is contained in:
Kurt 2022-03-04 22:33:53 -08:00
parent 6ae59c509f
commit d0f2b6eeb5
3 changed files with 39 additions and 0 deletions

View file

@ -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)),
};

View file

@ -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;
}
/// <summary>
/// Sets the provided moves in a random order.
/// </summary>

View file

@ -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
}
/// <summary>
/// Gets the suggested <see cref="PKM.Met_Level"/> based on a baseline <see cref="minLevel"/> and the <see cref="pkm"/>'s current moves.
/// </summary>