diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index 7f3221043..9ace19eb2 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -398,11 +398,11 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s RibbonApplicator.SetAllValidRibbons(pk); return ModifyResult.Modified; case nameof(PKM.Met_Location): - var encounter = info.SuggestedEncounter; + var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk); if (encounter == null) return ModifyResult.Error; - int level = encounter.Level; + int level = encounter.LevelMin; int location = encounter.Location; int minlvl = Legal.GetLowestLevel(pk, encounter.LevelMin); diff --git a/PKHeX.Core/Editing/Bulk/PKMInfo.cs b/PKHeX.Core/Editing/Bulk/PKMInfo.cs index 1eff8b811..e61c78e12 100644 --- a/PKHeX.Core/Editing/Bulk/PKMInfo.cs +++ b/PKHeX.Core/Editing/Bulk/PKMInfo.cs @@ -15,6 +15,5 @@ internal sealed class PKMInfo public bool Legal => Legality.Valid; internal IReadOnlyList SuggestedRelearn => Legality.GetSuggestedRelearn(); - internal EncounterStatic? SuggestedEncounter => EncounterSuggestion.GetSuggestedMetInfo(Entity); } } \ No newline at end of file diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs index da1f73b71..62bb13131 100644 --- a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs +++ b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; namespace PKHeX.Core { @@ -10,7 +11,7 @@ public static class EncounterSuggestion /// /// Gets an object containing met data properties that might be legal. /// - public static EncounterStatic? GetSuggestedMetInfo(PKM pkm) + public static EncounterSuggestionData? GetSuggestedMetInfo(PKM pkm) { int loc = GetSuggestedTransferLocation(pkm); @@ -19,26 +20,20 @@ public static class EncounterSuggestion var w = EncounterSlotGenerator.GetCaptureLocation(pkm); if (w != null) - return GetSuggestedEncounterWild(w, loc); + return GetSuggestedEncounterWild(pkm, w, loc); var s = EncounterStaticGenerator.GetStaticLocation(pkm); if (s != null) - return GetSuggestedEncounterStatic(s, loc); + return GetSuggestedEncounterStatic(pkm, s, loc); return null; } - private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc = -1) + private static EncounterSuggestionData GetSuggestedEncounterEgg(PKM pkm, int loc = -1) { int lvl = GetSuggestedEncounterEggMetLevel(pkm); - var evo = Legal.GetBaseSpecies(pkm); - return new EncounterStatic - { - Species = evo.Species, - Form = evo.Form, - Location = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm), - Level = lvl, - }; + var met = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm); + return new EncounterSuggestionData(pkm, met, lvl); } public static int GetSuggestedEncounterEggMetLevel(PKM pkm) @@ -67,26 +62,18 @@ public static int GetSuggestedEncounterEggLocationEgg(PKM pkm, bool traded = fal } } - private static EncounterStatic GetSuggestedEncounterWild(EncounterArea area, int loc = -1) + private static EncounterSuggestionData GetSuggestedEncounterWild(PKM pkm, EncounterArea area, int loc = -1) { var slots = area.Slots.OrderBy(s => s.LevelMin); var first = slots.First(); - return new EncounterStatic - { - Location = loc != -1 ? loc : area.Location, - Species = first.Species, - Level = first.LevelMin, - }; + var met = loc != -1 ? loc : area.Location; + return new EncounterSuggestionData(pkm, first, met); } - private static EncounterStatic GetSuggestedEncounterStatic(EncounterStatic s, int loc = -1) + private static EncounterSuggestionData GetSuggestedEncounterStatic(PKM pkm, EncounterStatic s, int loc = -1) { - if (loc == -1) - loc = s.Location; - - // don't leak out the original EncounterStatic object - var encounter = s.Clone(loc); - return encounter; + var met = loc != -1 ? loc : s.Location; + return new EncounterSuggestionData(pkm, s, met); } /// @@ -179,4 +166,52 @@ public static int GetSuggestedTransferLocation(PKM pkm) return -1; } } + + public sealed class EncounterSuggestionData : IRelearn + { + private readonly IEncounterable? Encounter; + + public int[] Relearn => Encounter is IRelearn r ? r.Relearn : Array.Empty(); + + public EncounterSuggestionData(PKM pkm, IEncounterable enc, int met) + { + Encounter = enc; + Species = pkm.Species; + Form = pkm.AltForm; + Location = met; + + LevelMin = enc.LevelMin; + LevelMax = enc.LevelMax; + } + + public EncounterSuggestionData(PKM pkm, int met, int lvl) + { + Species = pkm.Species; + Form = pkm.AltForm; + Location = met; + + LevelMin = lvl; + LevelMax = lvl; + } + + public int Species { get; } + public int Form { get; } + public int Location { get; } + + 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.Valid) + return i; + } + return LevelMin; + } + } } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 27a364a3a..6a6d301c8 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -741,7 +741,7 @@ private bool SetSuggestedMetLocation(bool silent = false) return false; } - int level = encounter.Level; + int level = encounter.LevelMin; int location = encounter.Location; int minlvl = Legal.GetLowestLevel(Entity, encounter.LevelMin); if (minlvl == 0) @@ -765,7 +765,7 @@ private bool SetSuggestedMetLocation(bool silent = false) if (Entity.Format >= 3) { - TB_MetLevel.Text = level.ToString(); + TB_MetLevel.Text = encounter.GetSuggestedMetLevel(Entity).ToString(); CB_MetLocation.SelectedValue = location; if (Entity.Gen6 && Entity.WasEgg && ModifyPKM)