mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-26 05:50:22 +00:00
Simplify some repeated comparisons with expressions
Less prone for bugs since it uses the same value for all comparisons without re-specifying
This commit is contained in:
parent
c119f18af3
commit
e8c23f6644
41 changed files with 103 additions and 106 deletions
|
@ -14,13 +14,13 @@ namespace PKHeX.Core
|
|||
/// List of possible <see cref="GameVersion"/> values a <see cref="PKM.Version"/> can have.
|
||||
/// </summary>
|
||||
/// <remarks>Ordered roughly by most recent games first.</remarks>
|
||||
public static readonly IReadOnlyList<GameVersion> GameVersions = ((GameVersion[])Enum.GetValues(typeof(GameVersion))).Where(z => z < RB && z > 0).Reverse().ToArray();
|
||||
public static readonly IReadOnlyList<GameVersion> GameVersions = ((GameVersion[])Enum.GetValues(typeof(GameVersion))).Where(IsValidSavedVersion).Reverse().ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the <see cref="GameVersion"/> value is a value used by the games or is an aggregate indicator.
|
||||
/// </summary>
|
||||
/// <param name="game">Game to check</param>
|
||||
public static bool IsValidSavedVersion(this GameVersion game) => 0 < game && game <= RB;
|
||||
public static bool IsValidSavedVersion(this GameVersion game) => game is > 0 and <= HighestGameID;
|
||||
|
||||
/// <summary>
|
||||
/// Most recent game ID utilized by official games.
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace PKHeX.Core
|
|||
|
||||
public override IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, IReadOnlyList<EvoCriteria> chain)
|
||||
{
|
||||
int rate = pkm is PK1 pk1 && pkm.Gen1_NotTradeback ? pk1.Catch_Rate : -1;
|
||||
int rate = pkm is PK1 {Gen1_NotTradeback: true} pk1 ? pk1.Catch_Rate : -1;
|
||||
foreach (var slot in Slots)
|
||||
{
|
||||
foreach (var evo in chain)
|
||||
|
|
|
@ -85,12 +85,12 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public static bool IsWildArea(int loc) => IsWildArea8(loc) || IsWildArea8Armor(loc) || IsWildArea8Crown(loc);
|
||||
public static bool IsBoostedArea60(int loc) => IsWildArea(loc);
|
||||
public static bool IsWildArea(int location) => IsWildArea8(location) || IsWildArea8Armor(location) || IsWildArea8Crown(location);
|
||||
public static bool IsBoostedArea60(int location) => IsWildArea(location);
|
||||
|
||||
private static bool IsWildArea8(int loc) => 122 <= loc && loc <= 154; // Rolling Fields -> Lake of Outrage
|
||||
private static bool IsWildArea8Armor(int loc) => 164 <= loc && loc <= 194; // Fields of Honor -> Honeycalm Island
|
||||
private static bool IsWildArea8Crown(int loc) => 204 <= loc && loc <= 234 && loc != 206; // Slippery Slope -> Dyna Tree Hill, skip Freezington
|
||||
private static bool IsWildArea8(int location) => location is >= 122 and <= 154; // Rolling Fields -> Lake of Outrage
|
||||
private static bool IsWildArea8Armor(int location) => location is >= 164 and <= 194; // Fields of Honor -> Honeycalm Island
|
||||
private static bool IsWildArea8Crown(int location) => location is >= 204 and <= 234 and not 206; // Slippery Slope -> Dyna Tree Hill, skip Freezington
|
||||
|
||||
// Location, and areas that it can feed encounters to.
|
||||
public static readonly IReadOnlyDictionary<int, IReadOnlyList<byte>> ConnectingArea8 = new Dictionary<int, IReadOnlyList<byte>>
|
||||
|
|
|
@ -160,7 +160,7 @@ namespace PKHeX.Core
|
|||
continue; // already flagged
|
||||
var cp = AllData[i];
|
||||
var ca = AllAnalysis[i];
|
||||
bool g345 = 3 <= ca.Info.Generation && ca.Info.Generation <= 5;
|
||||
bool g345 = ca.Info.Generation is 3 or 4 or 5;
|
||||
var id = g345 ? cp.EncryptionConstant : cp.PID;
|
||||
|
||||
if (!dict.TryGetValue(id, out var pa))
|
||||
|
@ -210,7 +210,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
const CheckIdentifier ident = PID;
|
||||
int gen = pa.Info.Generation;
|
||||
bool gbaNDS = 3 <= gen && gen <= 5;
|
||||
bool gbaNDS = gen is 3 or 4 or 5;
|
||||
|
||||
if (!gbaNDS)
|
||||
{
|
||||
|
@ -245,7 +245,7 @@ namespace PKHeX.Core
|
|||
return;
|
||||
}
|
||||
|
||||
bool gbaNDS = 3 <= gen && gen <= 5;
|
||||
bool gbaNDS = gen is 3 or 4 or 5;
|
||||
if (!gbaNDS)
|
||||
{
|
||||
AddLine(pa.pkm, ca.pkm, "PID sharing for 3DS-onward origin detected.", ident);
|
||||
|
|
|
@ -276,19 +276,6 @@ namespace PKHeX.Core
|
|||
new() { Roaming = true, Species = 146, Level = 60, TypeEncounter = EncounterType.TallGrass | EncounterType.Surfing_Fishing, Version = Pt }, // Moltres
|
||||
};
|
||||
|
||||
internal static readonly EncounterStatic4 SpikyEaredPichu = new() // Spiky-Eared Pichu @ Ilex Forest
|
||||
{
|
||||
Species = 172,
|
||||
Level = 30,
|
||||
Gender = 1,
|
||||
Form = 1,
|
||||
Nature = Nature.Naughty,
|
||||
Location = 214,
|
||||
Moves = new[] { 344, 270, 207, 220 },
|
||||
TypeEncounter = EncounterType.Starter_Fossil_Gift_Pt_DPTrio,
|
||||
Shiny = Shiny.Never
|
||||
};
|
||||
|
||||
private static readonly EncounterStatic4[] Encounter_HGSS =
|
||||
{
|
||||
// Starters
|
||||
|
@ -344,7 +331,19 @@ namespace PKHeX.Core
|
|||
new() { Species = 143, Level = 50, Location = 159, }, // Snorlax @ Route 11
|
||||
new() { Species = 143, Level = 50, Location = 160, }, // Snorlax @ Route 12
|
||||
new() { Species = 185, Level = 20, Location = 184, }, // Sudowoodo @ Route 36, Encounter does not have type
|
||||
SpikyEaredPichu,
|
||||
|
||||
new() // Spiky-Eared Pichu @ Ilex Forest
|
||||
{
|
||||
Species = 172,
|
||||
Level = 30,
|
||||
Gender = 1,
|
||||
Form = 1,
|
||||
Nature = Nature.Naughty,
|
||||
Location = 214,
|
||||
Moves = new[] { 344, 270, 207, 220 },
|
||||
TypeEncounter = EncounterType.Starter_Fossil_Gift_Pt_DPTrio,
|
||||
Shiny = Shiny.Never
|
||||
},
|
||||
|
||||
// Stationary Legendary
|
||||
new() { Species = 144, Level = 50, Location = 203, TypeEncounter = EncounterType.Cave_HallOfOrigin }, // Articuno @ Seafoam Islands
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace PKHeX.Core
|
|||
// Let it get picked up as regular EncounterEgg under other conditions.
|
||||
if (pkm.Format > 2)
|
||||
return false;
|
||||
if (pkm.Move1 != Dizzy && pkm.Move2 != Dizzy && pkm.Move3 != Dizzy && pkm.Move4 != Dizzy)
|
||||
if (!pkm.HasMove(Dizzy))
|
||||
return false;
|
||||
if (pkm.IsEgg && pkm.EXP != 125)
|
||||
return false;
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
if (IVs.Count != 0 && !Legal.GetIsFixedIVSequenceValidNoRand(IVs, pkm))
|
||||
return false;
|
||||
if (pkm.Format == 2 && pkm.Met_Location != 0 && pkm.Met_Location != 126)
|
||||
if (pkm.Format == 2 && pkm.Met_Location is not 0 and not 126)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
foreach (var z in GetValidStaticEncounter(pkm, chain))
|
||||
{
|
||||
if (z.Gift && pkm.Ball != 4)
|
||||
if (z.Gift && pkm.Ball != z.Ball)
|
||||
deferIncompat.Enqueue(z);
|
||||
else
|
||||
yield return z;
|
||||
|
@ -269,7 +269,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
foreach (var z in GetValidStaticEncounter(pkm, chain))
|
||||
{
|
||||
if (z.Gift && pkm.Ball != 4)
|
||||
if (z.Gift && pkm.Ball != z.Ball)
|
||||
deferIncompat.Enqueue(z);
|
||||
else
|
||||
yield return z;
|
||||
|
|
|
@ -35,8 +35,6 @@ namespace PKHeX.Core
|
|||
int species = pkm.Species;
|
||||
if (info.EncounterMatch.Species == species)
|
||||
return true;
|
||||
if (info.EncounterMatch.EggEncounter && species == (int)Species.Milotic && pkm.Format >= 5 && !pkm.IsUntraded) // Prism Scale
|
||||
return true;
|
||||
if (species == (int)Species.Vespiquen && info.Generation < 6 && (pkm.PID & 0xFF) >= 0x1F) // Combee->Vespiquen Invalid Evolution
|
||||
return false;
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ namespace PKHeX.Core
|
|||
private static bool GetChannelMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv, PKM pk)
|
||||
{
|
||||
var ver = pk.Version;
|
||||
if (ver != (int) GameVersion.R && ver != (int) GameVersion.S)
|
||||
if (ver is not (int) GameVersion.R and not (int) GameVersion.S)
|
||||
return GetNonMatch(out pidiv);
|
||||
|
||||
var undo = top ^ 0x8000;
|
||||
|
@ -526,7 +526,7 @@ namespace PKHeX.Core
|
|||
|
||||
private static bool GetColoStarterMatch(PKM pk, uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
||||
{
|
||||
if (pk.Version != 15 || (pk.Species != 196 && pk.Species != 197))
|
||||
if (pk.Version != (int)GameVersion.CXD || pk.Species is not (int)Species.Espeon and not (int)Species.Umbreon)
|
||||
return GetNonMatch(out pidiv);
|
||||
|
||||
var iv1 = GetIVChunk(IVs, 0);
|
||||
|
@ -862,11 +862,12 @@ namespace PKHeX.Core
|
|||
{
|
||||
switch (encounter)
|
||||
{
|
||||
case EncounterStatic s:
|
||||
if (s == Encounters4.SpikyEaredPichu || (s.Location == Locations.PokeWalker4 && s.Gift)) // Pokewalker
|
||||
return val == PIDType.Pokewalker;
|
||||
if (s.Shiny == Shiny.Always)
|
||||
case EncounterStatic4Pokewalker:
|
||||
case EncounterStatic4 {Species: (int)Species.Pichu}:
|
||||
return val == PIDType.Pokewalker;
|
||||
case EncounterStatic4 {Shiny: Shiny.Always}:
|
||||
return val == PIDType.ChainShiny;
|
||||
case EncounterStatic4:
|
||||
if (val == PIDType.CuteCharm && IsCuteCharm4Valid(encounter, pkm))
|
||||
return true;
|
||||
return val == PIDType.Method_1;
|
||||
|
@ -879,9 +880,7 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
// 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 is GameVersion.D or GameVersion.P or GameVersion.Pt;
|
||||
return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Locations.IsSafariZoneLocation4(sl.Location);
|
||||
return pkm.IsShiny && !pkm.HGSS && sl.TypeEncounter == EncounterType.TallGrass && !Locations.IsSafariZoneLocation4(sl.Location);
|
||||
case PGT: // manaphy
|
||||
return IsG4ManaphyPIDValid(val, pkm);
|
||||
case PCD d when d.Gift.PK.PID != 1:
|
||||
|
@ -924,7 +923,7 @@ namespace PKHeX.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool IsCuteCharmAzurillMale(uint pid) => pid >= 0xC8 && pid <= 0xE0;
|
||||
private static bool IsCuteCharmAzurillMale(uint pid) => pid is >= 0xC8 and <= 0xE0;
|
||||
|
||||
private static void GetCuteCharmGenderSpecies(PKM pk, uint pid, out int genderValue, out int species)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace PKHeX.Core
|
|||
if (skipBetweenPID) // VBlank skip between PID rand() [RARE]
|
||||
B = rng.Next(B);
|
||||
|
||||
var swappedPIDHalves = PIDType.Method_1_Unown <= type && type <= PIDType.Method_4_Unown;
|
||||
var swappedPIDHalves = type is >= PIDType.Method_1_Unown and <= PIDType.Method_4_Unown;
|
||||
if (swappedPIDHalves) // switched order of PID halves, "BA.."
|
||||
pk.PID = (A & 0xFFFF0000) | B >> 16;
|
||||
else
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace PKHeX.Core
|
|||
|
||||
// Check AbilityNumber for transfers without unique abilities
|
||||
int gen = data.Info.Generation;
|
||||
if (3 <= gen && gen <= 5 && num != 4)
|
||||
if (gen is 3 or 4 or 5 && num != 4)
|
||||
{
|
||||
// To determine AbilityNumber [PK5->PK6], check if the first ability in Personal matches the ability.
|
||||
// It is not possible to flip it to the other index as capsule requires unique abilities.
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace PKHeX.Core
|
|||
private static void VerifyCXDStarterCorrelation(LegalityAnalysis data)
|
||||
{
|
||||
var pidiv = data.Info.PIDIV;
|
||||
if (pidiv.Type != PIDType.CXD && pidiv.Type != PIDType.CXDAnti)
|
||||
return;
|
||||
if (pidiv.Type is not PIDType.CXD and not PIDType.CXDAnti)
|
||||
return; // already flagged as invalid
|
||||
|
||||
bool valid;
|
||||
var EncounterMatch = data.EncounterMatch;
|
||||
|
|
|
@ -215,11 +215,11 @@ namespace PKHeX.Core
|
|||
|
||||
public static int GetArceusFormFromHeldItem(int item, int format)
|
||||
{
|
||||
if (777 <= item && item <= 793)
|
||||
if (item is >= 777 and <= 793)
|
||||
return Array.IndexOf(Arceus_ZCrystal, (ushort)item) + 1;
|
||||
|
||||
int form = 0;
|
||||
if ((298 <= item && item <= 313) || item == 644)
|
||||
if (item is >= 298 and <= 313 or 644)
|
||||
form = Array.IndexOf(Arceus_PlateIDs, (ushort)item) + 1;
|
||||
if (format == 4 && form >= 9)
|
||||
return form + 1; // ??? type Form shifts everything by 1
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace PKHeX.Core
|
|||
data.AddLine(Get(msg, Severity.Fishy));
|
||||
return true;
|
||||
}
|
||||
if (pkm.Format <= 7 && StringConverter.HasEastAsianScriptCharacters(nickname) && !(pkm is PB7)) // East Asian Scripts
|
||||
if (pkm.Format <= 7 && StringConverter.HasEastAsianScriptCharacters(nickname) && pkm is not PB7) // East Asian Scripts
|
||||
{
|
||||
data.AddLine(GetInvalid(LNickInvalidChar));
|
||||
return true;
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace PKHeX.Core
|
|||
// 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.
|
||||
var xor = pkm.ShinyXor;
|
||||
if (xor <= 15 && xor != 1)
|
||||
if (xor is <= 15 and not 1)
|
||||
data.AddLine(GetInvalid(LEncStaticPIDShiny, CheckIdentifier.Shiny));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
if (pkm is IRibbonSetCommon4 s4)
|
||||
{
|
||||
bool inhabited4 = 3 <= gen && gen <= 4;
|
||||
bool inhabited4 = gen is 3 or 4;
|
||||
var iterate = GetInvalidRibbons4Any(pkm, s4, gen);
|
||||
if (!inhabited4)
|
||||
iterate = iterate.Concat(GetInvalidRibbonsNone(s4.RibbonBitsOnly(), s4.RibbonNamesOnly()));
|
||||
|
@ -138,7 +138,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
if (pkm is IRibbonSetCommon6 s6)
|
||||
{
|
||||
bool inhabited6 = 3 <= gen && gen <= 6;
|
||||
bool inhabited6 = gen is >= 3 and <= 6;
|
||||
|
||||
var iterate = inhabited6
|
||||
? GetInvalidRibbons6Any(pkm, s6, gen, enc)
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
if ('0' <= c)
|
||||
return c <= '9';
|
||||
return c <= '9' && '0' <= c;
|
||||
return c is >= '0' and <= '9';
|
||||
}
|
||||
|
||||
return str.Count(IsNumber);
|
||||
|
|
|
@ -59,11 +59,11 @@ namespace PKHeX.Core
|
|||
return growth switch
|
||||
{
|
||||
0 => // MediumFast -- Can't be Brave, Adamant, Naughty, Bold, Docile, or Relaxed
|
||||
(nature < (int) Nature.Brave || nature > (int) Nature.Relaxed),
|
||||
(nature is < (int) Nature.Brave or > (int) Nature.Relaxed),
|
||||
4 => // Fast -- Can't be Gentle, Sassy, Careful, Quirky, Hardy, Lonely, Brave, Adamant, Naughty, or Bold
|
||||
(nature < (int) Nature.Gentle && nature > (int) Nature.Bold),
|
||||
(nature is < (int) Nature.Gentle and > (int) Nature.Bold),
|
||||
5 => // Slow -- Can't be Impish or Lax
|
||||
(nature != (int) Nature.Impish && nature != (int) Nature.Lax),
|
||||
(nature is not (int) Nature.Impish and not (int) Nature.Lax),
|
||||
_ => true
|
||||
};
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace PKHeX.Core
|
|||
// Star, not square. Requires transferring a shiny and having the initially random PID to already be a Star shiny.
|
||||
// (15:65536, ~1:4096) odds on a given shiny transfer!
|
||||
var xor = data.pkm.ShinyXor;
|
||||
if (xor < 16 && xor != 0)
|
||||
if (xor is <= 15 and not 0)
|
||||
data.AddLine(Get(LEncStaticPIDShiny, ParseSettings.Gen7TransferStarPID, CheckIdentifier.PID));
|
||||
}
|
||||
|
||||
|
@ -103,11 +103,11 @@ namespace PKHeX.Core
|
|||
switch (pkm.Species)
|
||||
{
|
||||
case (int)Species.Celebi:
|
||||
if (loc != Locations.Transfer4_CelebiUnused && loc != Locations.Transfer4_CelebiUsed)
|
||||
if (loc is not Locations.Transfer4_CelebiUnused and not Locations.Transfer4_CelebiUsed)
|
||||
data.AddLine(GetInvalid(LTransferMet));
|
||||
break;
|
||||
case (int)Species.Raikou or (int)Species.Entei or (int)Species.Suicune:
|
||||
if (loc != Locations.Transfer4_CrownUnused && loc != Locations.Transfer4_CrownUsed)
|
||||
if (loc is not Locations.Transfer4_CrownUnused and not Locations.Transfer4_CrownUsed)
|
||||
data.AddLine(GetInvalid(LTransferMet));
|
||||
break;
|
||||
default:
|
||||
|
@ -195,7 +195,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
else if (pkm.Species == (int)Species.Unown)
|
||||
{
|
||||
if (pkm.Form != 8 && pkm.Form != 21 && pkm.IsShiny) // impossibly form-shiny (not I or V)
|
||||
if (pkm.Form is not 8 and not 21 && pkm.IsShiny) // impossibly form-shiny (not I or V)
|
||||
yield return GetInvalid(LEncStaticPIDShiny, CheckIdentifier.PID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -582,8 +582,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
if (MetLevel != 0 && MetLevel != pkm.Met_Level) return false;
|
||||
if (Ball != 0 && Ball != pkm.Ball) return false;
|
||||
if (Ball == 0 && pkm.Ball != 4) return false;
|
||||
if ((Ball == 0 ? 4 : Ball) != pkm.Ball) return false;
|
||||
if (OTGender < 2 && OTGender != pkm.OT_Gender) return false;
|
||||
if (Nature != -1 && pkm.Nature != Nature) return false;
|
||||
if (Gender != 3 && Gender != pkm.Gender) return false;
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace PKHeX.Core.Searching
|
|||
{
|
||||
1 => res.Where(pk => pk.EVTotal == 0), // None (0)
|
||||
2 => res.Where(pk => pk.EVTotal < 128), // Some (127-0)
|
||||
3 => res.Where(pk => pk.EVTotal >= 128 && pk.EVTotal < 508), // Half (128-507)
|
||||
3 => res.Where(pk => pk.EVTotal is >= 128 and < 508), // Half (128-507)
|
||||
4 => res.Where(pk => pk.EVTotal >= 508), // Full (508+)
|
||||
_ => res
|
||||
};
|
||||
|
@ -73,9 +73,9 @@ namespace PKHeX.Core.Searching
|
|||
return option switch
|
||||
{
|
||||
1 => res.Where(pk => pk.IVTotal <= 90), // <= 90
|
||||
2 => res.Where(pk => pk.IVTotal > 90 && pk.IVTotal <= 120), // 91-120
|
||||
3 => res.Where(pk => pk.IVTotal > 120 && pk.IVTotal <= 150), // 121-150
|
||||
4 => res.Where(pk => pk.IVTotal > 150 && pk.IVTotal < 180), // 151-179
|
||||
2 => res.Where(pk => pk.IVTotal is > 90 and <= 120), // 91-120
|
||||
3 => res.Where(pk => pk.IVTotal is > 120 and <= 150), // 121-150
|
||||
4 => res.Where(pk => pk.IVTotal is > 150 and < 180), // 151-179
|
||||
5 => res.Where(pk => pk.IVTotal >= 180), // 180+
|
||||
6 => res.Where(pk => pk.IVTotal == 186), // == 186
|
||||
_ => res
|
||||
|
|
|
@ -187,7 +187,7 @@
|
|||
Unused4 = Unused4,
|
||||
};
|
||||
|
||||
if (pk is CK3 ck3 && ck3.ShadowID != 0)
|
||||
if (pk is CK3 {ShadowID: not 0} ck3)
|
||||
ck3.Purification = CK3.Purified; // purified
|
||||
return pk;
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ namespace PKHeX.Core
|
|||
private const ushort Gen7_ZH_Ofs = 0xE800;
|
||||
private const ushort SM_ZHCharTable_Size = 0x30F;
|
||||
private const ushort USUM_CHS_Size = 0x4;
|
||||
private static bool GetisG7CHSChar(int idx) => idx < SM_ZHCharTable_Size || (SM_ZHCharTable_Size * 2 <= idx && idx < (SM_ZHCharTable_Size * 2) + USUM_CHS_Size);
|
||||
private static bool GetisG7CHSChar(int idx) => idx is < SM_ZHCharTable_Size or >= SM_ZHCharTable_Size * 2 and < (SM_ZHCharTable_Size * 2) + USUM_CHS_Size;
|
||||
|
||||
private static readonly Dictionary<char, int> G7_CHS = Gen7_ZH
|
||||
.Select((value, index) => new { value, index })
|
||||
|
@ -277,7 +277,7 @@ namespace PKHeX.Core
|
|||
|
||||
var context = str.Except(FullToHalf);
|
||||
bool fullwidth = context.Select(c => c >> 12) // select the group the char belongs to
|
||||
.Any(c => c != 0 /* Latin */ && c != 0xE /* Special Symbols */);
|
||||
.Any(c => c is not 0 and not 0xE /* Latin, Special Symbols */);
|
||||
|
||||
if (fullwidth) // jp/ko/zh strings
|
||||
return s; // keep as full width
|
||||
|
@ -289,6 +289,6 @@ namespace PKHeX.Core
|
|||
|
||||
private static readonly char[] FullToHalf = {'\u2640', '\u2642'}; // ♀♂
|
||||
|
||||
public static bool HasEastAsianScriptCharacters(IEnumerable<char> str) => str.Any(c => 0x4E00 <= c && c <= 0x9FFF);
|
||||
public static bool HasEastAsianScriptCharacters(IEnumerable<char> str) => str.Any(c => c is >= '\u4E00' and <= '\u9FFF');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="data">Raw string bytes</param>
|
||||
/// <returns>Indication if the data is from a definitely-german string</returns>
|
||||
public static bool IsG12German(IEnumerable<byte> data) => data.Any(z => z >= 0xC0 && z <= 0xC6);
|
||||
public static bool IsG12German(IEnumerable<byte> data) => data.Any(z => z is >= 0xC0 and <= 0xC6);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the input byte array is definitely of German origin (any ÄÖÜäöü)
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
var val = data[offset + i];
|
||||
var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U;
|
||||
if (val <= 0xB && val != 0)
|
||||
if (val is <= 0xB and not 0)
|
||||
val = data[offset + ++i];
|
||||
if (!dict.TryGetValue(val, out var c)) // Take valid values
|
||||
break;
|
||||
|
|
|
@ -197,7 +197,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (pk.Format >= 3 && pk.Format > format)
|
||||
return false; // pk3->upward can't go backwards
|
||||
if (pk.Format <= 2 && format > 2 && format < 7)
|
||||
if (pk.Format <= 2 && format is > 2 and < 7)
|
||||
return false; // pk1/2->upward has to be 7 or greater
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Format hint that the file is.</returns>
|
||||
public static int GetPKMFormatFromExtension(char last, int prefer)
|
||||
{
|
||||
if ('1' <= last && last <= '9')
|
||||
if (last is >= '1' and <= '9')
|
||||
return last - '0';
|
||||
return last == 'x' ? 6 : prefer;
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
296 or 297 => metLevel != 30, // Makuhita 30 Colo 18 XD
|
||||
175 or 176 => metLevel != 20, // Togepi 20 Colo 25 XD, also 20 as Togetic in Colo
|
||||
179 or 180 or 181 => metLevel != 37 && metLevel != 30, // Mareep: 37 Colo 17 XD, Flaafy: 30 Colo
|
||||
179 or 180 or 181 => metLevel is not 37 and not 30, // Mareep: 37 Colo 17 XD, Flaafy: 30 Colo
|
||||
219 => metLevel != 30, // Magcargo 30 Colo 38 XD (Slugma in Colo)
|
||||
195 => metLevel != 30, // Quagsire 30 Colo // ** Wooper XD
|
||||
334 => metLevel != 33, // Altaria 33 Colo // 36 XD (Swablu in Colo)
|
||||
|
|
|
@ -224,13 +224,13 @@ namespace PKHeX.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
if (0 <= index && index < Table.Length)
|
||||
return Table[index];
|
||||
return Table[0];
|
||||
if ((uint)index >= Table.Length)
|
||||
return Table[0];
|
||||
return Table[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index < 0 || index >= Table.Length)
|
||||
if ((uint)index >= Table.Length)
|
||||
return;
|
||||
Table[index] = value;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace PKHeX.Core
|
|||
/// <returns>The resigned save data. Invalid input returns null.</returns>
|
||||
public static byte[] Resign7(byte[] sav7)
|
||||
{
|
||||
if (sav7.Length != SaveUtil.SIZE_G7SM && sav7.Length != SaveUtil.SIZE_G7USUM)
|
||||
if (sav7.Length is not SaveUtil.SIZE_G7SM and not SaveUtil.SIZE_G7USUM)
|
||||
throw new ArgumentException("Should not be using this for unsupported saves.");
|
||||
|
||||
// Save Chunks are 0x200 bytes each; Memecrypto signature is 0x100 bytes into the 2nd to last chunk.
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace PKHeX.Core
|
|||
public override IReadOnlyList<string> PKMExtensions => PKM.Extensions.Where(f =>
|
||||
{
|
||||
int gen = f.Last() - 0x30;
|
||||
return 1 <= gen && gen <= 2;
|
||||
return gen is 1 or 2;
|
||||
}).ToArray();
|
||||
|
||||
public SAV1(GameVersion version = GameVersion.RBY, bool japanese = false) : base(SaveUtil.SIZE_G1RAW)
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace PKHeX.Core
|
|||
int gen = f.Last() - 0x30;
|
||||
if (Korean)
|
||||
return gen == 2;
|
||||
return 1 <= gen && gen <= 2;
|
||||
return gen is 1 or 2;
|
||||
}).ToArray();
|
||||
|
||||
public SAV2(GameVersion version = GameVersion.C, LanguageID lang = LanguageID.English) : base(SaveUtil.SIZE_G2RAW_J)
|
||||
|
|
|
@ -439,7 +439,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
for (int i = 0; i < 8; i++) // 8 PGT
|
||||
{
|
||||
if (value[i] is PGT g && g.CardType != 0)
|
||||
if (value[i] is PGT {CardType: not 0})
|
||||
return true;
|
||||
}
|
||||
for (int i = 8; i < 11; i++) // 3 PCD
|
||||
|
|
|
@ -164,7 +164,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG1SAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G1RAW && data.Length != SIZE_G1BAT)
|
||||
if (data.Length is not SIZE_G1RAW and not SIZE_G1BAT)
|
||||
return Invalid;
|
||||
|
||||
// Check if it's not an american save or a japanese save
|
||||
|
@ -251,7 +251,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG3SAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G3RAW && data.Length != SIZE_G3RAWHALF)
|
||||
if (data.Length is not SIZE_G3RAW and not SIZE_G3RAWHALF)
|
||||
return Invalid;
|
||||
|
||||
// check the save file(s)
|
||||
|
@ -287,7 +287,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG3BOXSAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G3BOX && data.Length != SIZE_G3BOXGCI)
|
||||
if (data.Length is not SIZE_G3BOX and not SIZE_G3BOXGCI)
|
||||
return Invalid;
|
||||
|
||||
byte[] sav = data;
|
||||
|
@ -312,7 +312,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG3COLOSAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G3COLO && data.Length != SIZE_G3COLOGCI)
|
||||
if (data.Length is not SIZE_G3COLO and not SIZE_G3COLOGCI)
|
||||
return Invalid;
|
||||
|
||||
// Check the intro bytes for each save slot
|
||||
|
@ -331,7 +331,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG3XDSAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G3XD && data.Length != SIZE_G3XDGCI)
|
||||
if (data.Length is not SIZE_G3XD and not SIZE_G3XDGCI)
|
||||
return Invalid;
|
||||
|
||||
// Check the intro bytes for each save slot
|
||||
|
@ -416,7 +416,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
private static GameVersion GetIsG6SAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G6XY && data.Length != SIZE_G6ORAS && data.Length != SIZE_G6ORASDEMO)
|
||||
if (data.Length is not SIZE_G6XY and not SIZE_G6ORAS and not SIZE_G6ORASDEMO)
|
||||
return Invalid;
|
||||
|
||||
if (BitConverter.ToUInt32(data, data.Length - 0x1F0) != BEEF)
|
||||
|
@ -434,7 +434,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
private static GameVersion GetIsG7SAV(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_G7SM && data.Length != SIZE_G7USUM)
|
||||
if (data.Length is not SIZE_G7SM and not SIZE_G7USUM)
|
||||
return Invalid;
|
||||
|
||||
if (BitConverter.ToUInt32(data, data.Length - 0x1F0) != BEEF)
|
||||
|
|
|
@ -123,11 +123,12 @@ namespace PKHeX.Drawing
|
|||
|
||||
private Image LayerOverImageItem(Image baseImage, int item, int generation)
|
||||
{
|
||||
Image itemimg = (Image?)Resources.ResourceManager.GetObject(GetItemResourceName(item)) ?? UnknownItem;
|
||||
if (2 <= generation && generation <= 4 && 328 <= item && item <= 419) // gen2/3/4 TM
|
||||
itemimg = Resources.item_tm;
|
||||
else if (generation >= 8 && (1130 <= item && item <= 1229)) // Gen8 TR
|
||||
itemimg = Resources.bitem_tr;
|
||||
Image itemimg = generation switch
|
||||
{
|
||||
<= 4 when item is >= 328 and <= 419 => Resources.item_tm, // gen2/3/4 TM
|
||||
>= 8 when item is >= 1130 and <= 1229 => Resources.bitem_tr, // Gen8 TR
|
||||
_ => (Image?)Resources.ResourceManager.GetObject(GetItemResourceName(item)) ?? UnknownItem,
|
||||
};
|
||||
|
||||
// Redraw item in bottom right corner; since images are cropped, try to not have them at the edge
|
||||
int x = ItemShiftX + ((ItemMaxSize - itemimg.Width) / 2);
|
||||
|
|
|
@ -224,7 +224,7 @@ namespace PKHeX.WinForms
|
|||
int gt = SAV.Personal[index].Gender;
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255 && ModifierKeys != Keys.Control;
|
||||
|
||||
if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
|
@ -305,7 +305,7 @@ namespace PKHeX.WinForms
|
|||
if (mnuComplete == sender)
|
||||
{
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254; // not female only
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255; // not male only or genderless
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255; // not male only or genderless
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -369,9 +369,10 @@ namespace PKHeX.WinForms
|
|||
return;
|
||||
}
|
||||
|
||||
if (PKX.GetGenderFromString(CB_Form.Text) == 0 && Label_Gender.Text != gendersymbols[0])
|
||||
var g = PKX.GetGenderFromString(CB_Form.Text);
|
||||
if (g == 0 && Label_Gender.Text != gendersymbols[0])
|
||||
CB_Form.SelectedIndex = 1;
|
||||
else if (PKX.GetGenderFromString(CB_Form.Text) == 1 && Label_Gender.Text != gendersymbols[1])
|
||||
else if (g == 1 && Label_Gender.Text != gendersymbols[1])
|
||||
CB_Form.SelectedIndex = 0;
|
||||
|
||||
if (species == (int)Species.Pyroar)
|
||||
|
|
|
@ -219,7 +219,7 @@ namespace PKHeX.WinForms
|
|||
int gt = SAV.Personal[index].Gender;
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255 && ModifierKeys != Keys.Control;
|
||||
|
||||
if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
|
@ -318,7 +318,7 @@ namespace PKHeX.WinForms
|
|||
if (mnuComplete == sender)
|
||||
{
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254; // not female only
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255; // not male only or genderless
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255; // not male only or genderless
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -232,7 +232,7 @@ namespace PKHeX.WinForms
|
|||
int gt = SAV.Personal[index].Gender;
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255 && ModifierKeys != Keys.Control;
|
||||
|
||||
if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
|
@ -310,7 +310,7 @@ namespace PKHeX.WinForms
|
|||
if (mnuComplete == sender)
|
||||
{
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254; // not female only
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255; // not male only or genderless
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255; // not male only or genderless
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -217,7 +217,7 @@ namespace PKHeX.WinForms
|
|||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254; // Not Female-Only
|
||||
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt != 0 && gt != 255; // Not Male-Only and Not Genderless
|
||||
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt is not 0 and not 255; // Not Male-Only and Not Genderless
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
CP[i + 1].Checked = Dex.GetSeen(currentSpecies, i);
|
||||
|
@ -339,7 +339,7 @@ namespace PKHeX.WinForms
|
|||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255 && ModifierKeys != Keys.Control;
|
||||
|
||||
if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace PKHeX.WinForms
|
|||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254; // Not Female-Only
|
||||
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt != 0 && gt != 255; // Not Male-Only and Not Genderless
|
||||
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt is not 0 and not 255; // Not Male-Only and Not Genderless
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
CP[i + 1].Checked = Dex.GetSeen(currentSpecies, i);
|
||||
|
@ -277,7 +277,7 @@ namespace PKHeX.WinForms
|
|||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt is not 0 and not 255 && ModifierKeys != Keys.Control;
|
||||
|
||||
if (ModifierKeys == Keys.Control)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue