From 934628b0770778d58586edcdde0e8a22f252184b Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 15 Aug 2021 14:23:15 -0700 Subject: [PATCH] Pre-filter memory mismatch on moves All over the place with prior commits; everything should be correct (and more robust) now. --- .../Encounters/EncounterMatchRating.cs | 3 --- .../EncounterStatic/EncounterStatic8Nest.cs | 6 ------ .../ByGeneration/EncounterGenerator8.cs | 19 ++---------------- .../Encounters/Generator/EncounterFinder.cs | 20 +++++++++++++++++++ .../Legality/Verifiers/MemoryPermissions.cs | 2 +- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterMatchRating.cs b/PKHeX.Core/Legality/Encounters/EncounterMatchRating.cs index 411bc94aa..367d7019b 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterMatchRating.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterMatchRating.cs @@ -8,9 +8,6 @@ namespace PKHeX.Core /// Matches most data, might have a better match later. Deferred, - /// Matches most data, might have a better match later. Less preferred than due to potentially small errors in secondary data. - DeferredSecondary, - /// Matches most data, might have a better match later. Less preferred than due to small errors in secondary data. DeferredErrors, diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8Nest.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8Nest.cs index 489f7fae2..d628484dc 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8Nest.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8Nest.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using static PKHeX.Core.Encounters8Nest; namespace PKHeX.Core @@ -61,11 +60,6 @@ namespace PKHeX.Core } } - if (pkm is IMemoryOT m && MemoryPermissions.IsMoveKnowMemory(m.OT_Memory) && !Moves.Contains(m.OT_TextVar)) - return EncounterMatchRating.DeferredSecondary; - if (pkm is IMemoryHT h && MemoryPermissions.IsMoveKnowMemory(h.HT_Memory) && !Moves.Contains(h.HT_TextVar)) - return EncounterMatchRating.DeferredSecondary; - return base.IsMatchDeferred(pkm); } diff --git a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator8.cs b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator8.cs index 92861d678..9231762e6 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator8.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator8.cs @@ -64,18 +64,14 @@ namespace PKHeX.Core } // Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded. - var moveClash = new List(1); - foreach (var z in GetValidStaticEncounter(pkm, chain)) + var encs = GetValidStaticEncounter(pkm, chain); + foreach (var z in encs) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return z; } - else if (match == DeferredSecondary) - { - moveClash.Add(z); - } else if (match < rating) { cache = z; @@ -97,17 +93,6 @@ namespace PKHeX.Core } } - if (moveClash.Count != 0) - { - if (cache != null && rating < DeferredSecondary) - yield return cache; - - foreach (var e in moveClash) - yield return e; - - yield break; - } - if (cache != null) yield return cache; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs index 86a01b7b4..ae80451c5 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs @@ -103,10 +103,30 @@ namespace PKHeX.Core if (info.Moves.Any(z => !z.Valid) && iterator.PeekIsNext()) return false; + if (info.Parse.Any(z => !z.Valid) && iterator.PeekIsNext()) + return false; + var evo = EvolutionVerifier.VerifyEvolution(pkm, info); if (!evo.Valid && iterator.PeekIsNext()) return false; + // Memories of Knowing a move which is later forgotten can be problematic with encounters that have special moves. + if (pkm is ITrainerMemories m) + { + if (m is IMemoryOT o && MemoryPermissions.IsMemoryOfKnownMove(o.OT_Memory)) + { + var mem = MemoryVariableSet.Read(m, 0); + if (!MemoryPermissions.CanKnowMove(pkm, mem, info.EncounterMatch.Generation, info)) + return false; + } + if (m is IMemoryHT h && MemoryPermissions.IsMemoryOfKnownMove(h.HT_Memory) && !pkm.HasMove(h.HT_TextVar)) + { + var mem = MemoryVariableSet.Read(m, 1); + if (!MemoryPermissions.CanKnowMove(pkm, mem, info.EncounterMatch.Generation, info)) + return false; + } + } + info.Parse.Add(evo); return true; } diff --git a/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs b/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs index e7a6044ba..c811d75ea 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs @@ -13,7 +13,7 @@ namespace PKHeX.Core /// public static class MemoryPermissions { - public static bool IsMoveKnowMemory(int memory) => memory is 16 or 48 or 80 or 81; + public static bool IsMemoryOfKnownMove(int memory) => memory is 48 or 80 or 81; public static bool CanWinRotoLoto(int generation, int item) {