private LegalityCheck[] verifyRelearn() { LegalityCheck[] res = new LegalityCheck[4]; MatchedWC6 = null; // Reset int[] Moves = pk6.RelearnMoves; if (!pk6.Gen6) { goto noRelearn; } if (pk6.WasLink) { int[] moves = Legal.getLinkMoves(pk6); for (int i = 0; i < 4; i++) { res[i] = moves[i] != Moves[i] ? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.") : new LegalityCheck(); } return(res); } if (pk6.WasEvent || pk6.WasEventEgg) { // Get WC6's that match IEnumerable <WC6> vwc6 = Legal.getValidWC6s(pk6); foreach (var wc in vwc6) { int[] moves = wc.RelearnMoves; for (int i = 0; i < 4; i++) { res[i] = moves[i] != Moves[i] ? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.") : new LegalityCheck(Severity.Valid, $"Matched WC #{wc.CardID.ToString("0000")}"); } if (res.All(r => r.Valid)) { MatchedWC6 = wc; return(res); } } goto noRelearn; // No WC match } if (pk6.WasEgg) { const int games = 2; bool checkAllGames = pk6.WasTradedEgg; bool splitBreed = Legal.SplitBreed.Contains(pk6.Species); int iterate = (checkAllGames ? games : 1) * (splitBreed ? 2 : 1); for (int i = 0; i < iterate; i++) { int gameSource = !checkAllGames ? -1 : i % iterate / (splitBreed ? 2 : 1); int skipOption = splitBreed && iterate / 2 <= i ? 1 : 0; // Obtain level1 moves List <int> baseMoves = new List <int>(Legal.getBaseEggMoves(pk6, skipOption, gameSource)); int baseCt = baseMoves.Count; if (baseCt > 4) { baseCt = 4; } // Obtain Nonstandard moves var relearnMoves = Legal.getValidRelearn(pk6, skipOption).ToArray(); var relearn = pk6.RelearnMoves.Where(move => move != 0 && (!baseMoves.Contains(move) || relearnMoves.Contains(move)) ).ToArray(); int relearnCt = relearn.Length; // Get Move Window List <int> window = new List <int>(baseMoves); window.AddRange(relearn); int[] moves = window.Skip(baseCt + relearnCt - 4).Take(4).ToArray(); Array.Resize(ref moves, 4); int req; if (relearnCt == 4) { req = 0; } else if (baseCt + relearnCt > 4) { req = 4 - relearnCt; } else { req = baseCt; } // Movepool finalized! Check validity. int[] rl = pk6.RelearnMoves; string em = string.Join(", ", baseMoves); // Base Egg Move for (int j = 0; j < req; j++) { res[j] = !baseMoves.Contains(rl[j]) ? new LegalityCheck(Severity.Invalid, $"Base egg move missing; expected one of: {em}.") : new LegalityCheck(Severity.Valid, "Base egg move."); } // Non-Base if (Legal.LightBall.Contains(pk6.Species)) { relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray(); } for (int j = req; j < 4; j++) { res[j] = !relearnMoves.Contains(rl[j]) ? new LegalityCheck(Severity.Invalid, "Not an expected relearn move.") : new LegalityCheck(Severity.Valid, "Relearn move."); } if (res.All(r => r.Valid)) { break; } } return(res); } if (Moves[0] != 0) // DexNav only? { // Check DexNav if (!Legal.getDexNavValid(pk6)) { goto noRelearn; } res[0] = !Legal.getValidRelearn(pk6, 0).Contains(Moves[0]) ? new LegalityCheck(Severity.Invalid, "Not an expected DexNav move.") : new LegalityCheck(); for (int i = 1; i < 4; i++) { res[i] = Moves[i] != 0 ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Move in slot.") : new LegalityCheck(); } return(res); } // Should have no relearn moves. noRelearn: for (int i = 0; i < 4; i++) { res[i] = Moves[i] != 0 ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Moves.") : new LegalityCheck(); } return(res); }
private LegalityCheck[] verifyRelearn() { RelearnBase = null; LegalityCheck[] res = new LegalityCheck[4]; int[] Moves = pk6.RelearnMoves; if (!pk6.Gen6) { goto noRelearn; } if (pk6.WasLink) { var Link = Legal.getValidLinkGifts(pk6); if (Link == null) { for (int i = 0; i < 4; i++) { res[i] = new LegalityCheck(); } return(res); } EncounterMatch = Link; int[] moves = ((EncounterLink)EncounterMatch).RelearnMoves; RelearnBase = moves; for (int i = 0; i < 4; i++) { res[i] = moves[i] != Moves[i] ? new LegalityCheck(Severity.Invalid, $"Expected: {movelist[moves[i]]}.") : new LegalityCheck(); } return(res); } if (pk6.WasEvent || pk6.WasEventEgg) { // Get WC6's that match CardMatch = new List <WC6>(Legal.getValidWC6s(pk6)); foreach (var wc in CardMatch) { int[] moves = wc.RelearnMoves; for (int i = 0; i < 4; i++) { res[i] = moves[i] != Moves[i] ? new LegalityCheck(Severity.Invalid, $"Expected ID: {movelist[moves[i]]}.") : new LegalityCheck(Severity.Valid, $"Matched WC #{wc.CardID.ToString("0000")}"); } if (res.Any(r => !r.Valid)) { CardMatch.Remove(wc); } } if (CardMatch.Count > 1) { return(res); } if (CardMatch.Count == 1) { EncounterMatch = CardMatch[0]; RelearnBase = CardMatch[0].RelearnMoves; return(res); } EncounterMatch = EncounterType = null; goto noRelearn; // No WC match } if (pk6.WasEgg) { const int games = 2; bool checkAllGames = pk6.WasTradedEgg; bool splitBreed = Legal.SplitBreed.Contains(pk6.Species); int iterate = (checkAllGames ? games : 1) * (splitBreed ? 2 : 1); for (int i = 0; i < iterate; i++) { int gameSource = !checkAllGames ? -1 : i % iterate / (splitBreed ? 2 : 1); int skipOption = splitBreed && iterate / 2 <= i ? 1 : 0; // Obtain level1 moves List <int> baseMoves = new List <int>(Legal.getBaseEggMoves(pk6, skipOption, gameSource)); int baseCt = baseMoves.Count; if (baseCt > 4) { baseCt = 4; } // Obtain Nonstandard moves var relearnMoves = Legal.getValidRelearn(pk6, skipOption).ToArray(); var relearn = pk6.RelearnMoves.Where(move => move != 0 && (!baseMoves.Contains(move) || relearnMoves.Contains(move)) ).ToArray(); int relearnCt = relearn.Length; // Get Move Window List <int> window = new List <int>(baseMoves); window.AddRange(relearn); int[] moves = window.Skip(baseCt + relearnCt - 4).Take(4).ToArray(); Array.Resize(ref moves, 4); int req; if (relearnCt == 4) { req = 0; } else if (baseCt + relearnCt > 4) { req = 4 - relearnCt; } else { req = baseCt; } // Movepool finalized! Check validity. int[] rl = pk6.RelearnMoves; string em = string.Join(", ", baseMoves.Select(r => r >= movelist.Length ? "ERROR" : movelist[r])); RelearnBase = baseMoves.ToArray(); // Base Egg Move for (int j = 0; j < req; j++) { if (baseMoves.Contains(rl[j])) { res[j] = new LegalityCheck(Severity.Valid, "Base egg move."); } else { res[j] = new LegalityCheck(Severity.Invalid, "Base egg move missing."); for (int f = j + 1; f < req; f++) { res[f] = new LegalityCheck(Severity.Invalid, "Base egg move missing."); } res[req - 1].Comment += $"{Environment.NewLine}Expected the following Relearn Moves: {em}."; break; } } // Non-Base if (Legal.LightBall.Contains(pk6.Species)) { relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray(); } for (int j = req; j < 4; j++) { res[j] = !relearnMoves.Contains(rl[j]) ? new LegalityCheck(Severity.Invalid, "Not an expected relearn move.") : new LegalityCheck(Severity.Valid, rl[j] == 0 ? "Empty" : "Relearn move."); } if (res.All(r => r.Valid)) { break; } } return(res); } if (Moves[0] != 0) // DexNav only? { // Check DexNav if (!Legal.getDexNavValid(pk6)) { goto noRelearn; } res[0] = !Legal.getValidRelearn(pk6, 0).Contains(Moves[0]) ? new LegalityCheck(Severity.Invalid, "Not an expected DexNav move.") : new LegalityCheck(); for (int i = 1; i < 4; i++) { res[i] = Moves[i] != 0 ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Move in slot.") : new LegalityCheck(); } if (res[0].Valid) { RelearnBase = new[] { Moves[0], 0, 0, 0 } } ; return(res); } // Should have no relearn moves. noRelearn: for (int i = 0; i < 4; i++) { res[i] = Moves[i] != 0 ? new LegalityCheck(Severity.Invalid, "Expected no Relearn Moves.") : new LegalityCheck(); } return(res); }