public LegalityAnalysis(PKM pk) { for (int i = 0; i < 4; i++) { vMoves[i] = new CheckResult(CheckIdentifier.Move); vRelearn[i] = new CheckResult(CheckIdentifier.RelearnMove); } try { switch (pk.GenNumber) { case 6: parsePK6(pk); break; case 7: parsePK7(pk); break; default: return; } if (pkm.Format == 7) // Temp G7 Bank Checks { verifyG7PreBank(); } Valid = Parsed = Parse.Any(); if (Parsed) { if (Parse.Any(chk => !chk.Valid)) { Valid = false; } if (vMoves.Any(m => m.Valid != true)) { Valid = false; } else if (vRelearn.Any(m => m.Valid != true)) { Valid = false; } if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null) { AddLine(Severity.Indeterminate, "Fateful Encounter with no matching Encounter. Has the Mystery Gift data been contributed?", CheckIdentifier.Fateful); } } } catch { Valid = false; } getLegalityReport(); AllSuggestedMoves = !isOriginValid(pkm) ? new int[4] : getSuggestedMoves(true, true, true); AllSuggestedRelearnMoves = !isOriginValid(pkm) ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray(); AllSuggestedMovesAndRelearn = AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray(); }
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); }
public bool[] getRelearnValidity(int[] Moves) { if (Moves.Length != 4) { return(new bool[4]); } bool[] res = { true, true, true, true }; if (!pk6.Gen6) { goto noRelearn; } bool egg = Legal.EggLocations.Contains(pk6.Egg_Location) && pk6.Met_Level == 1; bool evnt = pk6.FatefulEncounter && pk6.Met_Location > 40000; bool eventEgg = pk6.FatefulEncounter && (pk6.Egg_Location > 40000 || pk6.Egg_Location == 30002) && pk6.Met_Level == 1; int[] relearnMoves = Legal.getValidRelearn(pk6, 0); if (evnt || eventEgg) { // Check Event Info // Not Implemented } else if (egg) { if (Legal.SplitBreed.Contains(pk6.Species)) { res = new bool[4]; for (int i = 0; i < 4; i++) { res[i] = relearnMoves.Contains(Moves[i]); } if (!res.Any(move => !move)) { return(res); } // Try Next Species up Legal.getValidRelearn(pk6, 1); for (int i = 0; i < 4; i++) { res[i] = relearnMoves.Contains(Moves[i]); } return(res); } if (Legal.LightBall.Contains(pk6.Species)) { relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray(); } for (int i = 0; i < 4; i++) { res[i] &= relearnMoves.Contains(Moves[i]); } return(res); } else if (Moves[0] != 0) // DexNav only? { // Check DexNav for (int i = 0; i < 4; i++) { res[i] &= Moves[i] == 0; } if (DexNav) { res[0] = relearnMoves.Contains(Moves[0]); } return(res); } // Should have no relearn moves. noRelearn: for (int i = 0; i < 4; i++) { res[i] &= Moves[i] == 0; } 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); }