private static CheckResult[] VerifyRelearnEggBase(PKM pkm, LegalInfo info, EncounterEgg e) { int[] RelearnMoves = pkm.RelearnMoves; CheckResult[] res = new CheckResult[4]; // Level up moves cannot be inherited if Ditto is the parent // that means genderless species and male only species except Nidoran and Volbeat (they breed with female nidoran and illumise) could not have level up moves as an egg bool inheritLvlMoves = Legal.GetCanInheritMoves(e.Species); // Obtain level1 moves var baseMoves = Legal.GetBaseEggMoves(pkm, e.Species, e.Version, 1); int baseCt = Math.Min(4, baseMoves.Length); // Obtain Inherited moves var inheritMoves = Legal.GetValidRelearn(pkm, e.Species, inheritLvlMoves, e.Version).ToList(); int reqBase = GetRequiredBaseMoves(RelearnMoves, baseMoves, baseCt, inheritMoves); // Check if the required amount of Base Egg Moves are present. FlagBaseEggMoves(res, reqBase, baseMoves, RelearnMoves); // Non-Base moves that can magically appear in the regular movepool if (Legal.LightBall.Contains(pkm.Species)) { inheritMoves.Add(344); // Volt Tackle } // If any splitbreed moves are invalid, flag accordingly var splitMoves = e is EncounterEggSplit s ? Legal.GetValidRelearn(pkm, s.OtherSpecies, inheritLvlMoves, e.Version).ToList() : (IReadOnlyList <int>)Array.Empty <int>(); // Inherited moves appear after the required base moves. // If the pkm is capable of split-species breeding and any inherited move is from the other split scenario, flag accordingly. bool splitInvalid = FlagInvalidInheritedMoves(res, reqBase, RelearnMoves, inheritMoves, splitMoves); if (splitInvalid) { FlagSplitbreedMoves(res, reqBase, e, pkm); } info.RelearnBase = baseMoves; return(res); }
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 = !pkm.IsOriginValid() ? new int[4] : getSuggestedMoves(true, true, true); AllSuggestedRelearnMoves = !pkm.IsOriginValid() ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray(); AllSuggestedMovesAndRelearn = AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray(); }
/// <summary> /// Adds a new Check parse value. /// </summary> /// <param name="chk">Check result to add.</param> internal void AddLine(CheckResult chk) => Parse.Add(chk);
private void UpdateInfo() { Info = EncounterFinder.FindVerifiedEncounter(pkm); Encounter = Info.Parse[0]; Parse.AddRange(Info.Parse); }
private void AddLine(CheckResult chk) { Parse.Add(chk); }
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.Format) // prior to storing GameVersion { case 1: parsePK1(pk); break; case 2: parsePK1(pk); break; } if (!Parse.Any()) { switch (pk.GenNumber) { case 3: parsePK3(pk); break; case 4: parsePK4(pk); break; case 5: parsePK5(pk); break; case 6: parsePK6(pk); break; case 1: parsePK7(pk); break; case 7: parsePK7(pk); break; } } if (Parse.Count > 0) { if (Parse.Any(chk => !chk.Valid)) { Valid = false; } else if (vMoves.Any(m => m.Valid != true)) { Valid = false; } else if (vRelearn.Any(m => m.Valid != true)) { Valid = false; } else { Valid = true; } if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null) { AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful); } } } catch (Exception e) { Console.WriteLine(e.Message); Valid = false; AddLine(Severity.Invalid, V190, CheckIdentifier.Misc); Error = true; } Parsed = true; }
public EncounterRejected(IEncounterable encounter, CheckResult check) { Encounter = encounter; Check = check; }
private CheckResult[] verifyMoves() { int[] Moves = pkm.Moves; CheckResult[] res = new CheckResult[4]; for (int i = 0; i < 4; i++) res[i] = new CheckResult(CheckIdentifier.Move); if (pkm.GenNumber < 6) return res; var validMoves = Legal.getValidMoves(pkm, EvoChain).ToArray(); if (pkm.Species == 235) // Smeargle { for (int i = 0; i < 4; i++) res[i] = Legal.InvalidSketch.Contains(Moves[i]) ? new CheckResult(Severity.Invalid, "Invalid Sketch move.", CheckIdentifier.Move) : new CheckResult(CheckIdentifier.Move); } else if (EventGiftMatch?.Count > 1) // Multiple possible Mystery Gifts matched { int[] RelearnMoves = pkm.RelearnMoves; foreach (MysteryGift mg in EventGiftMatch) { for (int i = 0; i < 4; i++) { if (Moves[i] == Legal.Struggle) res[i] = new CheckResult(Severity.Invalid, "Invalid Move: Struggle.", CheckIdentifier.Move); else if (validMoves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.", CheckIdentifier.Move); else if (RelearnMoves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.", CheckIdentifier.Move) { Flag = true }; else if (mg.Moves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, "Wonder Card Non-Relearn Move.", CheckIdentifier.Move); else res[i] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move); } if (res.Any(r => !r.Valid)) continue; EncounterMatch = mg; RelearnBase = mg.RelearnMoves; break; } } else { int[] RelearnMoves = pkm.RelearnMoves; MysteryGift MatchedGift = EncounterMatch as MysteryGift; int[] GiftMoves = MatchedGift?.Moves ?? new int[0]; for (int i = 0; i < 4; i++) { if (Moves[i] == Legal.Struggle) res[i] = new CheckResult(Severity.Invalid, "Invalid Move: Struggle.", CheckIdentifier.Move); else if (validMoves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.", CheckIdentifier.Move); else if (RelearnMoves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.", CheckIdentifier.Move) { Flag = true }; else if (GiftMoves.Contains(Moves[i])) res[i] = new CheckResult(Severity.Valid, "Wonder Card Non-Relearn Move.", CheckIdentifier.Move); else res[i] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move); } } if (Moves[0] == 0) // None res[0] = new CheckResult(Severity.Invalid, "Invalid Move.", CheckIdentifier.Move); if (pkm.Species == 647) // Keldeo if (pkm.AltForm == 1 ^ pkm.Moves.Contains(548)) res[Math.Max(Array.IndexOf(pkm.Moves, 548), 0)] = new CheckResult(Severity.Invalid, "Secret Sword / Resolute Keldeo Mismatch.", CheckIdentifier.Move); // Duplicate Moves Check for (int i = 0; i < 4; i++) if (Moves.Count(m => m != 0 && m == Moves[i]) > 1) res[i] = new CheckResult(Severity.Invalid, "Duplicate Move.", CheckIdentifier.Move); return res; }
private void updateEncounterChain() { if (EventGiftMatch?.Count > 1) // Multiple possible Mystery Gifts matched EncounterMatch = EventGiftMatch.First(); // temporarily set one so that Encounter can be verified Encounter = verifyEncounter(); EvoChain = Legal.getEvolutionChain(pkm, EncounterMatch); }
private void updateMoveLegality() { try { vMoves = verifyMoves(); } catch { for (int i = 0; i < 4; i++) vMoves[i] = new CheckResult(Severity.Invalid, "Internal error.", CheckIdentifier.Move); } // SecondaryChecked = false; }
private void updateRelearnLegality() { try { vRelearn = verifyRelearn(); } catch { for (int i = 0; i < 4; i++) vRelearn[i] = new CheckResult(Severity.Invalid, "Internal error.", CheckIdentifier.RelearnMove); } // SecondaryChecked = false; }
private CheckResult[] verifyRelearn() { RelearnBase = null; CheckResult[] res = new CheckResult[4]; int[] Moves = pkm.RelearnMoves; if (pkm.GenNumber < 6) goto noRelearn; if (pkm.WasLink) { var Link = Legal.getValidLinkGifts(pkm); if (Link == null) { for (int i = 0; i < 4; i++) res[i] = new CheckResult(CheckIdentifier.RelearnMove); 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 CheckResult(Severity.Invalid, $"Expected: {movelist[moves[i]]}.", CheckIdentifier.RelearnMove) : new CheckResult(CheckIdentifier.RelearnMove); return res; } if (pkm.WasEvent || pkm.WasEventEgg) { // Get WC6's that match EventGiftMatch = new List<MysteryGift>(Legal.getValidGifts(pkm)); foreach (MysteryGift mg in EventGiftMatch.ToArray()) { int[] moves = mg.RelearnMoves; for (int i = 0; i < 4; i++) res[i] = moves[i] != Moves[i] ? new CheckResult(Severity.Invalid, $"Expected: {movelist[moves[i]]}.", CheckIdentifier.RelearnMove) : new CheckResult(CheckIdentifier.RelearnMove); if (res.Any(r => !r.Valid)) EventGiftMatch.Remove(mg); } if (EventGiftMatch.Count > 1) return res; if (EventGiftMatch.Count == 1) { EncounterMatch = EventGiftMatch[0]; RelearnBase = EventGiftMatch[0].RelearnMoves; return res; } EncounterMatch = EncounterType = null; goto noRelearn; // No WC match } if (pkm.WasEgg && !Legal.NoHatchFromEgg.Contains(pkm.Species)) { GameVersion[] Games = { GameVersion.XY }; switch (pkm.GenNumber) { case 6: Games = new[] {GameVersion.XY, GameVersion.ORAS}; break; case 7: Games = new[] {GameVersion.SM}; break; } bool checkAllGames = pkm.WasTradedEgg; bool splitBreed = Legal.SplitBreed.Contains(pkm.Species); int iterate = (checkAllGames ? Games.Length : 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; GameVersion ver = gameSource == -1 ? GameVersion.Any : Games[gameSource]; // Obtain level1 moves List<int> baseMoves = new List<int>(Legal.getBaseEggMoves(pkm, skipOption, ver)); int baseCt = baseMoves.Count; if (baseCt > 4) baseCt = 4; // Obtain Nonstandard moves var relearnMoves = Legal.getValidRelearn(pkm, skipOption).ToArray(); var relearn = pkm.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 reqBase; int unique = baseMoves.Concat(relearn).Distinct().Count(); if (relearnCt == 4) reqBase = 0; else if (baseCt + relearnCt > 4) reqBase = 4 - relearnCt; else reqBase = baseCt; if (pkm.RelearnMoves.Where(m=>m != 0).Count() < Math.Min(4, baseMoves.Count)) reqBase = Math.Min(4, unique); // Movepool finalized! Check validity. int[] rl = pkm.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 < reqBase; j++) { if (baseMoves.Contains(rl[j])) res[j] = new CheckResult(Severity.Valid, "Base egg move.", CheckIdentifier.RelearnMove); else { res[j] = new CheckResult(Severity.Invalid, "Base egg move missing.", CheckIdentifier.RelearnMove); for (int f = j+1; f < reqBase; f++) res[f] = new CheckResult(Severity.Invalid, "Base egg move missing.", CheckIdentifier.RelearnMove); res[reqBase-1].Comment += $"{Environment.NewLine}Expected the following Relearn Moves: {em}."; break; } } // Non-Base if (Legal.LightBall.Contains(pkm.Species)) relearnMoves = relearnMoves.Concat(new[] { 344 }).ToArray(); for (int j = reqBase; j < 4; j++) res[j] = !relearnMoves.Contains(rl[j]) ? new CheckResult(Severity.Invalid, "Not an expected relearn move.", CheckIdentifier.RelearnMove) : new CheckResult(Severity.Valid, rl[j] == 0 ? "Empty" : "Relearn move.", CheckIdentifier.RelearnMove); if (res.All(r => r.Valid)) break; } // Duplicate Moves Check for (int i = 0; i < 4; i++) if (Moves.Count(m => m != 0 && m == Moves[i]) > 1) res[i] = new CheckResult(Severity.Invalid, "Duplicate Relearn Move.", CheckIdentifier.RelearnMove); return res; } if (Moves[0] != 0) // DexNav only? { // Check DexNav if (!Legal.getDexNavValid(pkm)) goto noRelearn; res[0] = !Legal.getValidRelearn(pkm, 0).Contains(Moves[0]) ? new CheckResult(Severity.Invalid, "Not an expected DexNav move.", CheckIdentifier.RelearnMove) : new CheckResult(CheckIdentifier.RelearnMove); for (int i = 1; i < 4; i++) res[i] = Moves[i] != 0 ? new CheckResult(Severity.Invalid, "Expected no Relearn Move in slot.", CheckIdentifier.RelearnMove) : new CheckResult(CheckIdentifier.RelearnMove); 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 CheckResult(Severity.Invalid, "Expected no Relearn Moves.", CheckIdentifier.RelearnMove) : new CheckResult(CheckIdentifier.RelearnMove); return res; }
private static bool IsCheckInvalid(CheckResult chk) => !(chk?.Valid ?? false);
public void AddLine(CheckResult chk) => Parse.Add(chk);
private static bool IsCheckValid(CheckResult chk) => chk?.Valid ?? false;
private static CheckResult[] VerifyRelearnEggBase(PKM pkm, LegalInfo info, EncounterEgg e) { int[] RelearnMoves = pkm.RelearnMoves; info.RelearnBase = new int[4]; CheckResult[] res = new CheckResult[4]; // Level up moves could not be inherited if Ditto is parent, // that means genderless species and male only species except Nidoran and Volbet (they breed with female nidoran and illumise) could not have level up moves as an egg var inheritLvlMoves = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species); // Obtain level1 moves List <int> baseMoves = new List <int>(Legal.GetBaseEggMoves(pkm, e.Species, e.Game, 1)); int baseCt = baseMoves.Count; if (baseCt > 4) { baseCt = 4; } // Obtain Inherited moves var inheritMoves = Legal.GetValidRelearn(pkm, e.Species, inheritLvlMoves).ToList(); var inherited = RelearnMoves.Where(m => m != 0 && (!baseMoves.Contains(m) || inheritMoves.Contains(m))).ToList(); int inheritCt = inherited.Count; // Get required amount of base moves int unique = baseMoves.Concat(inherited).Distinct().Count(); int reqBase = inheritCt == 4 || baseCt + inheritCt > 4 ? 4 - inheritCt : baseCt; if (RelearnMoves.Where(m => m != 0).Count() < Math.Min(4, baseMoves.Count)) { reqBase = Math.Min(4, unique); } // Check if the required amount of Base Egg Moves are present. for (int i = 0; i < reqBase; i++) { if (baseMoves.Contains(RelearnMoves[i])) { res[i] = new CheckResult(Severity.Valid, V179, CheckIdentifier.RelearnMove); } else { // mark remaining base egg moves missing for (int z = i; z < reqBase; z++) { res[z] = new CheckResult(Severity.Invalid, V180, CheckIdentifier.RelearnMove); } // provide the list of suggested base moves for the last required slot string em = string.Join(", ", baseMoves.Select(m => m >= MoveStrings.Length ? V190 : MoveStrings[m])); res[reqBase - 1].Comment += string.Format(Environment.NewLine + V181, em); break; } } // Non-Base moves that can magically appear in the regular movepool if (Legal.LightBall.Contains(pkm.Species)) { inheritMoves.Add(344); } // Begin verification of moves // If any splitbreed moves are invalid, flag accordingly var splitInvalid = false; var splitMoves = e.SplitBreed ? Legal.GetValidRelearn(pkm, Legal.GetBaseEggSpecies(pkm), inheritLvlMoves).ToList() : new List <int>(); // Inherited moves appear after the required base moves. for (int i = reqBase; i < 4; i++) { if (RelearnMoves[i] == 0) // empty { res[i] = new CheckResult(Severity.Valid, V167, CheckIdentifier.RelearnMove); } else if (inheritMoves.Contains(RelearnMoves[i])) // inherited { res[i] = new CheckResult(Severity.Valid, V172, CheckIdentifier.RelearnMove); } else if (e.SplitBreed && splitMoves.Contains(RelearnMoves[i])) // inherited { splitInvalid = true; } else // not inheritable, flag { res[i] = new CheckResult(Severity.Invalid, V182, CheckIdentifier.RelearnMove); } } if (splitInvalid) { var splitSpecies = Legal.GetBaseEggSpecies(pkm); for (int i = reqBase; i < 4; i++) { if (inheritMoves.Contains(RelearnMoves[i]) && !splitMoves.Contains(RelearnMoves[i])) { res[i] = new CheckResult(Severity.Invalid, string.Format(V379, SpeciesStrings[splitSpecies], SpeciesStrings[e.Species]), CheckIdentifier.RelearnMove); } if (!inheritMoves.Contains(RelearnMoves[i]) && splitMoves.Contains(RelearnMoves[i])) { res[i] = new CheckResult(Severity.Invalid, string.Format(V379, SpeciesStrings[e.Species], SpeciesStrings[splitSpecies]), CheckIdentifier.RelearnMove); } } } info.RelearnBase = baseMoves.ToArray(); return(res); }