From a07549f013b99efe3477d9bd2f78f42754cd24ed Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 6 Jun 2021 23:36:59 -0700 Subject: [PATCH] Extract sketch valid check GetCanKnowMove should be checking for Smeargle knowing thousand arrows/waves. GetNeededMoves should also return 1ka/1kw for needed moves, and then no encounters. All uses of InvalidSketch are behind that method, so any future Smeargle modifications (like sketching a dummied move) will be checked (yay BDSP considerations). --- .../Moveset/EncounterMovesetGenerator.cs | 2 +- .../Verifiers/VerifyCurrentMoves.cs | 6 +++--- PKHeX.Core/Legality/Tables/Tables.cs | 20 +++++++++++++++++-- .../Legality/Verifiers/MemoryPermissions.cs | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs index 49f58b5f2..0bf7ebba7 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs @@ -150,7 +150,7 @@ public static IEnumerable GenerateVersionEncounters(PKM pk, IEnu private static int[] GetNeededMoves(PKM pk, IEnumerable moves, IReadOnlyList chain) { if (pk.Species == (int)Species.Smeargle) - return moves.Intersect(Legal.InvalidSketch).ToArray(); // Can learn anything + return moves.Where(z => !Legal.IsValidSketch(z, pk.Format)).ToArray(); // Can learn anything // Roughly determine the generation the PKM is originating from var ver = pk.Version; diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs index 527e24e60..c98f1b73a 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyCurrentMoves.cs @@ -136,9 +136,9 @@ private static CheckMoveResult[] ParseMovesSketch(PKM pkm, IReadOnlyList cu for (int i = 0; i < 4; i++) { var move = currentMoves[i]; - res[i] = Legal.InvalidSketch.Contains(move) || (pkm.Format is 6 && move is (int)Move.ThousandArrows or (int)Move.ThousandWaves) - ? new CheckMoveResult(Unknown, pkm.Format, Invalid, LMoveSourceInvalidSketch, CurrentMove) - : new CheckMoveResult(Sketch, pkm.Format, CurrentMove); + res[i] = Legal.IsValidSketch(move, pkm.Format) + ? new CheckMoveResult(Sketch, pkm.Format, CurrentMove) + : new CheckMoveResult(Unknown, pkm.Format, Invalid, LMoveSourceInvalidSketch, CurrentMove); } return res; diff --git a/PKHeX.Core/Legality/Tables/Tables.cs b/PKHeX.Core/Legality/Tables/Tables.cs index 3c666f0cf..44f7736f9 100644 --- a/PKHeX.Core/Legality/Tables/Tables.cs +++ b/PKHeX.Core/Legality/Tables/Tables.cs @@ -81,9 +81,9 @@ public static partial class Legal }; /// - /// Moves that can not be obtained by using Sketch with Smeargle. + /// Moves that can not be obtained by using Sketch with Smeargle in any game. /// - internal static readonly HashSet InvalidSketch = new(Z_Moves) + private static readonly HashSet InvalidSketch = new(Z_Moves) { // Can't Sketch (int)Struggle, @@ -93,6 +93,22 @@ public static partial class Legal (int)LightofRuin, }; + /// + /// Checks if Sketch can obtain the in the requested + /// + /// Doesn't bounds check the for max move ID. + /// Move ID + /// Generation to check + /// True if can be sketched, false if not available. + public static bool IsValidSketch(int move, int generation) + { + if (InvalidSketch.Contains(move)) + return false; + if (generation is 6 && move is ((int)ThousandArrows or (int)ThousandWaves)) + return false; + return true; + } + /// /// Species that are from Mythical Distributions (disallowed species for competitive rulesets) /// diff --git a/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs b/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs index 00fa2a8e7..75d3b4ad0 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryPermissions.cs @@ -105,7 +105,7 @@ public static bool GetCanRelearnMove(PKM pkm, int move, int generation, IReadOnl private static bool GetCanKnowMove(PKM pkm, int move, int generation, IReadOnlyList> evos, GameVersion version = GameVersion.Any) { if (pkm.Species == (int)Smeargle) - return !Legal.InvalidSketch.Contains(move); + return Legal.IsValidSketch(move, generation); if (generation >= 8 && MoveEgg.GetIsSharedEggMove(pkm, generation, move)) return true;