From 4decaa73f7f659cf01411b5f299e9fa982da21d7 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 9 May 2020 20:47:32 -0700 Subject: [PATCH] Verify Contest stats on gen5 origin extract to separate logic class; only gen3+ call this (was originally called by gen6+); only really needs to include gen5 --- PKHeX.Core/Legality/Analysis.cs | 2 ++ PKHeX.Core/Legality/Checks.cs | 1 + .../Legality/Verifiers/ContestStatVerifier.cs | 36 +++++++++++++++++++ .../Legality/Verifiers/HistoryVerifier.cs | 20 +---------- 4 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 PKHeX.Core/Legality/Verifiers/ContestStatVerifier.cs diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index ef5d723be..a01fe13cb 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -318,6 +318,8 @@ namespace PKHeX.Core if (pkm.Format <= 6 && pkm.Format >= 4) EncounterType.Verify(this); // Gen 6->7 transfer deletes encounter type data + Contest.Verify(this); + if (pkm.Format < 6) return; diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 5d4a76637..373ea428e 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -25,6 +25,7 @@ namespace PKHeX.Core private static readonly Verifier CXD = new CXDVerifier(); private static readonly Verifier Memory = new MemoryVerifier(); private static readonly Verifier History = new HistoryVerifier(); + private static readonly Verifier Contest = new ContestStatVerifier(); private static readonly TrainerNameVerifier Trainer = new TrainerNameVerifier(); private static readonly LevelVerifier Level = new LevelVerifier(); diff --git a/PKHeX.Core/Legality/Verifiers/ContestStatVerifier.cs b/PKHeX.Core/Legality/Verifiers/ContestStatVerifier.cs new file mode 100644 index 000000000..b550fbc25 --- /dev/null +++ b/PKHeX.Core/Legality/Verifiers/ContestStatVerifier.cs @@ -0,0 +1,36 @@ +namespace PKHeX.Core +{ + /// + /// Verifies the Contest stat details. + /// + public class ContestStatVerifier : Verifier + { + protected override CheckIdentifier Identifier => CheckIdentifier.Memory; + public override void Verify(LegalityAnalysis data) + { + var pkm = data.pkm; + if (pkm.Format <= 4) + return; // legal || not present + + if (pkm is IContestStats s && s.HasContestStats() && !CanHaveContestStats(pkm, data.Info.Generation)) + data.AddLine(GetInvalid(LegalityCheckStrings.LContestZero)); + + // some encounters have contest stats built in. they're already checked by the initial encounter match. + } + + private static bool CanHaveContestStats(PKM pkm, int origin) + { + return origin switch + { + 1 => false, + 2 => false, + 3 => true, + 4 => true, + 5 => (pkm.Format >= 6), // ORAS Contests + 6 => (!pkm.IsUntraded || pkm.AO), + 7 => false, + _ => false + }; + } + } +} diff --git a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs index f7c8b08ad..1d3aa0307 100644 --- a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs @@ -22,15 +22,12 @@ namespace PKHeX.Core private void VerifyTradeState(LegalityAnalysis data) { var pkm = data.pkm; - var Info = data.Info; if (data.pkm is IGeoTrack t) VerifyGeoLocationData(data, t, data.pkm); if (pkm.VC && pkm is PK7 g && g.Geo1_Country == 0) // VC transfers set Geo1 Country data.AddLine(GetInvalid(LegalityCheckStrings.LGeoMemoryMissing)); - if (pkm is IContestStats s && s.HasContestStats() && !CanHaveContestStats(pkm, Info.Generation)) - data.AddLine(GetInvalid(LegalityCheckStrings.LContestZero)); if (!pkm.IsUntraded) { @@ -203,20 +200,5 @@ namespace PKHeX.Core _ => throw new IndexOutOfRangeException(), }; } - - private static bool CanHaveContestStats(PKM pkm, int origin) - { - return origin switch - { - 1 => false, - 2 => false, - 3 => true, - 4 => true, - 5 => (pkm.Format >= 6), // ORAS Contests - 6 => (!pkm.IsUntraded || pkm.AO), - 7 => false, - _ => false - }; - } } -} \ No newline at end of file +}