diff --git a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs index b747e6645..49f58b5f2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs @@ -264,6 +264,8 @@ namespace PKHeX.Core { if (gift is WC3 {NotDistributed: true}) continue; + if (!IsSane(chain, gift)) + continue; if (needs.Count == 0) { yield return gift; @@ -288,6 +290,8 @@ namespace PKHeX.Core var encounters = EncounterStaticGenerator.GetPossible(pk, chain, version); foreach (var enc in encounters) { + if (!IsSane(chain, enc)) + continue; if (enc.IsUnobtainable()) continue; if (needs.Count == 0) @@ -339,6 +343,8 @@ namespace PKHeX.Core var trades = EncounterTradeGenerator.GetPossible(pk, chain, version); foreach (var trade in trades) { + if (!IsSane(chain, trade)) + continue; if (needs.Count == 0) { yield return trade; @@ -365,6 +371,8 @@ namespace PKHeX.Core var slots = EncounterSlotGenerator.GetPossible(pk, chain, version); foreach (var slot in slots) { + if (!IsSane(chain, slot)) + continue; if (slot.IsUnobtainable()) continue; @@ -383,6 +391,22 @@ namespace PKHeX.Core } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsSane(IReadOnlyList chain, IEncounterTemplate enc) + { + foreach (var evo in chain) + { + if (evo.Species != enc.Species) + continue; + if (evo.Form == enc.Form) + return true; + if (FormInfo.IsFormChangeable(enc.Species, enc.Form, evo.Form, enc.Generation)) + return true; + break; + } + return false; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsUnobtainable(this EncounterSlot slot) { diff --git a/Tests/PKHeX.Core.Tests/Legality/LearnabilityTests.cs b/Tests/PKHeX.Core.Tests/Legality/LearnabilityTests.cs index 2f8686d91..aae267572 100644 --- a/Tests/PKHeX.Core.Tests/Legality/LearnabilityTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/LearnabilityTests.cs @@ -19,6 +19,9 @@ namespace PKHeX.Tests.Legality } [Theory] + [InlineData(nameof(Species.Perrserker), "Swift")] + [InlineData(nameof(Species.Perrserker), "Shock Wave")] + [InlineData(nameof(Species.Sirfetchd), "False Swipe")] [InlineData(nameof(Species.Bulbasaur), "Fly")] [InlineData(nameof(Species.Charizard), "Bubble")] [InlineData(nameof(Species.Mew), "Struggle")]