From ee5349ff98a780ce6fc92cfbf4e97df348a1cbea Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 25 Dec 2020 12:30:26 -0800 Subject: [PATCH] moar is or --- .../Editing/Applicators/MarkingApplicator.cs | 11 ++-- PKHeX.Core/Editing/ShowdownSet.cs | 14 ++--- .../GameStrings/FilteredGameDataSource.cs | 2 +- PKHeX.Core/Game/GameStrings/GameStrings.cs | 2 +- PKHeX.Core/Legality/Areas/EncounterArea8g.cs | 2 +- PKHeX.Core/Legality/BulkAnalysis.cs | 8 +-- .../Legality/Encounters/Data/Encounters7b.cs | 2 +- .../EncounterSlot/IEncounterTypeTile.cs | 2 +- .../EncounterStatic/EncounterStatic1.cs | 2 +- .../EncounterStatic/EncounterStatic6.cs | 2 +- .../EncounterStatic/EncounterStatic8NC.cs | 4 +- .../EncounterStatic/EncounterStatic8Nest.cs | 2 +- .../EncounterTrade/EncounterTrade.cs | 2 +- .../Generator/EncounterSlotGenerator.cs | 2 +- .../Legality/Evolutions/EvolutionTree.cs | 6 +- .../Legality/Evolutions/EvolutionType.cs | 2 +- PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs | 2 +- PKHeX.Core/Legality/RNG/MethodFinder.cs | 10 +-- PKHeX.Core/Legality/RNG/PIDGenerator.cs | 14 ++--- PKHeX.Core/Legality/Restrictions/Locale3DS.cs | 19 +++--- PKHeX.Core/Legality/Tables/FormInfo.cs | 2 +- PKHeX.Core/Legality/Tables/Locations.cs | 4 +- .../Legality/Verifiers/AbilityVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/BallVerifier.cs | 4 +- PKHeX.Core/Legality/Verifiers/FormVerifier.cs | 2 +- .../Legality/Verifiers/LanguageVerifier.cs | 2 +- .../Legality/Verifiers/MedalVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 2 +- .../Legality/Verifiers/NicknameVerifier.cs | 4 +- .../Verifiers/Ribbons/RibbonVerifier.cs | 8 +-- PKHeX.Core/MysteryGifts/MysteryUtil.cs | 2 +- PKHeX.Core/MysteryGifts/PGT.cs | 4 +- PKHeX.Core/MysteryGifts/WB7.cs | 2 +- PKHeX.Core/MysteryGifts/WC8.cs | 4 +- PKHeX.Core/PKM/PK2.cs | 2 +- PKHeX.Core/PKM/PK7.cs | 2 +- PKHeX.Core/PKM/PKM.cs | 63 ++++++++++--------- PKHeX.Core/PKM/Shared/G4PKM.cs | 2 +- PKHeX.Core/PKM/Shared/GBPKM.cs | 2 +- PKHeX.Core/PKM/Shared/IGigantamax.cs | 4 +- PKHeX.Core/PKM/Shared/PokeListGB.cs | 2 +- PKHeX.Core/PKM/Util/FormConverter.cs | 2 +- PKHeX.Core/PKM/Util/ItemConverter.cs | 8 +-- PKHeX.Core/PKM/Util/Language.cs | 4 +- PKHeX.Core/PKM/Util/PKX.cs | 4 +- PKHeX.Core/PKM/Util/PokeCrypto.cs | 4 +- PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs | 2 +- .../Saves/MemeCrypto/SCBlockMetadata.cs | 2 +- PKHeX.Core/Saves/SAV3.cs | 12 ++-- PKHeX.Core/Saves/SAV3RSBox.cs | 2 +- PKHeX.Core/Saves/SAV8.cs | 8 ++- PKHeX.Core/Saves/SaveFile.cs | 2 +- PKHeX.Core/Saves/SaveFileMetadata.cs | 2 +- PKHeX.Core/Saves/Storage/BulkStorage.cs | 2 +- .../Substructures/Gen5/CGearBackground.cs | 5 +- .../Saves/Substructures/Gen5/Daycare5.cs | 4 +- .../Saves/Substructures/Gen5/PWTBlock5.cs | 4 +- .../Substructures/Gen7/CaptureRecords.cs | 2 +- .../Substructures/Gen7/WormholeInfoReader.cs | 4 +- .../Substructures/Gen8/RaidSpawnList8.cs | 4 +- PKHeX.Core/Saves/Substructures/Mail/Mail2.cs | 14 ++--- .../Saves/Substructures/PokeDex/Zukan.cs | 2 +- .../Saves/Substructures/PokeDex/Zukan7.cs | 16 +++-- .../Saves/Substructures/PokeDex/Zukan8.cs | 16 +++-- PKHeX.Core/Saves/Util/SaveUtil.cs | 2 +- .../Controls/PKM Editor/LoadSave.cs | 2 +- .../Controls/SAV Editor/SAVEditor.cs | 8 +-- PKHeX.WinForms/MainWindow/Main.cs | 2 +- .../Subforms/Save Editors/Gen4/SAV_Misc4.cs | 2 +- .../Save Editors/Gen4/SAV_Pokedex4.cs | 2 +- .../Subforms/Save Editors/Gen5/SAV_Misc5.cs | 15 +---- .../Save Editors/Gen6/SAV_HallOfFame.cs | 3 +- .../Subforms/Save Editors/Gen6/SAV_Trainer.cs | 2 +- .../Save Editors/Gen7/SAV_PokedexGG.cs | 2 +- .../Save Editors/Gen7/SAV_Trainer7.cs | 6 +- .../Save Editors/Gen7/SAV_ZygardeCell.cs | 2 +- .../Subforms/Save Editors/SAV_Inventory.cs | 2 +- .../Subforms/Save Editors/SAV_MailBox.cs | 12 ++-- .../Save Editors/SAV_SimpleTrainer.cs | 2 +- .../Subforms/Save Editors/SAV_Wondercard.cs | 3 +- 80 files changed, 205 insertions(+), 218 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/MarkingApplicator.cs b/PKHeX.Core/Editing/Applicators/MarkingApplicator.cs index 2eff4fb4e..b03273681 100644 --- a/PKHeX.Core/Editing/Applicators/MarkingApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/MarkingApplicator.cs @@ -77,11 +77,12 @@ public static int[] ToggleMarking(this PKM pk, int index, int[] markings) static int GetSimpleMarking(int val, int _) => val == 31 ? 1 : 0; static int GetComplexMarking(int val, int _) { - if (val == 31 || val == 1) - return 1; - if (val == 30 || val == 0) - return 2; - return 0; + return val switch + { + 31 or 1 => 1, + 30 or 0 => 2, + _ => 0, + }; } } } diff --git a/PKHeX.Core/Editing/ShowdownSet.cs b/PKHeX.Core/Editing/ShowdownSet.cs index 1efd851b4..04497c3e4 100644 --- a/PKHeX.Core/Editing/ShowdownSet.cs +++ b/PKHeX.Core/Editing/ShowdownSet.cs @@ -639,17 +639,17 @@ private static string ConvertFormFromShowdown(string form, int spec, int ability switch (spec) { - case (int)Core.Species.Basculin when form == "Blue-Striped": + case (int)Core.Species.Basculin when form is "Blue-Striped": return "Blue"; case (int)Core.Species.Greninja when ability == 210: return "Ash"; // Battle Bond - case (int)Core.Species.Vivillon when form == "Pokeball": + case (int)Core.Species.Vivillon when form is "Pokeball": return "Poké Ball"; // Zygarde case (int)Core.Species.Zygarde when form.Length == 0: return ability == 211 ? "50%-C" : "50%"; - case (int)Core.Species.Zygarde when form == "Complete": + case (int)Core.Species.Zygarde when form is "Complete": return form; case (int)Core.Species.Zygarde when ability == 211: return "-C"; // Power Construct @@ -662,18 +662,18 @@ private static string ConvertFormFromShowdown(string form, int spec, int ability return $"C-{form}"; // Necrozma - case (int)Core.Species.Necrozma when form == "Dusk-Mane" || form == "Dusk Mane": + case (int)Core.Species.Necrozma when form is "Dusk-Mane" or "Dusk Mane": return "Dusk"; - case (int)Core.Species.Necrozma when form == "Dawn-Wings" || form == "Dawn Wings": + case (int)Core.Species.Necrozma when form is "Dawn-Wings" or "Dawn Wings": return "Dawn"; // Toxtricity - case (int)Core.Species.Toxtricity when form == "Low-Key": + case (int)Core.Species.Toxtricity when form is "Low-Key": return "Low Key"; // Darmanitan case (int)Core.Species.Darmanitan: - if (form == "Galar-Zen") + if (form is "Galar-Zen") return "Galar Zen"; return form; diff --git a/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs b/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs index bfa4a1d15..04c61eb6d 100644 --- a/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs +++ b/PKHeX.Core/Game/GameStrings/FilteredGameDataSource.cs @@ -45,7 +45,7 @@ private static IEnumerable GetFilteredSpecies(IGameValueLimit sav, Ga return sav switch { SAV7b => source.SpeciesDataSource // LGPE: Kanto 151, Meltan/Melmetal - .Where(s => s.Value <= (int)Core.Species.Mew || s.Value == (int)Core.Species.Meltan || s.Value == (int)Core.Species.Melmetal), + .Where(s => s.Value <= (int)Core.Species.Mew || s.Value is (int)Core.Species.Meltan or (int)Core.Species.Melmetal), _ => source.SpeciesDataSource.Where(s => s.Value <= sav.MaxSpeciesID) }; } diff --git a/PKHeX.Core/Game/GameStrings/GameStrings.cs b/PKHeX.Core/Game/GameStrings/GameStrings.cs index 220d13b4a..55541c1d1 100644 --- a/PKHeX.Core/Game/GameStrings/GameStrings.cs +++ b/PKHeX.Core/Game/GameStrings/GameStrings.cs @@ -257,7 +257,7 @@ private void SanitizeMetLocations() SanitizeMetG7SM(); SanitizeMetG8SWSH(); - if (lang == "es" || lang == "it") + if (lang is "es" or "it") { // Campeonato Mundial duplicates for (int i = 27; i < 34; i++) diff --git a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs index ff4dc2e6e..0a7ba4dfc 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea8g.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea8g.cs @@ -74,7 +74,7 @@ private static GameVersion GetGroup(int species, int form) var pi8 = (PersonalInfoSWSH)pt8[species]; if (pi8.IsPresentInGame) { - bool lgpe = (species <= 151 || species == 808 || species == 809) && (form == 0 || ptGG[species].HasForm(form)); + bool lgpe = (species <= 151 || species is 808 or 809) && (form == 0 || ptGG[species].HasForm(form)); return lgpe ? GameVersion.GG : GameVersion.SWSH; } if (species <= Legal.MaxSpeciesID_7_USUM) diff --git a/PKHeX.Core/Legality/BulkAnalysis.cs b/PKHeX.Core/Legality/BulkAnalysis.cs index 3900f67ec..f1bbbf877 100644 --- a/PKHeX.Core/Legality/BulkAnalysis.cs +++ b/PKHeX.Core/Legality/BulkAnalysis.cs @@ -225,9 +225,9 @@ private void VerifyECShare(LegalityAnalysis pa, LegalityAnalysis ca) // eggs/mystery gifts shouldn't share with wild encounters var cenc = ca.Info.EncounterMatch; - bool eggMysteryCurrent = cenc is EncounterEgg || cenc is MysteryGift; + bool eggMysteryCurrent = cenc is EncounterEgg or MysteryGift; var penc = pa.Info.EncounterMatch; - bool eggMysteryPrevious = penc is EncounterEgg || penc is MysteryGift; + bool eggMysteryPrevious = penc is EncounterEgg or MysteryGift; if (eggMysteryCurrent != eggMysteryPrevious) { @@ -254,9 +254,9 @@ private void VerifyPIDShare(LegalityAnalysis pa, LegalityAnalysis ca) // eggs/mystery gifts shouldn't share with wild encounters var cenc = ca.Info.EncounterMatch; - bool eggMysteryCurrent = cenc is EncounterEgg || cenc is MysteryGift; + bool eggMysteryCurrent = cenc is EncounterEgg or MysteryGift; var penc = pa.Info.EncounterMatch; - bool eggMysteryPrevious = penc is EncounterEgg || penc is MysteryGift; + bool eggMysteryPrevious = penc is EncounterEgg or MysteryGift; if (eggMysteryCurrent != eggMysteryPrevious) { diff --git a/PKHeX.Core/Legality/Encounters/Data/Encounters7b.cs b/PKHeX.Core/Legality/Encounters/Data/Encounters7b.cs index 1d8b78518..9f1cf4e2f 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Encounters7b.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Encounters7b.cs @@ -123,7 +123,7 @@ private static void ManuallyAddRareSpawns(IEnumerable areas) var slots = table.Slots; var first = slots[0]; var extra = species - .Select(z => new EncounterSlot7b(table, z, (z == 006 || z >= 144) ? 03 : first.LevelMin, (z == 006 || z >= 144) ? 56 : first.LevelMax)).ToArray(); + .Select(z => new EncounterSlot7b(table, z, (z is 006 or >= 144) ? 03 : first.LevelMin, (z is 006 or >= 144) ? 56 : first.LevelMax)).ToArray(); int count = slots.Length; Array.Resize(ref slots, count + extra.Length); diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/IEncounterTypeTile.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/IEncounterTypeTile.cs index 4b9e77d16..0a67a53c8 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/IEncounterTypeTile.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/IEncounterTypeTile.cs @@ -21,6 +21,6 @@ public static class EncounterTypeTileExtensions /// Gets if the resulting will still have a value depending on the current . /// /// Generation 6 no longer stores this value. - public static bool HasTypeEncounter(this IEncounterTypeTile _, int format) => format == 4 || format == 5; + public static bool HasTypeEncounter(this IEncounterTypeTile _, int format) => format is 4 or 5; } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1.cs index 1775c90af..5f75324a4 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1.cs @@ -58,7 +58,7 @@ private bool IsCatchRateValid(PK1 pk1) // Amnesia Psyduck has different catch rates depending on language if (Species == (int)Core.Species.Psyduck) return catch_rate == (pk1.Japanese ? 167 : 168); - return catch_rate == 167 || catch_rate == 168; + return catch_rate is 167 or 168; } // Encounters can have different Catch Rates (RBG vs Y) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic6.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic6.cs index 40e5eaa28..4a976bf80 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic6.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic6.cs @@ -40,7 +40,7 @@ protected override bool IsMatchLocation(PKM pkm) // Cosplay Pikachu is given from multiple locations var loc = pkm.Met_Location; - return loc == 180 || loc == 186 || loc == 194; + return loc is 180 or 186 or 194; } protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs index 216bb3261..a9afbbd0f 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8NC.cs @@ -11,7 +11,7 @@ public sealed record EncounterStatic8NC : EncounterStatic8Nest Level) return false; - if (lvl < 20 || lvl > 55) + if (lvl is < 20 or > 55) return false; return lvl % 5 == 0; } diff --git a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs index be0eaac54..a8c2e06fd 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterTrade/EncounterTrade.cs @@ -204,7 +204,7 @@ private void UpdateEdgeCase(PKM pkm) pkm.Language = (int)(pkm.Language == (int)LanguageID.German ? LanguageID.English : LanguageID.German); break; - case 4 when Version == GameVersion.DPPt && (pkm.Version == (int)GameVersion.D || pkm.Version == (int)GameVersion.P): + case 4 when Version == GameVersion.DPPt && (pkm.Version is (int)GameVersion.D or (int)GameVersion.P): // DP English origin are Japanese lang pkm.Language = (int)LanguageID.Japanese; break; diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs index 4a842280f..ab8b6e5f6 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs @@ -119,7 +119,7 @@ private static IEnumerable GetEncounterAreas(PKM pkm, GameVersion private static bool IsHiddenAbilitySlot(this EncounterSlot slot) { - return slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde || slot.Area.Type == SlotType.SOS; + return slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type is SlotType.FriendSafari or SlotType.Horde or SlotType.SOS; } internal static EncounterSlot? GetCaptureLocation(PKM pkm) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index 513a1e2a3..10a859ec6 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -167,13 +167,13 @@ private void FixEvoTreeSS() // 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 {CanGigantamax: true}); - BanEvo((int)Species.Raichu, 1, pkm => (pkm is IGigantamax {CanGigantamax: true}) || pkm.Version >= (int)GP || pkm.Version == (int)GO); + BanEvo((int)Species.Raichu, 1, pkm => (pkm is IGigantamax {CanGigantamax: true}) || pkm.Version is (int)GO or >= (int)GP); 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); + BanEvo((int)Species.Exeggutor, 1, pkm => pkm.Version is (int)GO or >= (int)GP); + BanEvo((int)Species.Marowak, 1, pkm => pkm.Version is (int)GO or >= (int)GP); BanEvo((int)Species.Weezing, 0, pkm => pkm.Version >= (int)SW); BanEvo((int)Species.MrMime, 0, pkm => pkm.Version >= (int)SW); diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionType.cs b/PKHeX.Core/Legality/Evolutions/EvolutionType.cs index 57dc3c454..572dde1a2 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionType.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionType.cs @@ -58,7 +58,7 @@ public enum EvolutionType : byte public static class EvolutionTypeExtensions { - public static bool IsTrade(this EvolutionType t) => t == Trade || t == TradeHeldItem || t == TradeSpecies; + public static bool IsTrade(this EvolutionType t) => t is Trade or TradeHeldItem or TradeSpecies; public static bool IsLevelUpRequired(this EvolutionType t) => t.ToString().StartsWith("LevelUp"); // don't use this } } \ No newline at end of file diff --git a/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs b/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs index 3f4f20a74..02aff615c 100644 --- a/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs +++ b/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs @@ -62,7 +62,7 @@ private static IEnumerable RefineFrames3(IEnumerable frames, Frame yield return f; // Generate frames for other slots after the regular slots - if (info.AllowLeads && (f.Lead == LeadRequired.CuteCharm || f.Lead == LeadRequired.None)) + if (info.AllowLeads && (f.Lead is LeadRequired.CuteCharm or LeadRequired.None)) list.Add(f); } foreach (var f in list) diff --git a/PKHeX.Core/Legality/RNG/MethodFinder.cs b/PKHeX.Core/Legality/RNG/MethodFinder.cs index 7720fdc78..6b80a4334 100644 --- a/PKHeX.Core/Legality/RNG/MethodFinder.cs +++ b/PKHeX.Core/Legality/RNG/MethodFinder.cs @@ -825,13 +825,13 @@ public static bool IsCompatible3(this PIDType val, IEncounterable encounter, PKM if (val == PIDType.CXDAnti && g.Shiny == Shiny.Never && g.Method == PIDType.CXD) return true; // forced shiny eggs, when hatched, can lose their detectable correlation. - return g.IsEgg && !pkm.IsEgg && val == PIDType.None && (g.Method == PIDType.BACD_R_S || g.Method == PIDType.BACD_U_S); + return g.IsEgg && !pkm.IsEgg && val == PIDType.None && (g.Method is PIDType.BACD_R_S or PIDType.BACD_U_S); case EncounterStaticShadow: - return pkm.Version == (int)GameVersion.CXD && (val == PIDType.CXD || val == PIDType.CXDAnti); + return pkm.Version == (int)GameVersion.CXD && (val is PIDType.CXD or PIDType.CXDAnti); case EncounterStatic3 s: return pkm.Version switch { - (int)GameVersion.CXD => val == PIDType.CXD || val == PIDType.CXD_ColoStarter || val == PIDType.CXDAnti, + (int)GameVersion.CXD => val is PIDType.CXD or PIDType.CXD_ColoStarter or PIDType.CXDAnti, (int)GameVersion.E => val == PIDType.Method_1, // no roamer glitch (int)GameVersion.FR or (int)GameVersion.LG => s.Roaming ? val.IsRoamerPIDIV(pkm) : val == PIDType.Method_1, // roamer glitch _ => s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val), // RS, roamer glitch && RSBox s/w emulation => method 4 available @@ -880,7 +880,7 @@ public static bool IsCompatible4(this PIDType val, IEncounterable encounter, PKM // Chain shiny with poke radar is only possible in DPPt in tall grass, safari zone do not allow pokeradar // TypeEncounter TallGrass discard any cave or city var ver = (GameVersion)pkm.Version; - var IsDPPt = ver == GameVersion.D || ver == GameVersion.P || ver == GameVersion.Pt; + var IsDPPt = ver is GameVersion.D or GameVersion.P or GameVersion.Pt; return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Locations.IsSafariZoneLocation4(sl.Location); case PGT: // manaphy return IsG4ManaphyPIDValid(val, pkm); @@ -915,7 +915,7 @@ bool IsAntiShinyARNG() private static bool IsCuteCharm4Valid(IEncounterable encounter, PKM pkm) { - if (pkm.Species == (int)Species.Marill || pkm.Species == (int)Species.Azumarill) + if (pkm.Species is (int)Species.Marill or (int)Species.Azumarill) { return !IsCuteCharmAzurillMale(pkm.PID) // recognized as not Azurill || encounter.Species == (int)Species.Azurill; // encounter must be male Azurill diff --git a/PKHeX.Core/Legality/RNG/PIDGenerator.cs b/PKHeX.Core/Legality/RNG/PIDGenerator.cs index 1bff696fe..d647fd42d 100644 --- a/PKHeX.Core/Legality/RNG/PIDGenerator.cs +++ b/PKHeX.Core/Legality/RNG/PIDGenerator.cs @@ -9,7 +9,7 @@ private static void SetValuesFromSeedLCRNG(PKM pk, PIDType type, uint seed) var rng = RNG.LCRNG; var A = rng.Next(seed); var B = rng.Next(A); - var skipBetweenPID = type == PIDType.Method_3 || type == PIDType.Method_3_Unown; + var skipBetweenPID = type is PIDType.Method_3 or PIDType.Method_3_Unown; if (skipBetweenPID) // VBlank skip between PID rand() [RARE] B = rng.Next(B); @@ -20,12 +20,12 @@ private static void SetValuesFromSeedLCRNG(PKM pk, PIDType type, uint seed) pk.PID = (B & 0xFFFF0000) | A >> 16; var C = rng.Next(B); - var skipIV1Frame = type == PIDType.Method_2 || type == PIDType.Method_2_Unown; + var skipIV1Frame = type is PIDType.Method_2 or PIDType.Method_2_Unown; if (skipIV1Frame) // VBlank skip after PID C = rng.Next(C); var D = rng.Next(C); - var skipIV2Frame = type == PIDType.Method_4 || type == PIDType.Method_4_Unown; + var skipIV2Frame = type is PIDType.Method_4 or PIDType.Method_4_Unown; if (skipIV2Frame) // VBlank skip between IVs D = rng.Next(D); @@ -43,7 +43,7 @@ private static void SetValuesFromSeedLCRNG(PKM pk, PIDType type, uint seed) private static void SetValuesFromSeedBACD(PKM pk, PIDType type, uint seed) { var rng = RNG.LCRNG; - bool shiny = type == PIDType.BACD_R_S || type == PIDType.BACD_U_S; + bool shiny = type is PIDType.BACD_R_S or PIDType.BACD_U_S; uint X = shiny ? rng.Next(seed) : seed; var A = rng.Next(X); var B = rng.Next(A); @@ -58,7 +58,7 @@ private static void SetValuesFromSeedBACD(PKM pk, PIDType type, uint seed) pk.PID = PID; } - else if (type == PIDType.BACD_R_AX || type == PIDType.BACD_U_AX) + else if (type is PIDType.BACD_R_AX or PIDType.BACD_U_AX) { uint low = B >> 16; pk.PID = ((A & 0xFFFF0000) ^ (((uint)pk.TID ^ (uint)pk.SID ^ low) << 16)) | low; @@ -70,7 +70,7 @@ private static void SetValuesFromSeedBACD(PKM pk, PIDType type, uint seed) pk.IVs = MethodFinder.GetIVsInt32(C >> 16, D >> 16); - bool antishiny = type == PIDType.BACD_R_A || type == PIDType.BACD_U_A; + bool antishiny = type is PIDType.BACD_R_A or PIDType.BACD_U_A; while (antishiny && pk.IsShiny) pk.PID = unchecked(pk.PID + 1); } @@ -232,7 +232,7 @@ public static uint GetPokeWalkerPID(int TID, int SID, uint nature, int gender, i // Ensure nature is set to required nature without affecting shininess pid += nature - (pid % 25); - if (gr >= 0xFE || gr == 0) // non-dual gender + if (gr is 0 or >= 0xFE) // non-dual gender return pid; // Ensure Gender is set to required gender without affecting other properties diff --git a/PKHeX.Core/Legality/Restrictions/Locale3DS.cs b/PKHeX.Core/Legality/Restrictions/Locale3DS.cs index 00b9683bc..55b695047 100644 --- a/PKHeX.Core/Legality/Restrictions/Locale3DS.cs +++ b/PKHeX.Core/Legality/Restrictions/Locale3DS.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// Provides information for and data. @@ -17,17 +15,14 @@ public static bool IsConsoleRegionCountryValid(int consoleRegion, int country) { return consoleRegion switch { - 0 => (country == 1), // Japan - 1 => ((8 <= country && country <= 52) || ExtendedAmericas.Contains(country)), // Americas - 2 => ((64 <= country && country <= 127) || ExtendedEurope.Contains(country)), // Europe - 4 => (country == 144 || country == 160), // China - 5 => (country == 136), // Korea - 6 => (country == 144 || country == 128), // Taiwan + 0 => country is 1, // Japan + 1 => (8 <= country && country <= 52) || (country is 153 or 156 or 168 or 174 or 186), // Americas + 2 => (64 <= country && country <= 127) || (country is 169 or 184 or 185), // Europe + 4 => country is 144 or 160, // China + 5 => country is 136, // Korea + 6 => country is 144 or 128, // Taiwan _ => false }; } - - private static readonly HashSet ExtendedAmericas = new() { 153, 156, 168, 174, 186 }; - private static readonly HashSet ExtendedEurope = new() { 169, 184, 185 }; } } diff --git a/PKHeX.Core/Legality/Tables/FormInfo.cs b/PKHeX.Core/Legality/Tables/FormInfo.cs index cce13ee77..998b75140 100644 --- a/PKHeX.Core/Legality/Tables/FormInfo.cs +++ b/PKHeX.Core/Legality/Tables/FormInfo.cs @@ -220,7 +220,7 @@ public static bool IsTotemForm(int species, int form, int format) if (!Legal.Totem_USUM.Contains(species)) return false; if (species == (int)Mimikyu) - return form == 2 || form == 3; + return form is 2 or 3; if (Legal.Totem_Alolan.Contains(species)) return form == 2; return form == 1; diff --git a/PKHeX.Core/Legality/Tables/Locations.cs b/PKHeX.Core/Legality/Tables/Locations.cs index 331049d29..4cf7d8381 100644 --- a/PKHeX.Core/Legality/Tables/Locations.cs +++ b/PKHeX.Core/Legality/Tables/Locations.cs @@ -121,7 +121,7 @@ public static int TradedEggLocation(int gen) private const int SafariLocation_FRLG = 136; private const int SafariLocation_HGSS = 202; private const int MarshLocation_DPPt = 52; - public static bool IsSafariZoneLocation3(int loc) => loc == SafariLocation_RSE || loc == SafariLocation_FRLG; - public static bool IsSafariZoneLocation4(int loc) => loc == MarshLocation_DPPt || loc == SafariLocation_HGSS; + public static bool IsSafariZoneLocation3(int loc) => loc is SafariLocation_RSE or SafariLocation_FRLG; + public static bool IsSafariZoneLocation4(int loc) => loc is MarshLocation_DPPt or SafariLocation_HGSS; } } diff --git a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs index 30b0d6305..b59bc43ee 100644 --- a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs @@ -298,7 +298,7 @@ private CheckResult VerifyAbility6(LegalityAnalysis data, IEncounterable enc) // hidden abilities if (enc is EncounterSlot slot) { - bool valid = slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde; + bool valid = slot is EncounterSlot6AO {CanDexNav: true} || slot.Area.Type is SlotType.FriendSafari or SlotType.Horde; if (!valid) return GetInvalid(LAbilityMismatchHordeSafari); } diff --git a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs index afb4d568c..157052c25 100644 --- a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs @@ -209,7 +209,7 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) { if (!Legal.Inherit_Sport.Contains(species)) return GetInvalid(LBallSpecies); - if ((species == (int)Species.Volbeat || species == (int)Species.Illumise) && IsHiddenAndNotPossible(pkm)) // Volbeat/Illumise + if ((species is (int)Species.Volbeat or (int)Species.Illumise) && IsHiddenAndNotPossible(pkm)) // Volbeat/Illumise return GetInvalid(LBallAbility); return GetValid(LBallSpeciesPass); } @@ -293,7 +293,7 @@ private CheckResult VerifyBallEggGen8(LegalityAnalysis data) { if (!Legal.Inherit_Sport.Contains(species)) return GetInvalid(LBallSpecies); - if ((species == (int)Species.Volbeat || species == (int)Species.Illumise) && IsHiddenAndNotPossible(pkm)) // Volbeat/Illumise + if ((species is (int)Species.Volbeat or (int)Species.Illumise) && IsHiddenAndNotPossible(pkm)) // Volbeat/Illumise return GetInvalid(LBallAbility); return GetValid(LBallSpeciesPass); } diff --git a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs index ce2364b03..c5e1896d5 100644 --- a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs @@ -196,7 +196,7 @@ bool IsValidPikachuCap() { // We're okay here. There's also Alolan Meowth... } - else if ((orig == (int) Species.MrMime || orig == (int)Species.MimeJr) && pkm.CurrentLevel > data.EncounterOriginal.LevelMin && Info.Generation >= 4) + else if ((orig is (int) Species.MrMime or (int)Species.MimeJr) && pkm.CurrentLevel > data.EncounterOriginal.LevelMin && Info.Generation >= 4) { // We're okay with a Mime Jr. that has evolved via level up. } diff --git a/PKHeX.Core/Legality/Verifiers/LanguageVerifier.cs b/PKHeX.Core/Legality/Verifiers/LanguageVerifier.cs index 965bbf1b8..84f9e6cb4 100644 --- a/PKHeX.Core/Legality/Verifiers/LanguageVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LanguageVerifier.cs @@ -24,7 +24,7 @@ public override void Verify(LegalityAnalysis data) // Korean Gen4 games can not trade with other Gen4 languages, but can use Pal Park with any Gen3 game/language. if (pkm.Format == 4 && pkm.Gen4 && !IsValidG4Korean(currentLanguage) - && !(data.EncounterMatch is EncounterTrade x && (x.Species == (int)Species.Pikachu || x.Species == (int)Species.Magikarp)) // ger magikarp / eng pikachu + && !(data.EncounterMatch is EncounterTrade4 {Species: (int)Species.Pikachu or (int)Species.Magikarp}) // ger magikarp / eng pikachu ) { bool kor = currentLanguage == (int)LanguageID.Korean; diff --git a/PKHeX.Core/Legality/Verifiers/MedalVerifier.cs b/PKHeX.Core/Legality/Verifiers/MedalVerifier.cs index 1add60a2e..79dff3858 100644 --- a/PKHeX.Core/Legality/Verifiers/MedalVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MedalVerifier.cs @@ -38,7 +38,7 @@ private void VerifyMedalsRegular(LegalityAnalysis data) return; } - if (Info.Generation >= 7 || Info.Generation <= 2) + if (Info.Generation is >= 7 or <= 2) { // Can't have any super training data if it never visited Gen6. if (TrainCount > 0) diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index f859f62a5..c59bddcb1 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -109,7 +109,7 @@ private void VerifyMiscG1Types(LegalityAnalysis data, PK1 pk1) var Type_B_Match = Type_B == pi.Type2; var first = Type_A_Match ? GetValid(LG1TypeMatch1) : GetInvalid(LG1Type1Fail); - var second = Type_B_Match || (ParseSettings.AllowGBCartEra && ((species == (int)Species.Magnemite || species == (int)Species.Magneton) && Type_B == 9)) // Steel Magnemite via Stadium2 + var second = Type_B_Match || (ParseSettings.AllowGBCartEra && ((species is (int)Species.Magnemite or (int)Species.Magneton) && Type_B == 9)) // Steel Magnemite via Stadium2 ? GetValid(LG1TypeMatch2) : GetInvalid(LG1Type2Fail); data.AddLine(first); data.AddLine(second); diff --git a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs index 77e00e898..11d924400 100644 --- a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs @@ -251,7 +251,7 @@ private static void VerifyTrade4(LegalityAnalysis data, EncounterTrade t) break; default: - if (lang == 1 && (pkm.Version == (int)GameVersion.D || pkm.Version == (int)GameVersion.P)) + if (lang == 1 && (pkm.Version is (int)GameVersion.D or (int)GameVersion.P)) { // DP English origin are Japanese lang if (pkm.OT_Name != t.GetOT(1)) // not japanese @@ -333,7 +333,7 @@ private static void VerifyTrade5(LegalityAnalysis data, EncounterTrade t) } else // B2W2 { - if (t.TID == Encounters5.YancyTID || t.TID == Encounters5.CurtisTID) + if (t.TID is Encounters5.YancyTID or Encounters5.CurtisTID) VerifyTradeOTOnly(data, t); else VerifyTrade(data, t, lang); diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs index 50ea8b7bb..baa76ff17 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs @@ -123,7 +123,7 @@ private static IEnumerable GetInvalidRibbons(PKM pkm, IEncounterab var c4 = u4.RibbonBitsContest4(); var c4n = u4.RibbonNamesContest4(); - var iter4 = (gen == 3 || gen == 4) && IsAllowedInContest4(pkm.Species) ? GetMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n); + var iter4 = (gen is 3 or 4) && IsAllowedInContest4(pkm.Species) ? GetMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n); foreach (var z in iter4) yield return z; } @@ -207,8 +207,8 @@ private static IEnumerable GetInvalidRibbons4Any(PKM pkm, IRibbonS if (s4.RibbonFootprint && !CanHaveFootprintRibbon(pkm, gen)) yield return new RibbonResult(nameof(s4.RibbonFootprint)); - bool gen34 = gen == 3 || gen == 4; - bool not6 = pkm.Format < 6 || gen > 6 || gen < 3; + bool gen34 = gen is 3 or 4; + bool not6 = pkm.Format < 6 || gen is > 6 or < 3; bool noDaily = !gen34 && not6; bool noCosmetic = !gen34 && (not6 || (pkm.XY && pkm.IsUntraded)); @@ -504,7 +504,7 @@ private static bool CanHaveRibbonWinning(PKM pkm, IEncounterable enc, int gen) if (enc.LevelMin <= 50) return true; - return !(enc is EncounterStaticShadow || enc is WC3); + return !(enc is EncounterStaticShadow or WC3); } private static bool CanHaveRibbonVictory(PKM pkm, int gen) diff --git a/PKHeX.Core/MysteryGifts/MysteryUtil.cs b/PKHeX.Core/MysteryGifts/MysteryUtil.cs index e1ab9e894..5c2763488 100644 --- a/PKHeX.Core/MysteryGifts/MysteryUtil.cs +++ b/PKHeX.Core/MysteryGifts/MysteryUtil.cs @@ -135,7 +135,7 @@ public static bool IsCardCompatible(this MysteryGift g, SaveFile sav, out string if (g is WC6 && g.CardID == 2048 && g.ItemID == 726) // Eon Ticket (OR/AS) { - if (!(sav is SAV6AO)) + if (sav is not SAV6AO) { message = MsgMysteryGiftSlotSpecialReject; return false; diff --git a/PKHeX.Core/MysteryGifts/PGT.cs b/PKHeX.Core/MysteryGifts/PGT.cs index 7f42e02fd..5a9c78ff4 100644 --- a/PKHeX.Core/MysteryGifts/PGT.cs +++ b/PKHeX.Core/MysteryGifts/PGT.cs @@ -254,7 +254,7 @@ public static bool IsRangerManaphy(PKM pkm) { var egg = pkm.Egg_Location; if (!pkm.IsEgg) // Link Trade Egg or Ranger - return egg == Locations.LinkTrade4 || egg == Locations.Ranger4; + return egg is Locations.LinkTrade4 or Locations.Ranger4; if (egg != Locations.Ranger4) return false; @@ -262,7 +262,7 @@ public static bool IsRangerManaphy(PKM pkm) return false; var met = pkm.Met_Location; - return met == Locations.LinkTrade4 || met == 0; + return met is Locations.LinkTrade4 or 0; } protected override bool IsMatchExact(PKM pkm, DexLevel evo) => false; diff --git a/PKHeX.Core/MysteryGifts/WB7.cs b/PKHeX.Core/MysteryGifts/WB7.cs index f7cb97296..ad01c621a 100644 --- a/PKHeX.Core/MysteryGifts/WB7.cs +++ b/PKHeX.Core/MysteryGifts/WB7.cs @@ -239,7 +239,7 @@ public override int[] IVs private static int GetLanguageIndex(int language) { var lang = (LanguageID) language; - if (lang < LanguageID.Japanese || lang == LanguageID.UNUSED_6 || lang > LanguageID.ChineseT) + if (lang is < LanguageID.Japanese or LanguageID.UNUSED_6 or > LanguageID.ChineseT) return (int) LanguageID.English; // fallback return lang < LanguageID.UNUSED_6 ? language - 1 : language - 2; } diff --git a/PKHeX.Core/MysteryGifts/WC8.cs b/PKHeX.Core/MysteryGifts/WC8.cs index 782f010a6..c77ccc8cb 100644 --- a/PKHeX.Core/MysteryGifts/WC8.cs +++ b/PKHeX.Core/MysteryGifts/WC8.cs @@ -90,7 +90,7 @@ public override bool IsShiny get { var type = PIDType; - if (type == Shiny.AlwaysStar || type == Shiny.AlwaysSquare) + if (type is Shiny.AlwaysStar or Shiny.AlwaysSquare) return true; if (type != Shiny.FixedValue) return false; @@ -260,7 +260,7 @@ public int[] EVs private static int GetLanguageIndex(int language) { var lang = (LanguageID) language; - if (lang < LanguageID.Japanese || lang == LanguageID.UNUSED_6 || lang > LanguageID.ChineseT) + if (lang is < LanguageID.Japanese or LanguageID.UNUSED_6 or > LanguageID.ChineseT) return (int) LanguageID.English; // fallback return lang < LanguageID.UNUSED_6 ? language - 1 : language - 2; } diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index 6ff9b7fed..62792e1b1 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -170,7 +170,7 @@ public PK7 ConvertToPK7() pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship; // IVs - var special = Species == 151 || Species == 251; + var special = Species is 151 or 251; var new_ivs = new int[6]; int flawless = special ? 5 : 3; var rnd = Util.Rand; diff --git a/PKHeX.Core/PKM/PK7.cs b/PKHeX.Core/PKM/PK7.cs index bdf167845..9feeaa92b 100644 --- a/PKHeX.Core/PKM/PK7.cs +++ b/PKHeX.Core/PKM/PK7.cs @@ -236,7 +236,7 @@ public override string Nickname if (!IsNicknamed) { int lang = SpeciesName.GetSpeciesNameLanguage(Species, Language, value, 7); - if (lang == (int)LanguageID.ChineseS || lang == (int)LanguageID.ChineseT) + if (lang is (int)LanguageID.ChineseS or (int)LanguageID.ChineseT) { StringConverter.SetString7(value, 12, lang, chinese: true).CopyTo(Data, 0x40); return; diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 729e01495..4b8746e86 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using static PKHeX.Core.GameVersion; namespace PKHeX.Core { @@ -282,34 +283,34 @@ private void SetID7(int sid7, int tid7) } public bool E => Version == (int)GameVersion.E; - public bool FRLG => Version == (int)GameVersion.FR || Version == (int)GameVersion.LG; + public bool FRLG => Version is (int)FR or (int)LG; public bool Pt => (int)GameVersion.Pt == Version; - public bool HGSS => Version == (int)GameVersion.HG || Version == (int)GameVersion.SS; - public bool BW => Version == (int)GameVersion.B || Version == (int)GameVersion.W; - public bool B2W2 => Version == (int)GameVersion.B2 || Version == (int)GameVersion.W2; - public bool XY => Version == (int)GameVersion.X || Version == (int)GameVersion.Y; - public bool AO => Version == (int)GameVersion.AS || Version == (int)GameVersion.OR; - public bool SM => Version == (int)GameVersion.SN || Version == (int)GameVersion.MN; - public bool USUM => Version == (int)GameVersion.US || Version == (int)GameVersion.UM; - public bool GO => Version == (int)GameVersion.GO; - public bool VC1 => Version >= (int)GameVersion.RD && Version <= (int)GameVersion.YW; - public bool VC2 => Version >= (int)GameVersion.GD && Version <= (int)GameVersion.C; - public bool LGPE => Version == (int)GameVersion.GP || Version == (int)GameVersion.GE; - public bool SWSH => Version == (int)GameVersion.SW || Version == (int)GameVersion.SH; + public bool HGSS => Version is (int)HG or (int)SS; + public bool BW => Version is (int)B or (int)W; + public bool B2W2 => Version is (int)B2 or (int)W2; + public bool XY => Version is (int)X or (int)Y; + public bool AO => Version is (int)AS or (int)OR; + public bool SM => Version is (int)SN or (int)MN; + public bool USUM => Version is (int)US or (int)UM; + public bool GO => Version is (int)GameVersion.GO; + public bool VC1 => Version is >= (int)RD and <= (int)YW; + public bool VC2 => Version is >= (int)GD and <= (int)C; + public bool LGPE => Version is (int)GP or (int)GE; + public bool SWSH => Version is (int)SW or (int)SH; protected bool PtHGSS => Pt || HGSS; public bool GO_LGPE => GO && Met_Location == Locations.GO7; public bool GO_HOME => GO && Met_Location == Locations.GO8; public bool VC => VC1 || VC2; public bool GG => LGPE || GO_LGPE; - public bool Gen8 => (Version >= 44 && Version <= 45) || GO_HOME; - public bool Gen7 => (Version >= 30 && Version <= 33) || GG; - public bool Gen6 => Version >= 24 && Version <= 29; - public bool Gen5 => Version >= 20 && Version <= 23; - public bool Gen4 => Version >= 7 && Version <= 12 && Version != 9; - public bool Gen3 => (Version >= 1 && Version <= 5) || Version == 15; - public bool Gen2 => Version == (int)GameVersion.GSC; - public bool Gen1 => Version == (int)GameVersion.RBY; + public bool Gen8 => Version is >= 44 and <= 45 || GO_HOME; + public bool Gen7 => Version is >= 30 and <= 33 || GG; + public bool Gen6 => Version is >= 24 and <= 29; + public bool Gen5 => Version is >= 20 and <= 23; + public bool Gen4 => Version is >= 7 and <= 12 and not 9; + public bool Gen3 => Version is >= 1 and <= 5 or 15; + public bool Gen2 => Version == (int)GSC; // Fixed value set by the Gen2 PKM classes + public bool Gen1 => Version == (int)RBY; // Fixed value set by the Gen1 PKM classes public bool GenU => Generation <= 0; public int Generation @@ -454,7 +455,7 @@ public int PIDAbility if (Generation > 5 || Format > 5) return -1; - if (Version == (int) GameVersion.CXD) + if (Version == (int) CXD) return PersonalInfo.GetAbilityIndex(Ability); // Can mismatch; not tied to PID return (int)((Gen5 ? PID >> 16 : PID) & 1); } @@ -614,14 +615,14 @@ public bool InhabitedGeneration(int generation, int species = -1) int gen = Generation; return generation switch { - 1 => (Format == 1 || VC), // species compat checked via sanity above - 2 => (Format == 2 || VC), + 1 => Format == 1 || VC, // species compat checked via sanity above + 2 => Format == 2 || VC, 3 => Gen3, - 4 => (3 <= gen && gen <= 4), - 5 => (3 <= gen && gen <= 5), - 6 => (3 <= gen && gen <= 6), - 7 => ((3 <= gen && gen <= 7) || VC), - 8 => ((3 <= gen && gen <= 8) || VC), + 4 => gen is >= 3 and <= 4, + 5 => gen is >= 3 and <= 5, + 6 => gen is >= 3 and <= 6, + 7 => gen is >= 3 and <= 7 || VC, + 8 => gen is >= 3 and <= 8 || VC, _ => false }; } @@ -648,7 +649,7 @@ public virtual bool IsGenderValid() return gender == 0; int gen = Generation; - if (gen <= 2 || gen >= 6) + if (gen is <= 2 or >= 6) // not 3-5 return gender == (gender & 1); return gender == PKX.GetGenderFromPIDAndRatio(PID, gv); @@ -1030,7 +1031,7 @@ public int GetFlawlessIVCount() return 2; } if (VC) - return Species == (int)Core.Species.Mew || Species == (int)Core.Species.Celebi ? 5 : 3; + return Species is (int)Core.Species.Mew or (int)Core.Species.Celebi ? 5 : 3; return 0; } diff --git a/PKHeX.Core/PKM/Shared/G4PKM.cs b/PKHeX.Core/PKM/Shared/G4PKM.cs index 9d8adb943..32bda3666 100644 --- a/PKHeX.Core/PKM/Shared/G4PKM.cs +++ b/PKHeX.Core/PKM/Shared/G4PKM.cs @@ -49,7 +49,7 @@ public sealed override int Characteristic public sealed override int AbilityNumber { get => 1 << PIDAbility; set { } } // Legality Extensions - public sealed override bool WasEvent => (Met_Location >= 3000 && Met_Location <= 3076) || FatefulEncounter; + public sealed override bool WasEvent => (Met_Location is >= 3000 and <= 3076) || FatefulEncounter; public sealed override bool WasEventEgg => WasEgg && Species == (int)Core.Species.Manaphy; // Manaphy was the only generation 4 released event egg public abstract int ShinyLeaf { get; set; } diff --git a/PKHeX.Core/PKM/Shared/GBPKM.cs b/PKHeX.Core/PKM/Shared/GBPKM.cs index a7bac5b7b..b32806720 100644 --- a/PKHeX.Core/PKM/Shared/GBPKM.cs +++ b/PKHeX.Core/PKM/Shared/GBPKM.cs @@ -178,7 +178,7 @@ public int GuessedLanguage(int fallback = (int)LanguageID.English) int lang = Language; if (lang > 0) return lang; - if (fallback == (int)LanguageID.French || fallback == (int)LanguageID.German) // only other permitted besides English + if (fallback is (int)LanguageID.French or (int)LanguageID.German) // only other permitted besides English return fallback; return (int)LanguageID.English; } diff --git a/PKHeX.Core/PKM/Shared/IGigantamax.cs b/PKHeX.Core/PKM/Shared/IGigantamax.cs index 0b6b180f5..b7b3f9adf 100644 --- a/PKHeX.Core/PKM/Shared/IGigantamax.cs +++ b/PKHeX.Core/PKM/Shared/IGigantamax.cs @@ -26,7 +26,7 @@ public static class GigantamaxExtensions /// True if either species can toggle Gigantamax potential public static bool CanToggleGigantamax(this IGigantamax _, int currentSpecies, int currentForm, int originSpecies, int originForm) { - if (currentSpecies == (int)Species.Meowth || currentSpecies == (int)Species.Pikachu) + if (currentSpecies is (int)Species.Meowth or (int)Species.Pikachu) return currentForm == 0; var soup = CanEatMaxSoup; @@ -42,7 +42,7 @@ public static bool CanToggleGigantamax(this IGigantamax _, int currentSpecies, i /// True if the species can toggle Gigantamax potential public static bool CanToggleGigantamax(this IGigantamax _, int currentSpecies, int currentForm) { - if (currentSpecies == (int)Species.Meowth || currentSpecies == (int)Species.Pikachu) + if (currentSpecies is (int)Species.Meowth or (int)Species.Pikachu) return currentForm == 0; var soup = CanEatMaxSoup; return soup.Contains(currentSpecies); diff --git a/PKHeX.Core/PKM/Shared/PokeListGB.cs b/PKHeX.Core/PKM/Shared/PokeListGB.cs index b1b7b7357..158911341 100644 --- a/PKHeX.Core/PKM/Shared/PokeListGB.cs +++ b/PKHeX.Core/PKM/Shared/PokeListGB.cs @@ -80,7 +80,7 @@ private byte[] GetEmptyList(PokeListType c, bool jp = false) private static int GetStringLength(bool jp) => jp ? GBPKML.STRLEN_J : GBPKML.STRLEN_U; protected bool IsFormatParty => IsCapacityPartyFormat((PokeListType)Capacity); - protected static bool IsCapacityPartyFormat(PokeListType Capacity) => Capacity == PokeListType.Single || Capacity == PokeListType.Party; + protected static bool IsCapacityPartyFormat(PokeListType Capacity) => Capacity is PokeListType.Single or PokeListType.Party; protected static int GetDataSize(PokeListType c, bool jp, int entrySize) { diff --git a/PKHeX.Core/PKM/Util/FormConverter.cs b/PKHeX.Core/PKM/Util/FormConverter.cs index e3ddb86b0..cf14eb432 100644 --- a/PKHeX.Core/PKM/Util/FormConverter.cs +++ b/PKHeX.Core/PKM/Util/FormConverter.cs @@ -45,7 +45,7 @@ public static string[] GetFormList(int species, IReadOnlyList types, IRe } // this is a hack; depends on currently loaded SaveFile's Game ID - private static bool IsGG() => PKMConverter.Game == (int)GameVersion.GP || PKMConverter.Game == (int)GameVersion.GE; + private static bool IsGG() => PKMConverter.Game is (int)GameVersion.GP or (int)GameVersion.GE; private static readonly string[] EMPTY = { string.Empty }; private const string Starter = nameof(Starter); diff --git a/PKHeX.Core/PKM/Util/ItemConverter.cs b/PKHeX.Core/PKM/Util/ItemConverter.cs index 4c4be9476..78d1ebbd4 100644 --- a/PKHeX.Core/PKM/Util/ItemConverter.cs +++ b/PKHeX.Core/PKM/Util/ItemConverter.cs @@ -212,10 +212,10 @@ internal static bool IsItemHM(ushort item, int generation) { return generation switch { - 1 => (196 <= item && item <= 200), // HMs - 2 => (item >= 243), // HMs - 3 => (339 <= item && item <= 346), - _ => ((420 <= item && item <= 427) || item == 737) + 1 => item is >= 196 and <= 200, // HMs + 2 => item is >= 243, // HMs + 3 => item is >= 339 and <= 346, + _ => item is >= 420 and <= 427 or 737, }; } } diff --git a/PKHeX.Core/PKM/Util/Language.cs b/PKHeX.Core/PKM/Util/Language.cs index 97a835dab..c1711377b 100644 --- a/PKHeX.Core/PKM/Util/Language.cs +++ b/PKHeX.Core/PKM/Util/Language.cs @@ -63,7 +63,7 @@ public static string GetLanguage2CharName(this LanguageID lang) /// Main Series language ID. public static byte GetMainLangIDfromGC(byte value) { - if (value <= 2 || value > 7) + if (value is <= 2 or > 7) return value; return (byte) GCtoMainSeries[(LanguageGC)value]; } @@ -75,7 +75,7 @@ public static byte GetMainLangIDfromGC(byte value) /// GameCube (C/XD) language ID. public static byte GetGCLangIDfromMain(byte value) { - if (value <= 2 || value > 7) + if (value is <= 2 or > 7) return value; return (byte) MainSeriesToGC[(LanguageID)value]; } diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index 026141031..a576087e1 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -129,7 +129,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin, uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000; bool g3unown = origin <= 5 && species == (int)Species.Unown; - bool singleGender = gt == 255 || gt == 254 || gt == 0; // skip gender check + bool singleGender = gt is 0 or 254 or 255; // single gender, skip gender check while (true) // Loop until we find a suitable PID { uint pid = Util.Rand32(rnd); @@ -209,7 +209,7 @@ public static int GetGenderFromPIDAndRatio(uint pid, int gr) public static string[] GetPKMExtensions(int maxGeneration = Generation) { var result = new List(); - int min = maxGeneration <= 2 || maxGeneration >= 7 ? 1 : 3; + int min = maxGeneration is <= 2 or >= 7 ? 1 : 3; for (int i = min; i <= maxGeneration; i++) result.Add($"pk{i}"); diff --git a/PKHeX.Core/PKM/Util/PokeCrypto.cs b/PKHeX.Core/PKM/Util/PokeCrypto.cs index 9a7219c6c..70f2e9f4a 100644 --- a/PKHeX.Core/PKM/Util/PokeCrypto.cs +++ b/PKHeX.Core/PKM/Util/PokeCrypto.cs @@ -254,7 +254,7 @@ private static void Crypt(byte[] data, ref uint seed, in int i) /// Decrypted data. public static byte[] DecryptArray3(byte[] ekm) { - Debug.Assert(ekm.Length == SIZE_3PARTY || ekm.Length == SIZE_3STORED); + Debug.Assert(ekm.Length is SIZE_3PARTY or SIZE_3STORED); uint PID = BitConverter.ToUInt32(ekm, 0); uint OID = BitConverter.ToUInt32(ekm, 4); @@ -296,7 +296,7 @@ private static byte[] ShuffleArray3(byte[] data, uint sv) /// Encrypted data. public static byte[] EncryptArray3(byte[] pkm) { - Debug.Assert(pkm.Length == SIZE_3PARTY || pkm.Length == SIZE_3STORED); + Debug.Assert(pkm.Length is SIZE_3PARTY or SIZE_3STORED); uint PID = BitConverter.ToUInt32(pkm, 0); uint OID = BitConverter.ToUInt32(pkm, 4); diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs index 2682b98dc..b16af954a 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs @@ -69,7 +69,7 @@ private void LoadChanged(SCBlockAccessor s1, SCBlockAccessor s2, IEnumerable GameVersion.FRLG, + GameVersion.R or GameVersion.S => GameVersion.RS, + _ => version + }; _personal = SaveUtil.GetG3Personal(Version); Japanese = japanese; diff --git a/PKHeX.Core/Saves/SAV3RSBox.cs b/PKHeX.Core/Saves/SAV3RSBox.cs index 8a097d723..c4df1d478 100644 --- a/PKHeX.Core/Saves/SAV3RSBox.cs +++ b/PKHeX.Core/Saves/SAV3RSBox.cs @@ -159,7 +159,7 @@ public override string GetBoxName(int box) box /= 2; int offset = Box + 0x1EC38 + (9 * box); - if (Data[offset] == 0 || Data[offset] == 0xFF) + if (Data[offset] is 0 or 0xFF) boxName += $"BOX {box + 1}"; boxName += GetString(offset, 9); diff --git a/PKHeX.Core/Saves/SAV8.cs b/PKHeX.Core/Saves/SAV8.cs index a5f6bb2ce..e41a97616 100644 --- a/PKHeX.Core/Saves/SAV8.cs +++ b/PKHeX.Core/Saves/SAV8.cs @@ -65,9 +65,11 @@ public override GameVersion Version get { var game = (GameVersion)Game; - if (game == GameVersion.SW || game == GameVersion.SH) - return game; - return GameVersion.Invalid; + return game switch + { + GameVersion.SW or GameVersion.SH => game, + _ => GameVersion.Invalid + }; } } diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 61185b09b..7d691f14e 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -293,7 +293,7 @@ public IList PartyData } set { - if (value.Count == 0 || value.Count > 6) + if (value.Count is 0 or > 6) throw new ArgumentException($"Expected 1-6, got {value.Count}"); if (value.Any(pk => PKMType != pk.GetType())) throw new ArgumentException($"Not {PKMType} array."); diff --git a/PKHeX.Core/Saves/SaveFileMetadata.cs b/PKHeX.Core/Saves/SaveFileMetadata.cs index d3086346d..f2d8f8307 100644 --- a/PKHeX.Core/Saves/SaveFileMetadata.cs +++ b/PKHeX.Core/Saves/SaveFileMetadata.cs @@ -117,7 +117,7 @@ public string GetSuggestedExtension() if (fn != null) return Path.GetExtension(fn); - if ((sav.Generation == 4 || sav.Generation == 5) && sav.Metadata.HasFooter) + if ((sav.Generation is 4 or 5) && sav.Metadata.HasFooter) return ".dsv"; return sav.Extension; } diff --git a/PKHeX.Core/Saves/Storage/BulkStorage.cs b/PKHeX.Core/Saves/Storage/BulkStorage.cs index 780fa64b3..099f01436 100644 --- a/PKHeX.Core/Saves/Storage/BulkStorage.cs +++ b/PKHeX.Core/Saves/Storage/BulkStorage.cs @@ -45,7 +45,7 @@ protected BulkStorage(byte[] data, Type t, int start, int slotsPerBox = 30) : ba public sealed override int MaxGameID => blank.MaxGameID; public sealed override int OTLength => blank.OTLength; public sealed override int NickLength => blank.NickLength; - public bool IsBigEndian => blank is BK4 || blank is XK3 || blank is CK3; + public bool IsBigEndian => blank is BK4 or XK3 or CK3; private readonly Func GetIsPKMPresent; public sealed override bool IsPKMPresent(byte[] data, int offset) => GetIsPKMPresent(data, offset); diff --git a/PKHeX.Core/Saves/Substructures/Gen5/CGearBackground.cs b/PKHeX.Core/Saves/Substructures/Gen5/CGearBackground.cs index 37be0fa0a..b96ba56e0 100644 --- a/PKHeX.Core/Saves/Substructures/Gen5/CGearBackground.cs +++ b/PKHeX.Core/Saves/Substructures/Gen5/CGearBackground.cs @@ -169,9 +169,10 @@ private static byte[] PSKtoCGB(byte[] psk) private static int ValToIndex(int val) { - if ((val & 0x3FF) < 0xA0 || (val & 0x3FF) > 0x280) + var trunc = (val & 0x3FF); + if (trunc is < 0xA0 or > 0x280) return (val & 0x5C00) | 0xFF; - return ((val % 0x20) + (17 * (((val & 0x3FF) - 0xA0) / 0x20))) | (val & 0x5C00); + return ((val % 0x20) + (17 * ((trunc - 0xA0) / 0x20))) | (val & 0x5C00); } private static byte Convert8to5(int colorval) diff --git a/PKHeX.Core/Saves/Substructures/Gen5/Daycare5.cs b/PKHeX.Core/Saves/Substructures/Gen5/Daycare5.cs index f310f6985..a5a36252d 100644 --- a/PKHeX.Core/Saves/Substructures/Gen5/Daycare5.cs +++ b/PKHeX.Core/Saves/Substructures/Gen5/Daycare5.cs @@ -20,14 +20,14 @@ public sealed class Daycare5 : SaveBlock public ulong? GetSeed() { - if (!(SAV is SAV5B2W2)) + if (SAV is not SAV5B2W2) return null; return BitConverter.ToUInt64(Data, Offset + 0x1CC); } public void SetSeed(string value) { - if (!(SAV is SAV5B2W2)) + if (SAV is not SAV5B2W2) return; var data = Util.GetBytesFromHexString(value); SAV.SetData(data, Offset + 0x1CC); diff --git a/PKHeX.Core/Saves/Substructures/Gen5/PWTBlock5.cs b/PKHeX.Core/Saves/Substructures/Gen5/PWTBlock5.cs index 922caeb61..8197f869d 100644 --- a/PKHeX.Core/Saves/Substructures/Gen5/PWTBlock5.cs +++ b/PKHeX.Core/Saves/Substructures/Gen5/PWTBlock5.cs @@ -10,7 +10,7 @@ public sealed class PWTBlock5 : SaveBlock public ushort GetPWTRecord(PWTRecordID id) { - if (id < PWTRecordID.Normal || id > PWTRecordID.MixMaster) + if (id is < PWTRecordID.Normal or > PWTRecordID.MixMaster) throw new ArgumentException(nameof(id)); int ofs = Offset + 0x5C + ((int)id * 2); return BitConverter.ToUInt16(Data, ofs); @@ -20,7 +20,7 @@ public ushort GetPWTRecord(PWTRecordID id) public void SetPWTRecord(PWTRecordID id, ushort value) { - if (id < PWTRecordID.Normal || id > PWTRecordID.MixMaster) + if (id is < PWTRecordID.Normal or > PWTRecordID.MixMaster) throw new ArgumentException(nameof(id)); int ofs = Offset + 0x5C + ((int)id * 2); SAV.SetData(BitConverter.GetBytes(value), ofs); diff --git a/PKHeX.Core/Saves/Substructures/Gen7/CaptureRecords.cs b/PKHeX.Core/Saves/Substructures/Gen7/CaptureRecords.cs index f4b05d8cd..e213b6d6a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/CaptureRecords.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/CaptureRecords.cs @@ -37,7 +37,7 @@ public static int GetSpeciesIndex(int species) { if (species <= (int)Species.Mew) return species - 1; - if (species == (int)Species.Meltan || species == (int)Species.Melmetal) + if (species is (int)Species.Meltan or (int)Species.Melmetal) return species - 657; // 151, 152 return -1; } diff --git a/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs b/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs index 447ce65b4..167ae9587 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs @@ -30,7 +30,7 @@ public int WormholeSlot } set { - if (value < 1 || value > WormholeSlotMax) + if (value is < 1 or > WormholeSlotMax) return; for (int i = 1; i <= WormholeSlotMax; i++) { @@ -129,7 +129,7 @@ public int WormholeSlot public static int WormholeSlotToPokemon(int mapid, int slot) { - if (slot < 1 || slot > WormholeSlotMax) + if (slot is < 1 or > WormholeSlotMax) return -1; return mapid switch diff --git a/PKHeX.Core/Saves/Substructures/Gen8/RaidSpawnList8.cs b/PKHeX.Core/Saves/Substructures/Gen8/RaidSpawnList8.cs index 2af50406a..861260154 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/RaidSpawnList8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/RaidSpawnList8.cs @@ -126,7 +126,7 @@ public byte Flags [Category(Derived), Description("Rare encounter details used instead of Common details.")] public bool IsRare { - get => DenType == RaidType.Rare || DenType == RaidType.RareWish; + get => DenType is RaidType.Rare or RaidType.RareWish; set { if (value) @@ -143,7 +143,7 @@ public bool IsRare [Category(Derived), Description("Wishing Piece was used for Raid encounter.")] public bool IsWishingPiece { - get => DenType == RaidType.CommonWish || DenType == RaidType.RareWish; + get => DenType is RaidType.CommonWish or RaidType.RareWish; set { if (value) diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs index 9a37e5584..038d5908d 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs @@ -54,15 +54,13 @@ public override ushort AuthorTID public override int AppearPKM { get => Data[0x2D]; set => Data[0x2D] = (byte)value; } public override int MailType { get => Data[0x2E]; set => Data[0x2E] = (byte)value; } - public override bool? IsEmpty + public override bool? IsEmpty => MailType switch { - get - { - if (MailType == 0) return true; - else if (MailType == 0x9E || (MailType >= 0xB5 && MailType <= 0xBD)) return false; - else return null; - } - } + 0 => true, + 0x9E => false, + >= 0xB5 and <= 0xBD => false, + _ => null + }; public override void SetBlank() => (new byte[0x2F]).CopyTo(Data, 0); } diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan.cs index 8915ff63f..78b981fd1 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan.cs @@ -116,7 +116,7 @@ public override void SetDex(PKM pkm) { if (SAV.Version == GameVersion.Invalid) // sanity return; - if (pkm.Species == 0 || pkm.Species > SAV.MaxSpeciesID) // out of range + if ((uint)(pkm.Species - 1) >= (uint)SAV.MaxSpeciesID) // out of range return; if (pkm.IsEgg) // do not add return; diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan7.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan7.cs index f57cffb0f..a3f5aa530 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan7.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan7.cs @@ -126,16 +126,14 @@ public static bool SanitizeFormsToIterate(int species, out int formStart, out in return true; } - protected sealed override int GetDexLangFlag(int lang) + protected sealed override int GetDexLangFlag(int lang) => lang switch { - if (lang > 10 || lang == 6 || lang <= 0) - return -1; // invalid language - - if (lang >= 7) // skip over langID 6 (unused) - lang--; - lang--; // skip over langID 0 (unused) => [0-8] - return lang; - } + > 10 or 6 or <= 0 => -1, // invalid language + // skip over langID 0 (unused) => [0-8] + // skip over langID 6 (unused) + >= 7 => lang - 2, + _ => lang - 1, + }; protected sealed override void SetSpindaDexData(PKM pkm, bool alreadySeen) { diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs index 6d7aca971..83b5324af 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs @@ -112,16 +112,14 @@ public static List GetRawIndexes(PersonalTable pt, int dexRevis return result; } - private static int GetDexLangFlag(int lang) + private static int GetDexLangFlag(int lang) => lang switch { - if (lang > 10 || lang == 6 || lang <= 0) - return -1; // invalid language - - if (lang >= 7) // skip over langID 6 (unused) - lang--; - lang--; // skip over langID 0 (unused) => [0-8] - return lang; - } + > 10 or 6 or <= 0 => -1, // invalid language + // skip over langID 0 (unused) => [0-8] + // skip over langID 6 (unused) + >= 7 => lang - 2, + _ => lang - 1, + }; public IList GetEntryNames(IReadOnlyList speciesNames) { diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index fe6b355bf..3f5028c75 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -364,7 +364,7 @@ bool validSequence(int offset) const int DATE_INT = 0x20060623; const int DATE_KO = 0x20070903; - return sdk == DATE_INT || sdk == DATE_KO; + return sdk is DATE_INT or DATE_KO; } // Check the other save -- first save is done to the latter half of the binary. diff --git a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs index 0d22df02d..0ba34daf9 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs @@ -350,7 +350,7 @@ private void SaveHandlingTrainer(PKM pk) private static void CheckTransferPIDValid(PKM pk) { var ver = pk.Version; - if (ver >= (int)GameVersion.X || ver == 0) + if (ver is 0 or >= (int)GameVersion.X) // Gen6+ ignored return; uint EC = pk.EncryptionConstant; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index e58840a5e..4524a81c5 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -1075,15 +1075,15 @@ private void ToggleViewSubEditors(SaveFile sav) B_CGearSkin.Enabled = sav.Generation == 5; B_OpenPokeBeans.Enabled = B_CellsStickers.Enabled = B_FestivalPlaza.Enabled = sav is SAV7; - B_OtherSlots.Enabled = sav is SAV1StadiumJ || sav is SAV1Stadium || sav is SAV2Stadium; - B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && !(SAV is SAV4BR)) || SAV is SAV7b; // Box RS & Battle Revolution - B_OpenMiscEditor.Enabled = sav is SAV3 || sav is SAV4 || sav is SAV5; + B_OtherSlots.Enabled = sav is SAV1StadiumJ or SAV1Stadium or SAV2Stadium; + B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = (sav.HasParty && SAV is not SAV4BR) || SAV is SAV7b; // Box RS & Battle Revolution + B_OpenMiscEditor.Enabled = sav is SAV3 or SAV4 or SAV5; B_Roamer.Enabled = sav is SAV3; B_OpenHoneyTreeEditor.Enabled = B_OpenUGSEditor.Enabled = sav is SAV4Sinnoh; 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_MailBox.Enabled = sav is SAV2 or SAV3 or SAV4 or SAV5; B_Raids.Enabled = sav is SAV8SWSH; B_RaidArmor.Enabled = sav is SAV8SWSH {SaveRevision: >= 1}; diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index a50e396b9..4363dc199 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -1108,7 +1108,7 @@ private void Main_DragDrop(object sender, DragEventArgs e) private void Dragout_MouseDown(object sender, MouseEventArgs e) { - if (e.Button == MouseButtons.Left && (ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift)) + if (e.Button == MouseButtons.Left && (ModifierKeys is Keys.Alt or Keys.Shift)) ClickQR(sender, e); if (e.Button == MouseButtons.Right) return; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs index 1814100da..4adc12236 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs @@ -298,7 +298,7 @@ private void SetFlagsFromFileName(string inpFileName) } int ColorCount = BrightCount.Count(v => v > 0); - if (ColorCount > 4 || ColorCount == 0) + if (ColorCount is 0 or > 4) return; int errmin = int.MaxValue; byte[] LCT = new byte[4]; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs index 626e82fa9..858d48e8a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs @@ -298,7 +298,7 @@ private void SeenAll() private void ModifyAll(object sender, EventArgs e) { int lang = SAV.Language - 1; - if (lang > 5 || lang < 0) // KOR or Invalid + if (lang is < 0 or > 5) // KOR or Invalid lang = 0; bool seenA = sender == mnuSeenAll || sender == mnuCaughtAll || sender == mnuComplete; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs index 3a54e8130..c574b3710 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs @@ -735,18 +735,9 @@ private void ReadSubway() } else { - if (swSuperCheck == 0x10 || swSuperCheck == 0x30 || swSuperCheck == 0x50) - { - CHK_SuperSingle.Checked = true; - } - if (swSuperCheck == 0x20 || swSuperCheck == 0x30 || swSuperCheck == 0x60) - { - CHK_SuperDouble.Checked = true; - } - if (swSuperCheck == 0x40 || swSuperCheck == 0x50 || swSuperCheck == 0x60) - { - CHK_SuperMulti.Checked = true; - } + if (swSuperCheck is 0x10 or 0x30 or 0x50) CHK_SuperSingle.Checked = true; + if (swSuperCheck is 0x20 or 0x30 or 0x60) CHK_SuperDouble.Checked = true; + if (swSuperCheck is 0x40 or 0x50 or 0x60) CHK_SuperMulti.Checked = true; } // Normal diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs index 9ce838e6c..734dd7314 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs @@ -325,7 +325,8 @@ private void UpdateNickname(object sender, EventArgs e) private void SetForms() { int species = WinFormsUtil.GetIndex(CB_Species); - bool hasForms = PersonalTable.AO[species].HasForms || new[] { 664, 665, 414 }.Contains(species); + var pi = PersonalTable.AO[species]; + bool hasForms = FormInfo.HasFormSelection(pi, species, 6); CB_Form.Enabled = CB_Form.Visible = hasForms; CB_Form.InitializeBinding(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs index e5097387f..f803ad7f0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs @@ -46,7 +46,7 @@ public SAV_Trainer(SaveFile sav) PB_Sprite.Visible = CHK_MegaRayquazaUnlocked.Visible = SAV is SAV6AO; L_Style.Visible = TB_Style.Visible = SAV is SAV6XY; - if (!(SAV is SAV6XY)) + if (SAV is not SAV6XY) TC_Editor.TabPages.Remove(Tab_Appearance); if (SAV is SAV6AODemo) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs index a16fa3226..948e5d32e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs @@ -412,7 +412,7 @@ private void SetAll(object sender, int lang) if (sender != mnuSeenAll) SetRecords(); - if (spec == 25 || spec == 133) + if (spec is (int)Species.Pikachu or (int)Species.Eevee) continue; // ignore starter (setdex doesn't set buddy bit; totem raticate is not emitted below). // Set forme flags diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index ae6ac12b2..17e798f9c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -71,7 +71,7 @@ private void GetComboBoxes() CB_Vivillon.InitializeBinding(); CB_Vivillon.DataSource = FormConverter.GetFormList((int)Species.Vivillon, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, SAV.Generation); - if (!(SAV is SAV7USUM)) + if (SAV is not SAV7USUM) BattleStyles.RemoveAt(BattleStyles.Count - 1); // remove Nihilist foreach (string t in BattleStyles) { @@ -241,7 +241,7 @@ private void LoadMapFlyToData() 188,-1,-1, 198,202,110,204,//Beach }; - if (SAV.Version == GameVersion.UM || SAV.Version == GameVersion.MN) + if (SAV.Version is GameVersion.UM or GameVersion.MN) { FlyDestNameIndex[28] = 142; FlyDestNameIndex[36] = 178; @@ -409,7 +409,7 @@ private void SaveThrowType() if (CB_BallThrowType.SelectedIndex >= 0) SAV.MyStatus.BallThrowType = CB_BallThrowType.SelectedIndex; - if (!(SAV is SAV7SM)) // unlock flags are in flag editor instead + if (SAV is not SAV7SM) // unlock flags are in flag editor instead return; const int unlockStart = 292; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs index bb013d56b..db57263b1 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs @@ -93,7 +93,7 @@ private void B_GiveAll_Click(object sender, EventArgs e) } NUD_Collected.Value += added; - if (!(SAV is SAV7USUM)) + if (SAV is not SAV7USUM) NUD_Cells.Value += added; System.Media.SystemSounds.Asterisk.Play(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs index bf2b3cf79..06bda0439 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs @@ -26,7 +26,7 @@ public SAV_Inventory(SaveFile sav) itemlist[i] = $"(Item #{i:000})"; } - HasFreeSpace = SAV.Generation >= 7 && !(SAV is SAV7b); + HasFreeSpace = SAV.Generation >= 7 && SAV is not SAV7b; HasNew = CHK_NEW.Visible = SAV.Generation >= 7; Pouches = SAV.Inventory; CreateBagViews(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs index ec910775a..ebde77cb4 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs @@ -35,9 +35,9 @@ public SAV_MailBox(SaveFile sav) NUD_BoxSize.Visible = L_BoxSize.Visible = Gen == 2; GB_MessageTB.Visible = Gen == 2; GB_MessageNUD.Visible = Gen != 2; - Messages[0][3].Visible = Messages[1][3].Visible = Messages[2][3].Visible = Gen == 4 || Gen == 5; + Messages[0][3].Visible = Messages[1][3].Visible = Messages[2][3].Visible = Gen is 4 or 5; NUD_AuthorSID.Visible = Gen != 2; - Label_OTGender.Visible = CB_AuthorLang.Visible = CB_AuthorVersion.Visible = Gen == 4 || Gen == 5; + Label_OTGender.Visible = CB_AuthorLang.Visible = CB_AuthorVersion.Visible = Gen is 4 or 5; L_AppearPKM.Visible = AppearPKMs[0].Visible = Gen != 5; AppearPKMs[1].Visible = AppearPKMs[2].Visible = Gen == 4; NUD_MessageEnding.Visible = Gen == 5; @@ -112,13 +112,13 @@ public SAV_MailBox(SaveFile sav) MakePartyList(); MakePCList(); - if (Gen == 2 || Gen == 3) + if (Gen is 2 or 3) { CB_AppearPKM1.Items.Clear(); CB_AppearPKM1.InitializeBinding(); CB_AppearPKM1.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), null); } - else if (Gen == 4 || Gen == 5) + else if (Gen is 4 or 5) { var species = GameInfo.FilteredSources.Species.ToList(); foreach (ComboBox a in AppearPKMs) @@ -351,7 +351,7 @@ private List CheckValid() heldMailIDs[i] = h; if (ItemIsMail(p[i].HeldItem)) { - if (h < 0 || h > 5) //A + if (h is < 0 or > 5) //A ret.Add($"Party#{i + 1} MailID mismatch"); else if (m[h].IsEmpty == true) //B ret.Add($"Party#{i + 1} MailID mismatch"); @@ -373,7 +373,7 @@ private List CheckValid() // Gen2, Gen4 // P: held item is mail, but mail is empty(invalid mail type. g2:not 181 to 189, g4:12 to 255). it should be not empty or held not mail. // Q: held item is not mail, but mail is not empty. it should be empty or held mail. - else if (Gen == 2 || Gen == 4) + else if (Gen is 2 or 4) { for (int i = 0; i < p.Count; i++) { diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_SimpleTrainer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_SimpleTrainer.cs index 82551df9e..b6db4cad7 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_SimpleTrainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_SimpleTrainer.cs @@ -102,7 +102,7 @@ public SAV_SimpleTrainer(SaveFile sav) CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false; CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false; } - if (SAV is SAV3Colosseum || SAV is SAV3XD) + if (SAV is SAV3Colosseum or SAV3XD) { GB_Map.Visible = false; GB_Badges.Visible = false; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index d8e53d165..87258b20c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -109,7 +109,8 @@ private void GetReceivedFlags() private void SetCardID(int cardID) { - if (cardID <= 0 || cardID >= 0x100 * 8) return; + if (cardID is <= 0 or >= 0x100 * 8) + return; string card = cardID.ToString("0000"); if (!LB_Received.Items.Contains(card))