From 25565e6f07383ce1187a1f90f407379d6c5f2a18 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 20 Apr 2021 02:17:28 -0700 Subject: [PATCH] More pattern matching expressions Shapes are fancy; nested pattern checks --- PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs | 2 +- PKHeX.Core/Legality/Areas/EncounterArea8g.cs | 4 ++-- PKHeX.Core/Legality/Restrictions/GBRestrictions.cs | 2 +- PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs | 7 ++++--- PKHeX.Core/Saves/SAV4.cs | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs b/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs index b4b2db10e..e100ca250 100644 --- a/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/MoveSetApplicator.cs @@ -95,7 +95,7 @@ namespace PKHeX.Core } var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm); - if (encounter is IRelearn r && r.Relearn.Count > 0) + if (encounter is IRelearn {Relearn: {Count: > 0}} r) return r.Relearn; return m; diff --git a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs index bc9381813..c0331ab01 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs @@ -76,12 +76,12 @@ namespace PKHeX.Core var pi8 = (PersonalInfoSWSH)pt8[species]; if (pi8.IsPresentInGame) { - bool lgpe = (species <= 151 || species is 808 or 809) && (form == 0 || ptGG[species].HasForm(form)); + bool lgpe = (species is (<= 151 or 808 or 809)) && (form == 0 || ptGG[species].HasForm(form)); return lgpe ? GameVersion.GG : GameVersion.SWSH; } if (species <= Legal.MaxSpeciesID_7_USUM) { - bool lgpe = species <= 151 && (form == 0 || ptGG[species].HasForm(form)); + bool lgpe = species is <= 151 && (form == 0 || ptGG[species].HasForm(form)); return lgpe ? GameVersion.GG : GameVersion.USUM; } diff --git a/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs b/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs index 81d9b6a37..eec0fc47e 100644 --- a/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs +++ b/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs @@ -470,7 +470,7 @@ namespace PKHeX internal static bool IsTradedKadabraG1(PKM pkm) { - if (pkm is not PK1 pk1 || pk1.Species != (int)Kadabra) + if (pkm is not PK1 {Species: (int)Kadabra} pk1) return false; if (pk1.TradebackStatus == TradebackType.WasTradeback) return true; diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs index a4378c47c..ea6a2c499 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs @@ -440,9 +440,10 @@ namespace PKHeX.Core if (pkm.Version == 15 && enc is EncounterStaticShadow s) { // only require national ribbon if no longer on origin game - eb[1] = s.Version == GameVersion.XD - ? pkm is not XK3 x || x.RibbonNational - : pkm is not CK3 c || c.RibbonNational; + bool untraded = s.Version == GameVersion.XD + ? pkm is XK3 {RibbonNational: false} + : pkm is CK3 {RibbonNational: false}; + eb[1] = !untraded; } } diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index a195289a9..c11a766b9 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -444,7 +444,7 @@ namespace PKHeX.Core } for (int i = 8; i < 11; i++) // 3 PCD { - if (value[i] is PCD d && d.Gift.CardType != 0) + if (value[i] is PCD {Gift: {CardType: not 0}}) return true; } return false;