From 76ff6290065d7f95b85b490d9c86f13ed390deef Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 5 Sep 2017 20:32:07 -0700 Subject: [PATCH] Flag invalid nsparkle previously would only flag if it was missing on npokemon also fix gen5 traded egg locations move egg ribbon verification to the new class --- PKHeX.Core/Legality/Checks.cs | 29 +++---------------- .../Legality/Encounters/EncounterVerifier.cs | 2 +- PKHeX.Core/Legality/Ribbons/RibbonVerifier.cs | 20 +++++++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 18d96ccbc..77af5d9fe 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -753,7 +753,8 @@ private void VerifyRibbons() var encounterContent = (EncounterMatch as MysteryGift)?.Content ?? EncounterMatch; if (pkm.IsEgg) { - VerifyRibbonsEgg(encounterContent); + if (RibbonVerifier.GetIncorrectRibbonsEgg(pkm, encounterContent)) + AddLine(Severity.Invalid, V603, CheckIdentifier.Ribbon); return; } @@ -763,28 +764,6 @@ private void VerifyRibbons() else AddLine(Severity.Valid, V602, CheckIdentifier.Ribbon); } - private void VerifyRibbonsEgg(object encounter) - { - var event3 = encounter as IRibbonSetEvent3; - var event4 = encounter as IRibbonSetEvent4; - var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon"); - if (event3 != null) - RibbonNames = RibbonNames.Except(event3.RibbonNames()); - if (event4 != null) - RibbonNames = RibbonNames.Except(event4.RibbonNames()); - - foreach (object RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName))) - { - if (!HasFlag(RibbonValue) && !HasCount(RibbonValue)) - continue; - - AddLine(Severity.Invalid, V603, CheckIdentifier.Ribbon); - return; - - bool HasFlag(object o) => o is bool z && z; - bool HasCount(object o) => o is int z && z > 0; - } - } private void VerifyCXD() { @@ -2017,7 +1996,7 @@ private void VerifyMisc() if (!Encounter.Valid) return; - if (Info.Generation == 5 && ((EncounterMatch as EncounterStatic)?.NSparkle ?? false)) + if (Info.Generation == 5) VerifyNsPKM(); switch (EncounterMatch) @@ -2102,7 +2081,7 @@ private void VerifyFatefulIngameActive() } private void VerifyNsPKM() { - bool req = (EncounterMatch as EncounterStatic)?.NSparkle ?? false; + bool req = EncounterMatch is EncounterStatic s && s.NSparkle; if (pkm.Format == 5) { bool has = ((PK5)pkm).NPokémon; diff --git a/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs b/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs index 8367e4784..06fbb00cc 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs @@ -138,7 +138,7 @@ private static CheckResult VerifyEncounterEgg(PKM pkm, IEncounterable egg) case 2: return new CheckResult(CheckIdentifier.Encounter); // no met location info case 3: return pkm.Format != 3 ? VerifyEncounterEgg3Transfer(pkm) : VerifyEncounterEgg3(pkm); case 4: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 02002) : VerifyEncounterEgg4(pkm); - case 5: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg5(pkm); + case 5: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30003) : VerifyEncounterEgg5(pkm); case 6: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg6(pkm); case 7: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg7(pkm); diff --git a/PKHeX.Core/Legality/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Ribbons/RibbonVerifier.cs index 431b5f4ee..ad4154d0b 100644 --- a/PKHeX.Core/Legality/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Ribbons/RibbonVerifier.cs @@ -21,6 +21,26 @@ internal static List GetIncorrectRibbons(PKM pkm, object encounterConten result.Add(string.Format(V601, string.Join(", ", invalidRibbons.Select(z => z.Replace("Ribbon", ""))))); return result; } + internal static bool GetIncorrectRibbonsEgg(PKM pkm, object encounterContent) + { + var event3 = encounterContent as IRibbonSetEvent3; + var event4 = encounterContent as IRibbonSetEvent4; + var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon"); + if (event3 != null) + RibbonNames = RibbonNames.Except(event3.RibbonNames()); + if (event4 != null) + RibbonNames = RibbonNames.Except(event4.RibbonNames()); + + foreach (object RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName))) + { + if (HasFlag(RibbonValue) || HasCount(RibbonValue)) + return true; + + bool HasFlag(object o) => o is bool z && z; + bool HasCount(object o) => o is int z && z > 0; + } + return false; + } private static IEnumerable GetRibbonResults(PKM pkm, object encounterContent, int gen) { return GetInvalidRibbons(pkm, gen)