Ejemplo n.º 1
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters.GetEnumerator()))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }
                return(info);
            }
        }
Ejemplo n.º 2
0
        public static EncounterStatic GetSuggestedMetInfo(PKM pkm)
        {
            if (pkm == null)
            {
                return(null);
            }

            int loc = GetSuggestedTransferLocation(pkm);

            if (pkm.WasEgg)
            {
                return(GetSuggestedEncounterEgg(pkm, loc));
            }

            var w = EncounterGenerator.GetCaptureLocation(pkm);

            if (w != null)
            {
                return(GetSuggestedEncounterWild(w, loc));
            }

            var s = EncounterGenerator.GetStaticLocation(pkm);

            if (s != null)
            {
                return(GetSuggestedEncounterStatic(s, loc));
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void UpdateTypeInfo()
        {
            if (pkm.Format >= 7)
            {
                if (pkm.VC1)
                {
                    Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level);
                }
                else if (pkm.VC2)
                {
                    Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level);
                }
            }

            if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && (EncounterMatch as GBEncounterData)?.Generation != pkm.GenNumber)
            {
                // Example: GSC Pokemon with only possible encounters in RBY, like the legendary birds
                pkm.TradebackStatus = TradebackType.WasTradeback;
            }

            Type = (EncounterOriginalGB ?? EncounterMatch)?.GetType();
            var bt = Type.GetTypeInfo().BaseType;

            if (bt != null && !(bt == typeof(Array) || bt == typeof(object) || bt.GetTypeInfo().IsPrimitive)) // a parent exists
            {
                Type = bt;                                                                                    // use base type
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            var info       = new LegalInfo(pkm);
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                return(VerifyWithoutEncounter(pkm, info));
            }

            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);

            while (encounter.MoveNext())
            {
                info.EncounterMatch = encounter.Current;
                var e = EncounterValidator(pkm, info);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }
                info.Parse.Add(e);

                if (VerifySecondaryChecks(pkm, info, encounter))
                    break; // passes
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 5
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <param name="info">Object to store matched encounter info</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static void FindVerifiedEncounter(PKM pkm, LegalInfo info)
        {
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                VerifyWithoutEncounter(pkm, info);
                return;
            }

            var first = encounter.Current;
            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(first.Generation);

            while (encounter.MoveNext())
            {
                var enc = encounter.Current;

                // Check for basic compatibility.
                var e = EncounterValidator(pkm, enc);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }

                // Looks like we might have a good enough match. Check if this is really a good match.
                info.EncounterMatch = enc;
                info.Parse.Add(e);
                if (!VerifySecondaryChecks(pkm, info, encounter))
                {
                    continue;
                }

                // Sanity Check -- Some secondary checks might not be as thorough as the partial-match leak-through checks done by the encounter.
                if (enc is not IEncounterMatch mx)
                {
                    break;
                }

                var match = mx.GetMatchRating(pkm);
                if (match != EncounterMatchRating.PartialMatch)
                {
                    break;
                }

                // Reaching here implies the encounter wasn't valid. Try stepping to the next encounter.
                if (encounter.PeekIsNext())
                {
                    continue;
                }

                // We ran out of possible encounters without finding a suitable match; add a message indicating that the encounter is not a complete match.
                info.Parse.Add(new CheckResult(Severity.Invalid, LEncInvalid, CheckIdentifier.Encounter));
                break;
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 6
0
 private void UpdateVCTransferInfo()
 {
     EncounterOriginalGB = EncounterMatch;
     if (pkm.VC1)
         Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level);
     else if (pkm.VC2)
         Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level);
     foreach (var z in VerifyVCEncounter(pkm, EncounterOriginalGB.Species, EncounterOriginalGB as GBEncounterData, Info.EncounterMatch as EncounterStatic))
         AddLine(z);
 }
Ejemplo n.º 7
0
 private void VerifyTrade12(LegalityAnalysis data, EncounterTrade t)
 {
     if (t.TID != 0) // Gen2 Trade
     {
         return;     // already checked all relevant properties when fetching with getValidEncounterTradeVC2
     }
     if (!EncounterGenerator.IsEncounterTrade1Valid(data.pkm, t))
     {
         data.AddLine(GetInvalid(LEncTradeChangedOT, CheckIdentifier.Trainer));
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <param name="info">Object to store matched encounter info</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static void FindVerifiedEncounter(PKM pkm, LegalInfo info)
        {
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                VerifyWithoutEncounter(pkm, info);
                return;
            }

            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);

            while (encounter.MoveNext())
            {
                info.EncounterMatch = encounter.Current;
                var e = EncounterValidator(pkm, info);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }
                info.Parse.Add(e);

                if (!VerifySecondaryChecks(pkm, info, encounter))
                {
                    continue;
                }

                // Sanity Check -- Some secondary checks might not be as thorough as the partial-match leak-through checks done by the encounter.
                if (info.EncounterMatch is not IEncounterMatch mx)
                {
                    break;
                }

                var match = mx.GetMatchRating(pkm);
                if (match != EncounterMatchRating.PartialMatch)
                {
                    break;
                }

                if (encounter.PeekIsNext())
                {
                    continue;
                }

                info.Parse.Add(new CheckResult(Severity.Invalid, LEncInvalid, CheckIdentifier.Encounter));
                break;
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 9
0
        private void UpdateVCTransferInfo()
        {
            EncounterOriginalGB = EncounterMatch;
            Info.EncounterMatch = EncounterGenerator.GetVCStaticTransferEncounter(pkm);
            if (!(Info.EncounterMatch is EncounterStatic s) || !EncounterGenerator.IsVCStaticTransferEncounterValid(pkm, s))
            {
                AddLine(Severity.Invalid, V80, CheckIdentifier.Encounter); return;
            }

            foreach (var z in VerifyVCEncounter(pkm, EncounterOriginalGB.Species, EncounterOriginalGB as GBEncounterData, s))
            {
                AddLine(z);
            }
        }
Ejemplo n.º 10
0
        public EncounterStatic GetSuggestedMetInfo()
        {
            if (pkm == null)
            {
                return(null);
            }

            int loc = GetSuggestedTransferLocation(pkm);

            if (pkm.WasEgg)
            {
                int lvl = 1; // gen5+
                if (!pkm.IsNative)
                {
                    lvl = pkm.CurrentLevel; // be generous with transfer conditions
                }
                else if (pkm.Format < 5)    // and native
                {
                    lvl = 0;
                }
                return(new EncounterStatic
                {
                    Species = Legal.GetBaseSpecies(pkm),
                    Location = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm),
                    Level = lvl,
                });
            }

            var area = EncounterGenerator.GetCaptureLocation(pkm);

            if (area != null)
            {
                var slots = area.Slots.OrderBy(s => s.LevelMin);
                return(new EncounterStatic
                {
                    Species = slots.First().Species,
                    Location = loc != -1 ? loc : area.Location,
                    Level = slots.First().LevelMin,
                });
            }

            var encounter = EncounterGenerator.GetStaticLocation(pkm);

            if (loc != -1 && encounter != null)
            {
                encounter.Location = loc;
            }
            return(encounter);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }

                if (!info.FrameMatches && info.EncounterMatch is EncounterSlot && pkm.Version != (int)GameVersion.CXD) // if false, all valid RNG frame matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Fishy, LEncConditionBadRNGFrame, CheckIdentifier.PID));    // todo for further confirmation
                }
                if (!info.PIDIVMatches)                                                                                // if false, all valid PIDIV matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Invalid, LPIDTypeMismatch, CheckIdentifier.PID));
                }

                return(info);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters.GetEnumerator()))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }

                if (!info.PIDIVMatches) // if false, all valid PIDIV matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Invalid, V411, CheckIdentifier.PID));
                }

                return(info);
            }
        }
Ejemplo n.º 13
0
        public static CheckResult[] VerifyRelearn(PKM pkm, LegalInfo info)
        {
            if (info.Generation < 6 || pkm.VC1)
            {
                return(VerifyRelearnNone(pkm, info));
            }

            if (info.EncounterMatch is EncounterLink l)
            {
                return(VerifyRelearnSpecifiedMoveset(pkm, info, l.RelearnMoves));
            }
            if (info.EncounterMatch is MysteryGift g)
            {
                return(VerifyRelearnSpecifiedMoveset(pkm, info, g.RelearnMoves));
            }
            if (info.EncounterMatch is EncounterStatic s)
            {
                return(VerifyRelearnSpecifiedMoveset(pkm, info, s.Relearn));
            }

            if (info.EncounterMatch is EncounterEgg e)
            {
                return(VerifyRelearnEggBase(pkm, info, e));
            }

            if (pkm.RelearnMove1 != 0 && info.EncounterMatch is EncounterSlot z && z.Permissions.DexNav && EncounterGenerator.IsDexNavValid(pkm))
            {
                return(VerifyRelearnDexNav(pkm, info));
            }

            return(VerifyRelearnNone(pkm, info));
        }