Exemple #1
0
        /// <summary>
        /// Checks the input <see cref="PKM"/> data for legality.
        /// </summary>
        /// <param name="pk">Input data to check</param>
        /// <param name="pi">Personal info to parse with</param>
        public LegalityAnalysis(PKM pk, PersonalInfo pi)
        {
            pkm          = pk;
            PersonalInfo = pi;

            if (pkm.Format <= 2) // prior to storing GameVersion
            {
                pkm.TradebackStatus = GBRestrictions.GetTradebackStatusInitial(pkm);
            }

#if SUPPRESS
            try
#endif
            {
                Info = EncounterFinder.FindVerifiedEncounter(pkm);
                if (!pkm.IsOriginValid)
                {
                    AddLine(Severity.Invalid, LEncConditionBadSpecies, CheckIdentifier.GameOrigin);
                }
                GetParseMethod()();

                if (Parse.Count == 0) // shouldn't ever happen as at least one is yielded above.
                {
                    AddLine(Severity.Invalid, L_AError, CheckIdentifier.Misc);
                    return;
                }

                Valid = Parse.All(chk => chk.Valid) &&
                        Info.Moves.All(m => m.Valid) &&
                        Info.Relearn.All(m => m.Valid);

                if (!Valid && pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid)
                {
                    AddLine(Severity.Indeterminate, LFatefulGiftMissing, CheckIdentifier.Fateful);
                }
                Parsed = true;
            }
#if SUPPRESS
            // We want to swallow any error from malformed input data from the user. The Valid state is all that we really need.
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Info  = new LegalInfo(pkm);
                Valid = false;
                AddLine(Severity.Invalid, L_AError, CheckIdentifier.Misc);
            }
#endif
        }
Exemple #2
0
        /// <summary>
        /// Checks the input <see cref="PKM"/> data for legality.
        /// </summary>
        /// <param name="pk">Input data to check</param>
        /// <param name="pi">Personal info to parse with</param>
        public LegalityAnalysis(PKM pk, PersonalInfo pi)
        {
            pkm          = pk;
            PersonalInfo = pi;

            if (pkm.Format <= 2) // prior to storing GameVersion
            {
                pkm.TradebackStatus = GBRestrictions.GetTradebackStatusInitial(pkm);
            }

#if SUPPRESS
            try
#endif
            {
                Info = EncounterFinder.FindVerifiedEncounter(pkm);
                if (!pkm.IsOriginValid)
                {
                    AddLine(Severity.Invalid, LEncConditionBadSpecies, CheckIdentifier.GameOrigin);
                }
                GetParseMethod()();

                if (Parse.Count == 0) // shouldn't ever happen as at least one is yielded above.
                {
                    AddLine(Severity.Invalid, L_AError, CheckIdentifier.Misc);
                    return;
                }

                Valid = Parse.All(chk => chk.Valid) &&
                        Info.Moves.All(m => m.Valid) &&
                        Info.Relearn.All(m => m.Valid);

                if (!Valid && pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid)
                {
                    AddLine(Severity.Indeterminate, LFatefulGiftMissing, CheckIdentifier.Fateful);
                }
                Parsed = true;
            }
#if SUPPRESS
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Info  = new LegalInfo(pkm);
                Valid = false;
                AddLine(Severity.Invalid, L_AError, CheckIdentifier.Misc);
            }
#endif
        }
Exemple #3
0
 private void UpdateInfo()
 {
     Info = EncounterFinder.FindVerifiedEncounter(pkm);
     Parse.AddRange(Info.Parse);
 }