From 444c3d22094215269210b4cf7f66087aa29e06b3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 26 Aug 2022 10:07:24 -0700 Subject: [PATCH] Narrow more types --- .../Encounters/Generator/EncounterFinder.cs | 6 +++--- .../Legality/Restrictions/GBRestrictions.cs | 10 +++++----- .../Memories/MemoryPermissions.cs | 20 +++++++++---------- PKHeX.Core/Legality/Tables/FormChangeUtil.cs | 6 +++--- .../Verifiers/Ability/AbilityBreedLegality.cs | 2 +- .../Legality/Verifiers/LevelVerifier.cs | 2 +- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs index 16e12fbe7..61db164a6 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs @@ -161,7 +161,7 @@ public static class EncounterFinder private static string GetHintWhyNotFound(PKM pk, int gen) { - if (WasGiftEgg(pk, gen, pk.Egg_Location)) + if (WasGiftEgg(pk, gen, (ushort)pk.Egg_Location)) return LEncGift; if (WasEventEgg(pk, gen)) return LEncGiftEggEvent; @@ -170,9 +170,9 @@ public static class EncounterFinder return LEncInvalid; } - private static bool WasGiftEgg(PKM pk, int gen, int loc) => !pk.FatefulEncounter && gen switch + private static bool WasGiftEgg(PKM pk, int gen, ushort loc) => !pk.FatefulEncounter && gen switch { - 3 => pk.IsEgg && pk.Met_Location == 253, // Gift Egg, indistinguishable from normal eggs after hatch + 3 => pk.IsEgg && (byte)pk.Met_Location == 253, // Gift Egg, indistinguishable from normal eggs after hatch 4 => Legal.GiftEggLocation4.Contains(loc) || (pk.Format != 4 && (loc == Locations.Faraway4 && pk.HGSS)), 5 => loc is Locations.Breeder5, _ => loc is Locations.Breeder6, diff --git a/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs b/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs index c341feac1..65c6fbb6f 100644 --- a/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs +++ b/PKHeX.Core/Legality/Restrictions/GBRestrictions.cs @@ -12,7 +12,7 @@ namespace PKHeX.Core; /// internal static class GBRestrictions { - private static readonly HashSet Stadium_GiftSpecies = new() + private static readonly HashSet Stadium_GiftSpecies = new() { (int)Bulbasaur, (int)Charmander, @@ -34,7 +34,7 @@ internal static class GBRestrictions /// /// Species that have a catch rate value that is different from their pre-evolutions, and cannot be obtained directly. /// - internal static readonly HashSet Species_NotAvailable_CatchRate = new() + internal static readonly HashSet Species_NotAvailable_CatchRate = new() { (int)Butterfree, (int)Pidgeot, @@ -55,7 +55,7 @@ internal static class GBRestrictions (int)Dragonite, }; - internal static readonly HashSet Trade_Evolution1 = new() + internal static readonly HashSet Trade_Evolution1 = new() { (int)Kadabra, (int)Machoke, @@ -83,7 +83,7 @@ internal static class GBRestrictions foreach (var entry in chain) { var s = entry.Species; - if (Species_NotAvailable_CatchRate.Contains(s)) + if (Species_NotAvailable_CatchRate.Contains((byte)s)) continue; if (catch_rate == PersonalTable.RB[s].CatchRate || catch_rate == PersonalTable.Y[s].CatchRate) return true; @@ -94,7 +94,7 @@ internal static class GBRestrictions if (catch_rate == 204 && (species is (int)Krabby or (int)Kingler)) return true; - if (catch_rate is (167 or 168) && Stadium_GiftSpecies.Contains(species)) + if (catch_rate is (167 or 168) && Stadium_GiftSpecies.Contains((byte)species)) return true; return false; diff --git a/PKHeX.Core/Legality/Restrictions/Memories/MemoryPermissions.cs b/PKHeX.Core/Legality/Restrictions/Memories/MemoryPermissions.cs index 89d52d8b2..7d1da0e6b 100644 --- a/PKHeX.Core/Legality/Restrictions/Memories/MemoryPermissions.cs +++ b/PKHeX.Core/Legality/Restrictions/Memories/MemoryPermissions.cs @@ -200,7 +200,7 @@ public static class MemoryPermissions return false; } - public static bool GetCanDynamaxTrainer(int species, int gen, GameVersion version) + public static bool GetCanDynamaxTrainer(ushort species, int gen, GameVersion version) { if (gen != 8) return false; @@ -214,11 +214,11 @@ public static class MemoryPermissions } // exclusive to version - private static bool IsDynamaxSW(int species) => species is (int)Machamp or (int)Gigalith or (int)Conkeldurr or (int)Coalossal or (int)Flapple; - private static bool IsDynamaxSH(int species) => species is (int)Gengar or (int)Lapras or (int)Dusknoir or (int)Froslass or (int)Appletun; + private static bool IsDynamaxSW(ushort species) => species is (int)Machamp or (int)Gigalith or (int)Conkeldurr or (int)Coalossal or (int)Flapple; + private static bool IsDynamaxSH(ushort species) => species is (int)Gengar or (int)Lapras or (int)Dusknoir or (int)Froslass or (int)Appletun; // common to SW & SH - private static readonly HashSet DynamaxTrainer_SWSH = new() + private static readonly HashSet DynamaxTrainer_SWSH = new() { (int)Venusaur, (int)Blastoise, @@ -249,7 +249,7 @@ public static class MemoryPermissions (int)Urshifu, }; - public static bool GetCanFishSpecies(int species, EntityContext context, GameVersion version) => context switch + public static bool GetCanFishSpecies(ushort species, EntityContext context, GameVersion version) => context switch { EntityContext.Gen6 => version switch { @@ -270,7 +270,7 @@ public static class MemoryPermissions _ => false, }; - private static readonly HashSet FishingSpecies_SWSH = new() + private static readonly HashSet FishingSpecies_SWSH = new() { (int)Shellder, (int)Cloyster, (int)Krabby, @@ -297,7 +297,7 @@ public static class MemoryPermissions (int)Arrokuda, (int)Barraskewda, }; - private static readonly HashSet FishingSpecies_AO = new() + private static readonly HashSet FishingSpecies_AO = new() { (int)Tentacool, (int)Horsea, (int)Seadra, @@ -315,11 +315,11 @@ public static class MemoryPermissions }; // exclusive to version - private static bool IsFishingSpeciesX(int species) => species is (int)Staryu or (int)Starmie or (int)Huntail or (int)Clauncher or (int)Clawitzer; - private static bool IsFishingSpeciesY(int species) => species is (int)Shellder or (int)Cloyster or (int)Gorebyss or (int)Skrelp or (int)Dragalge; + private static bool IsFishingSpeciesX(ushort species) => species is (int)Staryu or (int)Starmie or (int)Huntail or (int)Clauncher or (int)Clawitzer; + private static bool IsFishingSpeciesY(ushort species) => species is (int)Shellder or (int)Cloyster or (int)Gorebyss or (int)Skrelp or (int)Dragalge; // common to X & Y - private static readonly HashSet FishingSpecies_XY = new() + private static readonly HashSet FishingSpecies_XY = new() { (int)Poliwag, (int)Poliwhirl, (int)Poliwrath, (int)Politoed, (int)Horsea, (int)Seadra, diff --git a/PKHeX.Core/Legality/Tables/FormChangeUtil.cs b/PKHeX.Core/Legality/Tables/FormChangeUtil.cs index 82584a245..95bac7f6a 100644 --- a/PKHeX.Core/Legality/Tables/FormChangeUtil.cs +++ b/PKHeX.Core/Legality/Tables/FormChangeUtil.cs @@ -22,12 +22,12 @@ public static class FormChangeUtil return IterateAllForms(species); } - private static bool IterateAllForms(int species) => FormChangeMovesRetain.Contains(species); + private static bool IterateAllForms(ushort species) => FormChangeMovesRetain.Contains(species); /// /// Species that can change between their forms and get access to form-specific moves. /// - private static readonly HashSet FormChangeMovesRetain = new() + private static readonly HashSet FormChangeMovesRetain = new() { (int)Species.Deoxys, (int)Species.Giratina, @@ -38,7 +38,7 @@ public static class FormChangeUtil /// /// Species that can change between their forms and get access to form-specific moves. /// - private static readonly Dictionary> FormChangeMoves = new() + private static readonly Dictionary> FormChangeMoves = new() { {(int)Species.Deoxys, g => g.Generation >= 6}, {(int)Species.Giratina, g => g.Generation >= 6}, diff --git a/PKHeX.Core/Legality/Verifiers/Ability/AbilityBreedLegality.cs b/PKHeX.Core/Legality/Verifiers/Ability/AbilityBreedLegality.cs index f6b159b6f..a4c13cde7 100644 --- a/PKHeX.Core/Legality/Verifiers/Ability/AbilityBreedLegality.cs +++ b/PKHeX.Core/Legality/Verifiers/Ability/AbilityBreedLegality.cs @@ -150,7 +150,7 @@ internal static class AbilityBreedLegality // internal static readonly HashSet BanHidden8 = new(); // none as of DLC 1! /// - /// Species that cannot be bred with a Hidden Ability originating in + /// Species that cannot be bred with a Hidden Ability originating in /// internal static readonly HashSet BanHidden8b = new() { diff --git a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs index 069c837cf..1aa500978 100644 --- a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs @@ -111,7 +111,7 @@ public sealed class LevelVerifier : Verifier var species = pk.Species; // This check is only applicable if it's a trade evolution that has not been evolved. - if (!GBRestrictions.Trade_Evolution1.Contains(enc.Species) || enc.Species != species) + if (!GBRestrictions.Trade_Evolution1.Contains((byte)enc.Species) || enc.Species != species) return false; // Context check is only applicable to gen1/2; transferring to Gen2 is a trade. diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index 78f29bff1..b52bd35c1 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -226,7 +226,7 @@ public sealed class MiscVerifier : Verifier return GetValid(LG1CatchRateMatchPrevious); // Encounters detected by the catch rate, cant be invalid if match this encounters int species = pk1.Species; - if (GBRestrictions.Species_NotAvailable_CatchRate.Contains(species) && catch_rate == PersonalTable.RB[species].CatchRate) + if (GBRestrictions.Species_NotAvailable_CatchRate.Contains((byte)species) && catch_rate == PersonalTable.RB[species].CatchRate) { if (species != (int) Species.Dragonite || catch_rate != 45 || !e.Version.Contains(GameVersion.YW)) return GetInvalid(LG1CatchRateEvo);