public static IEnumerable <IEncounterable> GetEncounters(PKM pkm, EvoCriteria[] chain) { if (pkm.IsEgg) { yield break; } int ctr = 0; if (pkm.FatefulEncounter) { foreach (var z in GetValidGifts(pkm, chain)) { yield return(z); ++ctr; } if (ctr != 0) { yield break; } } IEncounterable? cache = null; EncounterMatchRating rating = None; // Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded. var encs = GetValidStaticEncounter(pkm, chain); foreach (var z in encs) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } if (cache != null) { yield return(cache); } }
private static IEnumerable <IEncounterable> GenerateRawEncounters3CXD(PKM pkm) { var chain = EncounterOrigin.GetOriginChain(pkm); // Mystery Gifts foreach (var z in GetValidGifts(pkm, chain)) { // Don't bother deferring matches. var match = z.GetMatchRating(pkm); if (match != PartialMatch) { yield return(z); } } // Trades foreach (var z in GetValidEncounterTrades(pkm, chain)) { // Don't bother deferring matches. var match = z.GetMatchRating(pkm); if (match != PartialMatch) { yield return(z); } } IEncounterable?partial = null; // Static Encounter foreach (var z in GetValidStaticEncounter(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) { partial ??= z; } else { yield return(z); } } // Encounter Slots foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) { partial ??= z; continue; } yield return(z); } if (partial is not null) { yield return(partial); } }
private static IEnumerable <IEncounterable> GenerateRawEncounters12(PKM pkm, GameVersion game) { // Since encounter matching is super weak due to limited stored data in the structure // Calculate all 3 at the same time and pick the best result (by species). // Favor special event move gifts as Static Encounters when applicable var chain = EncounterOrigin.GetOriginChain12(pkm, game); IEncounterable?deferred = null; foreach (var t in GetValidEncounterTradesVC(pkm, chain, game)) { // Gen2 trades are strictly matched (OT/Nick), while Gen1 trades allow for deferral (shrug). if (t is EncounterTrade1 t1 && t1.GetMatchRating(pkm) != Match) { deferred ??= t; continue; } yield return(t); } foreach (var s in GetValidStaticEncounter(pkm, chain, game)) { yield return(s); } foreach (var e in GetValidWildEncounters12(pkm, chain, game)) { yield return(e); } if (game != GameVersion.RBY) { foreach (var e in GenerateEggs(pkm, chain)) { yield return(e); } } foreach (var s in GenerateGBEvents(pkm, chain, game)) { yield return(s); } if (deferred != null) { yield return(deferred); } }
private static IEnumerable <IEncounterable> GetEncounters3CXD(PKM pkm, LegalInfo info) { info.PIDIV = MethodFinder.Analyze(pkm); IEncounterable?Partial = null; foreach (var z in GenerateRawEncounters3CXD(pkm)) { if (z is EncounterSlot3PokeSpot w) { var seeds = MethodFinder.GetPokeSpotSeeds(pkm, w.SlotNumber); foreach (var s in seeds) { info.PIDIV = s; break; } } else if (z is EncounterStaticShadow s) { bool valid = GetIsShadowLockValid(pkm, info, s); if (!valid) { Partial ??= s; continue; } } if (info.PIDIV.Type.IsCompatible3(z, pkm)) { yield return(z); } else { Partial ??= z; } } if (Partial == null) { yield break; } info.PIDIVMatches = false; yield return(Partial); }
private static IEnumerable <IEncounterable> GetEncounters3(PKM pkm, LegalInfo info) { info.PIDIV = MethodFinder.Analyze(pkm); IEncounterable?Partial = null; foreach (var z in GenerateRawEncounters3(pkm, info)) { if (info.PIDIV.Type.IsCompatible3(z, pkm)) { yield return(z); } else { Partial ??= z; } } if (Partial == null) { yield break; } info.PIDIVMatches = false; yield return(Partial); }
public static IEnumerable <IEncounterable> GetEncounters(PKM pkm, EvoCriteria[] chain) { int ctr = 0; if (pkm.FatefulEncounter) { foreach (var z in GetValidGifts(pkm, chain)) { yield return(z); ++ctr; } if (ctr != 0) { yield break; } } if (Locations.IsEggLocationBred8b(pkm.Egg_Location)) { foreach (var z in GenerateEggs(pkm, 8)) { yield return(z); ++ctr; } if (ctr == 0) { yield break; } } IEncounterable? cache = null; EncounterMatchRating rating = None; // Trades if (!pkm.IsEgg && pkm.Met_Location == Locations.LinkTrade6NPC) { foreach (var z in GetValidEncounterTrades(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } if (cache != null) { yield return(cache); } yield break; } // Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded. var encs = GetValidStaticEncounter(pkm, chain); foreach (var z in encs) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } if (cache != null) { yield return(cache); } }
/// <summary> /// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>. /// </summary> /// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param> /// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param> /// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns> public static IReadOnlyList <int> GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterable?enc = null) { var m = legal.GetSuggestedRelearnMovesFromEncounter(); if (m.Any(z => z != 0)) { return(m); } enc ??= legal.EncounterMatch; if (enc is MysteryGift or EncounterEgg) { return(m); } if (enc is EncounterSlot6AO { CanDexNav : true } dn) { var moves = legal.Info.Moves; for (int i = 0; i < moves.Length; i++) { if (moves[i].Valid) { continue; } var move = legal.pkm.GetMove(i); if (dn.CanBeDexNavMove(move)) { return new[] { move, 0, 0, 0 } } ; } } var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm); if (encounter is IRelearn r && r.Relearn.Count > 0) { return(r.Relearn); } return(m); } }
/// <summary> /// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>. /// </summary> /// <param name="pk">Pokémon to modify.</param> /// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will try to detect it via legality analysis. </param> /// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns> public static IReadOnlyList <int> GetSuggestedRelearnMoves(this PKM pk, IEncounterable?enc = null) => GetSuggestedRelearnMoves(new LegalityAnalysis(pk), enc);
public static IEnumerable <IEncounterable> GetEncounters(PKM pkm) { int ctr = 0; var chain = EncounterOrigin.GetOriginChain(pkm); IEncounterable?deferred = null; IEncounterable?partial = null; if (pkm.WasEvent || pkm.WasEventEgg || pkm.WasLink) { foreach (var z in GetValidGifts(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } ++ctr; } if (ctr != 0) { if (deferred != null) { yield return(deferred); } if (partial != null) { yield return(partial); } yield break; } } if (pkm.WasBredEgg) { foreach (var z in GenerateEggs(pkm, 6)) { yield return(z); ++ctr; } if (ctr == 0) { yield break; } } foreach (var z in GetValidStaticEncounter(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidEncounterTrades(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); /*++ctr*/ break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (deferred != null) { yield return(deferred); } if (partial != null) { yield return(partial); } }
private static IEnumerable <IEncounterable> GenerateRawEncounters3(PKM pkm, LegalInfo info) { var chain = EncounterOrigin.GetOriginChain(pkm); // Mystery Gifts foreach (var z in GetValidGifts(pkm, chain)) { // Don't bother deferring matches. var match = z.GetMatchRating(pkm); if (match != PartialMatch) { yield return(z); } } // Trades foreach (var z in GetValidEncounterTrades(pkm, chain)) { // Don't bother deferring matches. var match = z.GetMatchRating(pkm); if (match != PartialMatch) { yield return(z); } } IEncounterable?deferred = null; IEncounterable?partial = null; // Static Encounter // Defer everything if Safari Ball bool safari = pkm.Ball == 0x05; // never static encounters if (!safari) { foreach (var z in GetValidStaticEncounter(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) { partial ??= z; } else { yield return(z); } } } // Encounter Slots var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList(); foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) { partial ??= z; continue; } var frame = slots.Find(s => s.IsSlotCompatibile((EncounterSlot3)z, pkm)); if (frame == null) { deferred ??= z; continue; } yield return(z); } info.FrameMatches = false; if (deferred is EncounterSlot3 x) { yield return(x); } if (pkm.Version != (int)GameVersion.CXD) // no eggs in C/XD { foreach (var z in GenerateEggs(pkm, 3)) { yield return(z); } } if (partial is EncounterSlot3 y) { var frame = slots.Find(s => s.IsSlotCompatibile(y, pkm)); info.FrameMatches = frame != null; yield return(y); } // do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm if (!safari) { yield break; } partial = null; foreach (var z in GetValidStaticEncounter(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) { partial ??= z; } else { yield return(z); } } if (partial is not null) { yield return(partial); } }
public static IEnumerable <IEncounterable> GetEncounters(PKM pk) { int ctr = 0; var chain = EncounterOrigin.GetOriginChain(pk); var game = (GameVersion)pk.Version; IEncounterable?deferred = null; IEncounterable?partial = null; if (pk.FatefulEncounter || pk.Met_Location == Locations.LinkGift6) { foreach (var z in GetValidGifts(pk, chain, game)) { var match = z.GetMatchRating(pk); switch (match) { case Match: yield return(z); break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } ++ctr; } if (ctr != 0) { if (deferred != null) { yield return(deferred); } if (partial != null) { yield return(partial); } yield break; } } if (Locations.IsEggLocationBred6(pk.Egg_Location)) { foreach (var z in GenerateEggs(pk, 6)) { yield return(z); ++ctr; } if (ctr == 0) { yield break; } } foreach (var z in GetValidStaticEncounter(pk, chain, game)) { var match = z.GetMatchRating(pk); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidWildEncounters(pk, chain, game)) { var match = z.GetMatchRating(pk); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidEncounterTrades(pk, chain, game)) { var match = z.GetMatchRating(pk); switch (match) { case Match: yield return(z); /*++ctr*/ break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (deferred != null) { yield return(deferred); } if (partial != null) { yield return(partial); } }
public static IEnumerable <IEncounterable> GetEncountersFuzzy(PKM pk, EvoCriteria[] chain, GameVersion game) { int ctr = 0; if (pk.FatefulEncounter) { foreach (var z in GetValidGifts(pk, chain, game)) { yield return(z); ++ctr; } if (ctr != 0) { yield break; } } if (pk.Egg_Location == Locations.HOME_SWSHBDSPEgg && pk.Met_Level == 1) { foreach (var z in GenerateEggs(pk, 8)) { yield return(z); ++ctr; } if (ctr == 0) { yield break; } } IEncounterable? cache = null; EncounterMatchRating rating = None; // Trades if (!pk.IsEgg) { foreach (var z in GetValidEncounterTrades(pk, chain, game)) { var match = z.GetMatchRating(pk); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } if (cache != null) { yield return(cache); } } // Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded. var encs = GetValidStaticEncounter(pk, chain, game); foreach (var z in encs) { var match = z.GetMatchRating(pk); if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } // Only yield if Safari and Marsh encounters match. bool safari = pk is PK8 { Ball : (int)Ball.Safari }; foreach (var z in GetValidWildEncounters(pk, chain, game)) { var marsh = Locations.IsSafariZoneLocation8b(z.Location); var match = z.GetMatchRating(pk); if (safari != marsh) { match = DeferredErrors; } if (match == Match) { yield return(z); } else if (match < rating) { cache = z; rating = match; } } if (cache != null) { yield return(cache); } } }
public static IEnumerable <IEncounterable> GetEncounters(PKM pkm) { int ctr = 0; var chain = EncounterOrigin.GetOriginChain(pkm); if (pkm.FatefulEncounter) { foreach (var z in GetValidGifts(pkm, chain)) { yield return(z); ++ctr; } if (ctr != 0) { yield break; } } if (Locations.IsEggLocationBred5(pkm.Egg_Location)) { foreach (var z in GenerateEggs(pkm, 5)) { yield return(z); ++ctr; } if (ctr == 0) { yield break; } } IEncounterable?deferred = null; IEncounterable?partial = null; foreach (var z in GetValidStaticEncounter(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); ++ctr; break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (ctr != 0) { yield break; } foreach (var z in GetValidEncounterTrades(pkm, chain)) { var match = z.GetMatchRating(pkm); switch (match) { case Match: yield return(z); /*++ctr*/ break; case Deferred: deferred ??= z; break; case PartialMatch: partial ??= z; break; } } if (deferred != null) { yield return(deferred); } if (partial != null) { yield return(partial); } }