From 514b60b447811aa01eb5f21a3408d826e971b11e Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 21 Dec 2020 22:33:48 -0800 Subject: [PATCH] Merge type check with usage in if statements if x is y with z property true, then :D --- .../Editing/Applicators/CatchRateApplicator.cs | 2 +- PKHeX.Core/Editing/CommonEdits.cs | 2 +- PKHeX.Core/Editing/Saves/BoxManipBase.cs | 2 +- PKHeX.Core/Editing/Saves/Slots/Extensions.cs | 2 +- PKHeX.Core/Legality/BulkAnalysis.cs | 8 +++----- .../Encounters/EncounterStatic/EncounterStatic.cs | 4 ++-- .../Generator/EncounterMovesetGenerator.cs | 2 +- .../Encounters/Generator/EncounterSlotGenerator.cs | 2 +- .../Encounters/Verifiers/EncounterVerifier.cs | 4 ++-- PKHeX.Core/Legality/Evolutions/EvolutionTree.cs | 12 ++++++------ PKHeX.Core/Legality/LegalityAnalysis.cs | 2 +- PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs | 4 ++-- PKHeX.Core/Legality/Verifiers/BallVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/LevelVerifier.cs | 4 ++-- PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs | 6 +++--- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 12 ++++++------ PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/PIDVerifier.cs | 4 ++-- .../Legality/Verifiers/Ribbons/RibbonVerifier.cs | 11 ++++++----- PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs | 4 ++-- PKHeX.Core/Legality/Verifiers/TransferVerifier.cs | 6 +++--- PKHeX.Core/Saves/SaveFileMetadata.cs | 2 +- PKHeX.Core/Saves/Util/BoxUtil.cs | 2 +- PKHeX.Drawing/Sprites/SpriteUtil.cs | 4 ++-- PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs | 2 +- PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs | 6 +++--- .../Subforms/Save Editors/Gen4/SAV_Misc4.cs | 3 ++- Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs | 2 +- 29 files changed, 60 insertions(+), 60 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/CatchRateApplicator.cs b/PKHeX.Core/Editing/Applicators/CatchRateApplicator.cs index f0cd809d4..9ac037a04 100644 --- a/PKHeX.Core/Editing/Applicators/CatchRateApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/CatchRateApplicator.cs @@ -24,7 +24,7 @@ { case EncounterTrade1 c: return c.GetInitialCatchRate(); - case EncounterStatic s when s.Version == GameVersion.Stadium && s.Species == (int)Species.Psyduck: + case EncounterStatic1E { Version: GameVersion.Stadium, Species: (int)Species.Psyduck}: return pk1.Japanese ? 167 : 168; // Amnesia Psyduck has different catch rates depending on language default: { diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs index 78735efff..1e1bcb5fe 100644 --- a/PKHeX.Core/Editing/CommonEdits.cs +++ b/PKHeX.Core/Editing/CommonEdits.cs @@ -415,7 +415,7 @@ namespace PKHeX.Core /// Precomputed optional public static void SetDefaultNickname(this PKM pk, LegalityAnalysis la) { - if (la.Parsed && la.EncounterOriginal is EncounterTrade t && t.HasNickname) + if (la.Parsed && la.EncounterOriginal is EncounterTrade {HasNickname: true} t) pk.SetNickname(t.GetNickname(pk.Language)); else pk.ClearNickname(); diff --git a/PKHeX.Core/Editing/Saves/BoxManipBase.cs b/PKHeX.Core/Editing/Saves/BoxManipBase.cs index 0a7fe7aca..11918fc4b 100644 --- a/PKHeX.Core/Editing/Saves/BoxManipBase.cs +++ b/PKHeX.Core/Editing/Saves/BoxManipBase.cs @@ -28,7 +28,7 @@ namespace PKHeX.Core new BoxManipSort(BoxManipType.SortLevelReverse, PKMSorting.OrderByDescendingLevel), new BoxManipSort(BoxManipType.SortDate, PKMSorting.OrderByDateObtained, s => s.Generation >= 4), new BoxManipSort(BoxManipType.SortName, list => list.OrderBySpeciesName(GameInfo.Strings.Species)), - new BoxManipSort(BoxManipType.SortFavorite, list => list.OrderByCustom(pk => pk is PB7 pb7 && pb7.Favorite), s => s is SAV7b), + new BoxManipSort(BoxManipType.SortFavorite, list => list.OrderByCustom(pk => pk is PB7 {Favorite: true}), s => s is SAV7b), new BoxManipSortComplex(BoxManipType.SortParty, (list, sav) => list.OrderByCustom(pk => ((SAV7b)sav).Blocks.Storage.GetPartyIndex(pk.Box - 1, pk.Slot - 1)), s => s is SAV7b), new BoxManipSort(BoxManipType.SortShiny, list => list.OrderByCustom(pk => !pk.IsShiny)), new BoxManipSort(BoxManipType.SortRandom, list => list.OrderByCustom(_ => Util.Rand32())), diff --git a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs index cfac8582e..41b28c396 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs @@ -174,7 +174,7 @@ namespace PKHeX.Core new(dc.Data, 0, Daycare8.GetDaycareSlotOffset(1, 1)) {Type = StorageSlotType.Daycare}, }; - if (sav is SAV8SWSH s8 && s8.SaveRevision >= 2) + if (sav is SAV8SWSH {SaveRevision: >= 2} s8) { var block = s8.Blocks.GetBlockSafe(SaveBlockAccessor8SWSH.KFusedCalyrex); var c = new SlotInfoMisc(block.Data, 3, 0, true) {Type = StorageSlotType.Fused}; diff --git a/PKHeX.Core/Legality/BulkAnalysis.cs b/PKHeX.Core/Legality/BulkAnalysis.cs index 393c0cb20..3900f67ec 100644 --- a/PKHeX.Core/Legality/BulkAnalysis.cs +++ b/PKHeX.Core/Legality/BulkAnalysis.cs @@ -115,9 +115,7 @@ namespace PKHeX.Core { var dupes = AllAnalysis.Where(z => z.Info.Generation >= 3 - && z.EncounterOriginal is MysteryGift g - && g.EggEncounter - && !z.pkm.WasTradedEgg) + && z.EncounterOriginal is MysteryGift {EggEncounter: true} && !z.pkm.WasTradedEgg) .GroupBy(z => ((MysteryGift)z.EncounterOriginal).CardTitle); foreach (var dupe in dupes) @@ -268,9 +266,9 @@ namespace PKHeX.Core private bool VerifyIDReuse(PKM pp, LegalityAnalysis pa, PKM cp, LegalityAnalysis ca) { - if (pa.EncounterMatch is MysteryGift g1 && !g1.EggEncounter) + if (pa.EncounterMatch is MysteryGift {EggEncounter: false}) return false; - if (ca.EncounterMatch is MysteryGift g2 && !g2.EggEncounter) + if (ca.EncounterMatch is MysteryGift {EggEncounter: false}) return false; const CheckIdentifier ident = CheckIdentifier.Trainer; diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs index da617848d..19bf02955 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs @@ -180,7 +180,7 @@ namespace PKHeX.Core return e.Language == EncounterGBLanguage.Japanese ? 1 : 2; // E-Reader was only available to Japanese games. - case EncounterStaticShadow s when s.EReader: + case EncounterStaticShadow {EReader: true}: // Old Sea Map was only distributed to Japanese games. case EncounterStatic3 _ when Species == (int)Core.Species.Mew: pk.OT_Name = "ゲーフリ"; @@ -200,7 +200,7 @@ namespace PKHeX.Core { switch (Generation) { - case 3 when this is EncounterStatic3 s3 && s3.Roaming && Version != GameVersion.E: // Roamer IV glitch was fixed in Emerald + case 3 when this is EncounterStatic3 {Roaming: true} && Version != GameVersion.E: // Roamer IV glitch was fixed in Emerald return PIDType.Method_1_Roamer; case 4 when Shiny == Shiny.Always: // Lake of Rage Gyarados return PIDType.ChainShiny; diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs index a0f108ece..b14c203c0 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs @@ -241,7 +241,7 @@ namespace PKHeX.Core var gifts = MysteryGiftGenerator.GetPossible(pk, chain); foreach (var gift in gifts) { - if (gift is WC3 wc3 && wc3.NotDistributed) + if (gift is WC3 {NotDistributed: true}) continue; if (needs.Count == 0) { diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs index cff3db9cf..e83e9b88b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs @@ -117,7 +117,7 @@ namespace PKHeX.Core private static bool IsHiddenAbilitySlot(this EncounterSlot slot) { - return (slot is EncounterSlot6AO ao && ao.CanDexNav) || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde || slot.Area.Type == SlotType.SOS; + return slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde || slot.Area.Type == SlotType.SOS; } internal static EncounterSlot? GetCaptureLocation(PKM pkm) diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs b/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs index 8bad992a1..87374684f 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs @@ -263,7 +263,7 @@ namespace PKHeX.Core switch (s.Generation) { case 3: - if (s is EncounterStaticShadow w && w.EReader && pkm.Language != (int)LanguageID.Japanese) // Non-JP E-reader Pokemon + if (s is EncounterStaticShadow {EReader: true} && pkm.Language != (int)LanguageID.Japanese) // Non-JP E-reader Pokemon return new CheckResult(Severity.Invalid, LG3EReader, CheckIdentifier.Encounter); if (pkm.Species == (int)Species.Mew && s.Location == 201 && pkm.Language != (int)LanguageID.Japanese) // Non-JP Mew (Old Sea Map) @@ -282,7 +282,7 @@ namespace PKHeX.Core case (int)Species.Arceus when s.Location == 086: // Azure Flute Arceus return new CheckResult(Severity.Invalid, LEncUnreleasedHoOArceus, CheckIdentifier.Encounter); } - if (pkm.Met_Location == 193 && s is EncounterStaticTyped t && t.TypeEncounter == EncounterType.Surfing_Fishing) // Roaming pokemon surfing in Johto Route 45 + if (pkm.Met_Location == 193 && s is EncounterStaticTyped {TypeEncounter: EncounterType.Surfing_Fishing}) // Roaming pokemon surfing in Johto Route 45 return new CheckResult(Severity.Invalid, LG4InvalidTileR45Surf, CheckIdentifier.Encounter); break; case 7: diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index f29ad8790..513a1e2a3 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -166,11 +166,11 @@ namespace PKHeX.Core { // Gigantamax Pikachu, Meowth-0, and Eevee are prevented from evolving. // Raichu cannot be evolved to the Alolan variant at this time. - BanEvo((int)Species.Raichu, 0, pkm => pkm is IGigantamax g && g.CanGigantamax); - BanEvo((int)Species.Raichu, 1, pkm => (pkm is IGigantamax g && g.CanGigantamax) || pkm.Version >= (int)GP || pkm.Version == (int)GO); - BanEvo((int)Species.Persian, 0, pkm => pkm is IGigantamax g && g.CanGigantamax); - BanEvo((int)Species.Persian, 1, pkm => pkm is IGigantamax g && g.CanGigantamax); - BanEvo((int)Species.Perrserker, 0, pkm => pkm is IGigantamax g && g.CanGigantamax); + BanEvo((int)Species.Raichu, 0, pkm => pkm is IGigantamax {CanGigantamax: true}); + BanEvo((int)Species.Raichu, 1, pkm => (pkm is IGigantamax {CanGigantamax: true}) || pkm.Version >= (int)GP || pkm.Version == (int)GO); + BanEvo((int)Species.Persian, 0, pkm => pkm is IGigantamax {CanGigantamax: true}); + BanEvo((int)Species.Persian, 1, pkm => pkm is IGigantamax {CanGigantamax: true}); + BanEvo((int)Species.Perrserker, 0, pkm => pkm is IGigantamax {CanGigantamax: true}); BanEvo((int)Species.Exeggutor, 1, pkm => pkm.Version >= (int)GP || pkm.Version == (int)GO); BanEvo((int)Species.Marowak, 1, pkm => pkm.Version >= (int)GP || pkm.Version == (int)GO); @@ -178,7 +178,7 @@ namespace PKHeX.Core BanEvo((int)Species.MrMime, 0, pkm => pkm.Version >= (int)SW); foreach (var s in GetEvolutions((int)Species.Eevee, 0)) // Eeveelutions - BanEvo(s, 0, pkm => pkm is IGigantamax g && g.CanGigantamax); + BanEvo(s, 0, pkm => pkm is IGigantamax {CanGigantamax: true}); } private void BanEvo(int species, int form, Func func) diff --git a/PKHeX.Core/Legality/LegalityAnalysis.cs b/PKHeX.Core/Legality/LegalityAnalysis.cs index d67c58849..b41dfbfc6 100644 --- a/PKHeX.Core/Legality/LegalityAnalysis.cs +++ b/PKHeX.Core/Legality/LegalityAnalysis.cs @@ -221,7 +221,7 @@ namespace PKHeX.Core if (pkm.Version == (int)GameVersion.CXD) CXD.Verify(this); - if (Info.EncounterMatch is WC3 z && z.NotDistributed) + if (Info.EncounterMatch is WC3 {NotDistributed: true}) AddLine(Severity.Invalid, LEncUnreleased, CheckIdentifier.Encounter); if (pkm.Format >= 8) diff --git a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs index 37dc48229..f75207c33 100644 --- a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs @@ -68,7 +68,7 @@ namespace PKHeX.Core } var enc = data.EncounterMatch; - if (enc is MysteryGift g && g.Generation >= 4) + if (enc is MysteryGift {Generation: >= 4} g) return VerifyAbilityMG(data, g, abilities); if (format < 6) @@ -298,7 +298,7 @@ namespace PKHeX.Core // hidden abilities if (enc is EncounterSlot slot) { - bool valid = (slot is EncounterSlot6AO ao && ao.CanDexNav) || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde; + bool valid = slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde; if (!valid) return GetInvalid(LAbilityMismatchHordeSafari); } diff --git a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs index 510fccf71..d74d26c69 100644 --- a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs @@ -32,7 +32,7 @@ namespace PKHeX.Core return VerifyBallMysteryGift(data, g); case EncounterTrade t: return VerifyBallEquals(data, t.Ball); - case EncounterStatic s when s.Gift: + case EncounterStatic {Gift: true} s: return VerifyBallEquals(data, s.Ball); case EncounterSlot8GO _: // Already a strict match return GetResult(true); diff --git a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs index afca2ced6..63ce58cc6 100644 --- a/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/HistoryVerifier.cs @@ -26,7 +26,7 @@ namespace PKHeX.Core 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 + if (pkm.VC && pkm is PK7 {Geo1_Country: 0}) // VC transfers set Geo1 Country data.AddLine(GetInvalid(LegalityCheckStrings.LGeoMemoryMissing)); if (!pkm.IsUntraded) diff --git a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs index e5968bfc7..e69c696c7 100644 --- a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs @@ -23,7 +23,7 @@ namespace PKHeX.Core break; case WC7 wc7 when wc7.MetLevel == pkm.Met_Level: break; - case PGT pgt when pgt.IsManaphyEgg && pkm.Met_Level == 0: + case PGT {IsManaphyEgg: true} when pkm.Met_Level == 0: break; default: data.AddLine(GetInvalid(LLevelMetGift)); @@ -46,7 +46,7 @@ namespace PKHeX.Core return; } - var reqEXP = EncounterMatch is EncounterStatic s && s.Version == GameVersion.C + var reqEXP = EncounterMatch is EncounterStatic {Version: GameVersion.C} ? 125 // Gen2 Dizzy Punch gifts always have 125 EXP, even if it's more than the Lv5 exp required. : Experience.GetEXP(elvl, pkm.PersonalInfo.EXPGrowth); if (reqEXP != pkm.EXP) diff --git a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs index 57204b988..987645d9b 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs @@ -143,13 +143,13 @@ namespace PKHeX.Core switch (data.EncounterMatch) { - case WC6 g when !g.IsEgg && g.OTGender != 3: + case WC6 {IsEgg: false} g when g.OTGender != 3: VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling); return; - case WC7 g when !g.IsEgg && g.OTGender != 3: + case WC7 {IsEgg: false} g when g.OTGender != 3: VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling); return; - case WC8 g when !g.IsEgg && g.OTGender != 3: + case WC8 {IsEgg: false} g when g.OTGender != 3: VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling); return; diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index a7673b424..62a0b0b41 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -49,7 +49,7 @@ namespace PKHeX.Core switch (pkm) { - case PK7 pk7 when pk7.ResortEventStatus >= 20: + case PK7 {ResortEventStatus: >= 20}: data.AddLine(GetInvalid(LTransferBad)); break; case PB7 pb7: @@ -137,7 +137,7 @@ namespace PKHeX.Core CheckResult GetWasNotTradeback() { - if ((e is EncounterStatic1 s && s.Version == GameVersion.Stadium) || e is EncounterTrade1) + if (e is EncounterStatic1E {Version: GameVersion.Stadium} || e is EncounterTrade1) return GetValid(LG1CatchRateMatchPrevious); // Encounters detected by the catch rate, cant be invalid if match this encounters int species = pk1.Species; @@ -164,7 +164,7 @@ namespace PKHeX.Core var EncounterMatch = data.EncounterMatch; switch (EncounterMatch) { - case WC3 w when w.Fateful: + case WC3 {Fateful: true} w: if (w.IsEgg) { // Eggs hatched in RS clear the obedience flag! @@ -187,7 +187,7 @@ namespace PKHeX.Core VerifyReceivability(data, g); VerifyFatefulMysteryGift(data, g); return; - case EncounterStatic s when s.Fateful: // ingame fateful + case EncounterStatic {Fateful: true}: // ingame fateful case EncounterSlot3PokeSpot _: // ingame pokespot case EncounterTrade4Ranch _: // ranch varied PID VerifyFatefulIngameActive(data); @@ -244,7 +244,7 @@ namespace PKHeX.Core private static void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g) { var pkm = data.pkm; - if (g is PGF p && p.IsShiny) + if (g is PGF {IsShiny: true}) { var Info = data.Info; Info.PIDIV = MethodFinder.Analyze(pkm); @@ -397,7 +397,7 @@ namespace PKHeX.Core } var enc = data.EncounterMatch; - bool originGMax = enc is IGigantamax g && g.CanGigantamax; + bool originGMax = enc is IGigantamax {CanGigantamax: true}; if (originGMax != pk8.CanGigantamax) { bool ok = !pk8.IsEgg && pk8.CanToggleGigantamax(pk8.Species, pk8.Form, enc.Species, enc.Form); diff --git a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs index 68ca82857..77e00e898 100644 --- a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs @@ -33,7 +33,7 @@ namespace PKHeX.Core { if (pkm.VC) VerifyG1NicknameWithinBounds(data, pkm.Nickname); - else if (EncounterMatch is MysteryGift m && !m.IsEgg) + else if (EncounterMatch is MysteryGift {IsEgg: false}) data.AddLine(Get(LEncGiftNicknamed, ParseSettings.NicknamedMysteryGift)); } diff --git a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs index 5fa126d6f..1b63f6fba 100644 --- a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs @@ -37,7 +37,7 @@ namespace PKHeX.Core if (!s.Shiny.IsValid(pkm)) data.AddLine(GetInvalid(LEncStaticPIDShiny, CheckIdentifier.Shiny)); - if (s is EncounterStatic8U u && u.Shiny == Shiny.Random) + if (s is EncounterStatic8U {Shiny: Shiny.Random}) { // Underground Raids are originally anti-shiny on encounter. // When selecting a prize at the end, the game rolls and force-shiny is applied to be XOR=1. @@ -119,7 +119,7 @@ namespace PKHeX.Core if (pkm.EncryptionConstant == 0) { - if (Info.EncounterMatch is WC8 wc8 && wc8.PID == 0 && wc8.EncryptionConstant == 0) + if (Info.EncounterMatch is WC8 {PID: 0, EncryptionConstant: 0}) return; // HOME Gifts data.AddLine(Get(LPIDEncryptZero, Severity.Fishy, CheckIdentifier.EC)); } diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs index eee346f44..50ea8b7bb 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs @@ -367,7 +367,8 @@ namespace PKHeX.Core { const int memChampion = 27; { - bool hasChampMemory = (pkm.Format == 8 && pkm is IMemoryHT h && h.HT_Memory == memChampion) || (pkm.Gen8 && pkm is IMemoryOT o && o.OT_Memory == memChampion); + bool hasChampMemory = (pkm.Format == 8 && pkm is IMemoryHT {HT_Memory: memChampion}) || + (pkm.Gen8 && pkm is IMemoryOT {OT_Memory: memChampion}); if (hasChampMemory && !s8.RibbonChampionGalar) yield return new RibbonResult(nameof(s8.RibbonChampionGalar)); } @@ -387,9 +388,9 @@ namespace PKHeX.Core // If the Tower Master ribbon is not present but a memory hint implies it should... // This memory can also be applied in Gen6/7 via defeating the Chatelaines, where legends are disallowed. const int strongest = 30; - if ((pkm is IMemoryOT o && o.OT_Memory == strongest) || (pkm is IMemoryHT h && h.HT_Memory == strongest)) + if (pkm is IMemoryOT {OT_Memory: strongest} || pkm is IMemoryHT {HT_Memory: strongest}) { - if (pkm.Gen8 || !IsAllowedBattleFrontier(pkm.Species) || (pkm is IRibbonSetCommon6 s6 && !s6.RibbonBattlerSkillful)) + if (pkm.Gen8 || !IsAllowedBattleFrontier(pkm.Species) || pkm is IRibbonSetCommon6 {RibbonBattlerSkillful: false}) yield return new RibbonResult(nameof(s8.RibbonTowerMaster)); } } @@ -398,7 +399,7 @@ namespace PKHeX.Core private static bool CanParticipateInRankedSWSH(PKM pkm) { - if (!pkm.SWSH && pkm is IBattleVersion v && v.BattleVersion == 0) + if (!pkm.SWSH && pkm is IBattleVersion {BattleVersion: 0}) return false; // Clamp to permitted species @@ -446,7 +447,7 @@ namespace PKHeX.Core var sb = set2.RibbonBits(); var eb = enc is IRibbonSetEvent4 e4 ? e4.RibbonBits() : new bool[sb.Length]; - if (enc is EncounterStatic7 s && s.Species == (int)Species.Magearna) + if (enc is EncounterStatic7 {Species: (int)Species.Magearna}) eb[1] = true; // require Wishing Ribbon for (int i = 0; i < sb.Length; i++) diff --git a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs index e97cb477d..4575ac1c3 100644 --- a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs @@ -22,7 +22,7 @@ namespace PKHeX.Core switch (data.EncounterMatch) { case EncounterTrade _: - case MysteryGift g when !g.IsEgg: + case MysteryGift {IsEgg: false}: case EncounterStatic5N _: return; // already verified } @@ -107,7 +107,7 @@ namespace PKHeX.Core if (tr.Length == 0) { - if (pkm is SK2 sk2 && sk2.TID == 0 && sk2.IsRental) + if (pkm is SK2 {TID: 0, IsRental: true}) { data.AddLine(Get(LOTShort, Severity.Fishy)); } diff --git a/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs b/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs index 5dd87ab37..951bcf4ed 100644 --- a/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs @@ -130,7 +130,7 @@ namespace PKHeX.Core } var enc = data.EncounterMatch; - if (enc.Version == GameVersion.GO || (enc is WC8 wc && wc.IsHOMEGift)) + if (enc.Version == GameVersion.GO || enc is WC8 {IsHOMEGift: true}) { VerifyHOMETracker(data, pkm); } @@ -166,7 +166,7 @@ namespace PKHeX.Core { // Tracker value is set via Transfer across HOME. // Can't validate the actual values (we aren't the server), so we can only check against zero. - if (pkm is IHomeTrack home && home.Tracker == 0) + if (pkm is IHomeTrack {Tracker: 0}) { data.AddLine(Get(LTransferTrackerMissing, ParseSettings.Gen8TransferTrackerNotPresent)); // To the reader: It seems like the best course of action for setting a tracker is: @@ -183,7 +183,7 @@ namespace PKHeX.Core yield return GetInvalid(LEggLocationNone); // Flag Moves that cannot be transferred - if (encounter is EncounterStatic s && s.Version == GameVersion.C && s.EggLocation == 256) // Dizzy Punch Gifts + if (encounter is EncounterStatic2Odd {Version: GameVersion.C, EggLocation: 256}) // Dizzy Punch Gifts FlagIncompatibleTransferMove(pkm, Moves, 146, 2); // can't have Dizzy Punch at all bool checkShiny = pkm.VC2 || (pkm.TradebackStatus == TradebackType.WasTradeback && pkm.VC1); diff --git a/PKHeX.Core/Saves/SaveFileMetadata.cs b/PKHeX.Core/Saves/SaveFileMetadata.cs index 6bd1f0a2b..d3086346d 100644 --- a/PKHeX.Core/Saves/SaveFileMetadata.cs +++ b/PKHeX.Core/Saves/SaveFileMetadata.cs @@ -131,7 +131,7 @@ namespace PKHeX.Core var flags = ExportFlags.None; if (ext == ".dsv") flags |= ExportFlags.IncludeFooter; - if (ext == ".gci" || (SAV is IGCSaveFile gc && !gc.IsMemoryCardSave)) + if (ext == ".gci" || SAV is IGCSaveFile {IsMemoryCardSave: false}) flags |= ExportFlags.IncludeHeader; return flags; } diff --git a/PKHeX.Core/Saves/Util/BoxUtil.cs b/PKHeX.Core/Saves/Util/BoxUtil.cs index 025ef6d77..0c08fdd9b 100644 --- a/PKHeX.Core/Saves/Util/BoxUtil.cs +++ b/PKHeX.Core/Saves/Util/BoxUtil.cs @@ -189,7 +189,7 @@ namespace PKHeX.Core case PKM pk: yield return pk; break; - case MysteryGift g when g.IsPokémon: + case MysteryGift {IsPokémon: true} g: yield return g.ConvertToPKM(sav); break; case GP1 g when g.Species != 0: diff --git a/PKHeX.Drawing/Sprites/SpriteUtil.cs b/PKHeX.Drawing/Sprites/SpriteUtil.cs index dede04998..f5983b6cc 100644 --- a/PKHeX.Drawing/Sprites/SpriteUtil.cs +++ b/PKHeX.Drawing/Sprites/SpriteUtil.cs @@ -94,7 +94,7 @@ namespace PKHeX.Drawing var formarg = pk is IFormArgument f ? f.FormArgument : 0; bool alt = pk.Format >= 8 && (pk.ShinyXor == 0 || pk.FatefulEncounter || pk.Version == (int)GameVersion.GO); var img = GetSprite(pk.Species, pk.Form, pk.Gender, formarg, pk.SpriteItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed, alt); - if (pk is IShadowPKM s && s.IsShadow) + if (pk is IShadowPKM {IsShadow: true}) { const int Lugia = 249; if (pk.Species == Lugia) // show XD shadow sprite @@ -103,7 +103,7 @@ namespace PKHeX.Drawing var glowImg = ImageUtil.GetBitmap(pixels, baseSprite.Width, baseSprite.Height, baseSprite.PixelFormat); return ImageUtil.LayerImage(glowImg, img, 0, 0); } - if (pk is IGigantamax g && g.CanGigantamax) + if (pk is IGigantamax {CanGigantamax: true}) { var gm = Resources.dyna; return ImageUtil.LayerImage(img, gm, (img.Width - gm.Width) / 2, 0); diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 68d5ea094..d28ebe1a2 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -494,7 +494,7 @@ namespace PKHeX.WinForms.Controls PB_MarkShiny.Image = GetMarkSprite(PB_MarkShiny, !BTN_Shinytize.Enabled); PB_MarkCured.Image = GetMarkSprite(PB_MarkCured, CHK_Cured.Checked); - PB_Favorite.Image = GetMarkSprite(PB_Favorite, Entity is IFavorite f && f.Favorite); + PB_Favorite.Image = GetMarkSprite(PB_Favorite, Entity is IFavorite {Favorite: true}); PB_Origin.Image = GetOriginSprite(Entity); // Colored Markings diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 41e168dc3..a478290d3 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -1081,13 +1081,13 @@ namespace PKHeX.WinForms.Controls B_Roamer.Enabled = sav is SAV3; B_OpenHoneyTreeEditor.Enabled = B_OpenUGSEditor.Enabled = sav is SAV4Sinnoh; - B_OpenApricorn.Enabled = sav is SAV4 s4 && s4.HGSS; + B_OpenApricorn.Enabled = sav is SAV4HGSS; B_OpenRTCEditor.Enabled = sav.Generation == 2 || (sav is SAV3 s3 && (s3.RS || s3.E)); B_MailBox.Enabled = sav is SAV2 || sav is SAV3 || sav is SAV4 || sav is SAV5; B_Raids.Enabled = sav is SAV8SWSH; - B_RaidArmor.Enabled = sav is SAV8SWSH ss1 && ss1.SaveRevision >= 1; - B_RaidCrown.Enabled = sav is SAV8SWSH ss2 && ss2.SaveRevision >= 2; + B_RaidArmor.Enabled = sav is SAV8SWSH {SaveRevision: >= 1}; + B_RaidCrown.Enabled = sav is SAV8SWSH {SaveRevision: >= 2}; B_Blocks.Enabled = true; SL_Extra.SAV = sav; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs index aa68a198c..830344364 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs @@ -589,7 +589,8 @@ namespace PKHeX.WinForms { if (editing) return; - if (sender is RadioButton radioButton && !radioButton.Checked) return; + if (sender is RadioButton {Checked: false}) + return; StatAddrControl(SetValToSav: -2, SetSavToVal: true); if (GB_Hall.Visible) { diff --git a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs index f2ef31dcc..ca2865b8c 100644 --- a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs +++ b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs @@ -175,7 +175,7 @@ namespace PKHeX.Tests.Simulator var set = new ShowdownSet(text); var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, CurrentLevel = set.Level }; var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves); - var tr3 = encs.First(z => z is EncounterTrade t && t.Generation == 3); + var tr3 = encs.First(z => z is EncounterTrade3); var pk3 = tr3.ConvertToPKM(new SAV3()); var la = new LegalityAnalysis(pk3);