Narrow more types

This commit is contained in:
Kurt 2022-08-26 10:07:24 -07:00
parent 6e4613a3a7
commit 444c3d2209
7 changed files with 24 additions and 24 deletions

View file

@ -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,

View file

@ -12,7 +12,7 @@ namespace PKHeX.Core;
/// </summary>
internal static class GBRestrictions
{
private static readonly HashSet<int> Stadium_GiftSpecies = new()
private static readonly HashSet<byte> Stadium_GiftSpecies = new()
{
(int)Bulbasaur,
(int)Charmander,
@ -34,7 +34,7 @@ internal static class GBRestrictions
/// <summary>
/// Species that have a catch rate value that is different from their pre-evolutions, and cannot be obtained directly.
/// </summary>
internal static readonly HashSet<int> Species_NotAvailable_CatchRate = new()
internal static readonly HashSet<byte> Species_NotAvailable_CatchRate = new()
{
(int)Butterfree,
(int)Pidgeot,
@ -55,7 +55,7 @@ internal static class GBRestrictions
(int)Dragonite,
};
internal static readonly HashSet<int> Trade_Evolution1 = new()
internal static readonly HashSet<byte> 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;

View file

@ -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<int> DynamaxTrainer_SWSH = new()
private static readonly HashSet<ushort> 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<int> FishingSpecies_SWSH = new()
private static readonly HashSet<ushort> 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<int> FishingSpecies_AO = new()
private static readonly HashSet<ushort> 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<int> FishingSpecies_XY = new()
private static readonly HashSet<ushort> FishingSpecies_XY = new()
{
(int)Poliwag, (int)Poliwhirl, (int)Poliwrath, (int)Politoed,
(int)Horsea, (int)Seadra,

View file

@ -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);
/// <summary>
/// Species that can change between their forms and get access to form-specific moves.
/// </summary>
private static readonly HashSet<int> FormChangeMovesRetain = new()
private static readonly HashSet<ushort> FormChangeMovesRetain = new()
{
(int)Species.Deoxys,
(int)Species.Giratina,
@ -38,7 +38,7 @@ public static class FormChangeUtil
/// <summary>
/// Species that can change between their forms and get access to form-specific moves.
/// </summary>
private static readonly Dictionary<int, Func<(int Generation, int Form), bool>> FormChangeMoves = new()
private static readonly Dictionary<ushort, Func<(int Generation, int Form), bool>> FormChangeMoves = new()
{
{(int)Species.Deoxys, g => g.Generation >= 6},
{(int)Species.Giratina, g => g.Generation >= 6},

View file

@ -150,7 +150,7 @@ internal static class AbilityBreedLegality
// internal static readonly HashSet<int> BanHidden8 = new(); // none as of DLC 1!
/// <summary>
/// Species that cannot be bred with a Hidden Ability originating in <see cref="GameVersion.Gen7"/>
/// Species that cannot be bred with a Hidden Ability originating in <see cref="GameVersion.BDSP"/>
/// </summary>
internal static readonly HashSet<int> BanHidden8b = new()
{

View file

@ -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.

View file

@ -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);