From b603bc87b8ab937eb404d77049c317a47bb48bb4 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 1 Feb 2018 19:57:02 -0800 Subject: [PATCH] Update shedinja ninjask move checks check level of source moves for any incompatibility in non-bred cases. Closes #1805 --- PKHeX.Core/Legality/Core.cs | 20 ++++++----- .../Legality/Encounters/VerifyCurrentMoves.cs | 35 +++++++++++++++---- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index b2e289937..725fc142b 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -436,16 +436,12 @@ internal static IEnumerable GetValidRelearn(PKM pkm, int species, bool inhe r.AddRange(GetRelearnLVLMoves(pkm, species, 100, pkm.AltForm, version)); return r.Distinct(); } - internal static List[] GetShedinjaEvolveMoves(PKM pkm, int lvl = -1, int generation = 0) + internal static IList GetShedinjaEvolveMoves(PKM pkm, int lvl = -1, int generation = 0) { - var size = pkm.Format > 3 ? 4 : 3; - List[] r = new List[size + 1]; - for (int i = 1; i <= size; i++) - r[i] = new List(); if (lvl == -1) lvl = pkm.CurrentLevel; if (pkm.Species != 292 || lvl < 20) - return r; + return new List(); // If nincada evolves into Ninjask an learn in the evolution a move from ninjask learnset pool // Shedinja would appear with that move learned. Only one move above level 20 allowed, only in generations 3 and 4 @@ -454,17 +450,23 @@ internal static List[] GetShedinjaEvolveMoves(PKM pkm, int lvl = -1, int ge case 0: // Default (both) case 3: // Ninjask have the same learnset in every gen 3 games if (pkm.InhabitedGeneration(3)) - r[3] = LevelUpE[291].GetMoves(lvl, 20).ToList(); + return LevelUpE[291].GetMoves(lvl, 20).ToList(); if (generation == 0) goto case 4; break; case 4: // Ninjask have the same learnset in every gen 4 games if (pkm.InhabitedGeneration(4)) - r[4] = LevelUpPt[291].GetMoves(lvl, 20).ToList(); + return LevelUpPt[291].GetMoves(lvl, 20); break; } - return r; + return new List(); + } + internal static int GetShedinjaMoveLevel(int species, int move, int generation) + { + var src = generation == 4 ? LevelUpPt : LevelUpE; + var moves = src[species]; + return moves.GetLevelLearnMove(move); } internal static int[] GetBaseEggMoves(PKM pkm, int species, GameVersion gameSource, int lvl) { diff --git a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs index e2935a529..0267e6100 100644 --- a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs +++ b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs @@ -244,11 +244,12 @@ private static CheckMoveResult[] ParseMoves(PKM pkm, MoveParseSource source, Leg return res; } - if (pkm.Species == 292 && info.EncounterMatch.Species != 292) + if (pkm.Species == 292 && info.EncounterMatch.Species != 292 && !(info.EncounterMatch is EncounterEgg)) { // Ignore Shedinja if the Encounter was also a Shedinja, assume null Encounter as a Nincada egg // Check Shedinja evolved moves from Ninjask after egg moves // Those moves could also be inherited egg moves + if (info.Generation <= 4) // 3 or 4 ParseShedinjaEvolveMoves(pkm, res, source.CurrentMoves); } @@ -545,17 +546,17 @@ private static void ParseEvolutionsIncompatibleMoves(PKM pkm, IList res, int[] moves) { - List[] ShedinjaEvoMoves = Legal.GetShedinjaEvolveMoves(pkm); var ShedinjaEvoMovesLearned = new List(); for (int gen = Math.Min(pkm.Format, 4); gen >= 3; gen--) { + var ninjaskMoves = Legal.GetShedinjaEvolveMoves(pkm, generation: gen); bool native = gen == pkm.Format; for (int m = 0; m < 4; m++) { if (IsCheckValid(res[m])) // already validated continue; - if (!ShedinjaEvoMoves[gen].Contains(moves[m])) + if (!ninjaskMoves.Contains(moves[m])) continue; res[m] = new CheckMoveResult(MoveSource.ShedinjaEvo, gen, Severity.Valid, native ? V355 : string.Format(V356, gen), CheckIdentifier.Move); @@ -563,11 +564,33 @@ private static void ParseShedinjaEvolveMoves(PKM pkm, IList res } } - if (ShedinjaEvoMovesLearned.Count <= 1) + if (ShedinjaEvoMovesLearned.Count > 1) + { + // Can't have more than one Ninjask exclusive move on Shedinja + foreach (int m in ShedinjaEvoMovesLearned) + res[m] = new CheckMoveResult(res[m], Severity.Invalid, V357, CheckIdentifier.Move); return; + } - foreach (int m in ShedinjaEvoMovesLearned) - res[m] = new CheckMoveResult(res[m], Severity.Invalid, V357, CheckIdentifier.Move); + // Double check that the Ninjask move level isn't less than any Nincada move level + int move = ShedinjaEvoMovesLearned[0]; + int g = res[move].Generation; + int levelJ = Legal.GetShedinjaMoveLevel(291, moves[move], g); + + for (int m = 0; m < 4; m++) + { + if (m == move) + continue; + if (res[m].Source != MoveSource.LevelUp) + continue; + int levelS = Legal.GetShedinjaMoveLevel(292, moves[m], res[m].Generation); + if (levelS > 0) + continue; + + int levelN = Legal.GetShedinjaMoveLevel(290, moves[m], res[m].Generation); + if (levelN > levelJ) + res[m] = new CheckMoveResult(res[m], Severity.Invalid, string.Format(V366, SpeciesStrings[290], SpeciesStrings[291]), CheckIdentifier.Move); + } } private static void ParseEvolutionLevelupMove(PKM pkm, IList res, int[] moves, List IncenseMovesLearned, LegalInfo info) {