diff --git a/PKHeX.Core/Legality/Areas/EncounterArea2.cs b/PKHeX.Core/Legality/Areas/EncounterArea2.cs index b8018ed37..b0770b06f 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea2.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea2.cs @@ -170,14 +170,14 @@ namespace PKHeX.Core private static List GetAreas2Fishing(byte[] data, ref int ofs) { var areas = new List(); - var types = new[] { SlotType.Old_Rod, SlotType.Good_Rod, SlotType.Super_Rod }; while (ofs != 0x18C) { + var old = GetSlots2Fishing(data, ref ofs, SlotType.Old_Rod); + var good = GetSlots2Fishing(data, ref ofs, SlotType.Good_Rod); + var super = GetSlots2Fishing(data, ref ofs, SlotType.Super_Rod); areas.Add(new EncounterArea2 { - Slots = GetSlots2Fishing(data, ref ofs, types[0]) - .Concat(GetSlots2Fishing(data, ref ofs, types[1])) - .Concat(GetSlots2Fishing(data, ref ofs, types[2])).ToArray() + Slots = ArrayUtil.ConcatAll(old, good, super), }); } diff --git a/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs b/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs index 9a5ee7374..9ca3087cc 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs @@ -1058,16 +1058,11 @@ namespace PKHeX.Core #region Alt Slots - internal static readonly int[] SafariZoneLocation_4 = - { - 52, 202 - }; - private static readonly EncounterArea4DPPt[] DPPt_Unown = { new EncounterArea4DPPt { Location = 53, // Solaceon Ruins - Slots = new int[25].Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 14, LevelMax = 30, Type = SlotType.Grass, Form = i+1 }).ToArray() // B->?, Unown A is loaded from encounters raw file + Slots = Enumerable.Range(1, 25).Select(i => new EncounterSlot { Species = 201, LevelMin = 14, LevelMax = 30, Type = SlotType.Grass, Form = i }).ToArray() // B->?, Unown A is loaded from encounters raw file }, }; @@ -1488,7 +1483,7 @@ namespace PKHeX.Core SlotsHGSS_BCC, new EncounterArea4HGSS { Location = 209, // Ruins of Alph - Slots = new int[25].Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 5, LevelMax = 5, Type = SlotType.Grass, Form = i+1 }).ToArray() // B->?, Unown A is loaded from encounters raw file + Slots = Enumerable.Range(1, 25).Select((_, i) => new EncounterSlot { Species = 201, LevelMin = 5, LevelMax = 5, Type = SlotType.Grass, Form = i }).ToArray() // B->?, Unown A is loaded from encounters raw file }, SlotsHGSS_SafariZone, //Some edge cases diff --git a/PKHeX.Core/Legality/Encounters/Information/ValidEncounterMoves.cs b/PKHeX.Core/Legality/Encounters/Information/ValidEncounterMoves.cs index ade64fb4d..a15fffe6c 100644 --- a/PKHeX.Core/Legality/Encounters/Information/ValidEncounterMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Information/ValidEncounterMoves.cs @@ -9,13 +9,13 @@ namespace PKHeX.Core /// public sealed class ValidEncounterMoves { - public IReadOnlyList[] LevelUpMoves { get; } = Empty; + public IReadOnlyList[] LevelUpMoves { get; } public IReadOnlyList[] TMHMMoves { get; } = Empty; public IReadOnlyList[] TutorMoves { get; } = Empty; public int[] Relearn = Array.Empty(); private const int EmptyCount = PKX.Generation + 1; // one for each generation index (and 0th) - private static readonly List[] Empty = new int[EmptyCount].Select(_ => new List()).ToArray(); + private static readonly IReadOnlyList[] Empty = Enumerable.Repeat((IReadOnlyList)new List(), EmptyCount).ToArray(); public ValidEncounterMoves(PKM pkm, LevelUpRestriction restrict, IEncounterable encounter) { diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs index 787233f53..5672b35e6 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs @@ -15,7 +15,7 @@ namespace PKHeX.Core public static CheckResult[] VerifyRelearn(PKM pkm, LegalInfo info) { - if (info.Generation < 6 || pkm is IBattleVersion v && v.BattleVersion != 0) + if (info.Generation < 6 || (pkm is IBattleVersion v && v.BattleVersion != 0)) return VerifyRelearnNone(pkm, info); return info.EncounterMatch switch diff --git a/PKHeX.Core/Legality/RNG/MethodFinder.cs b/PKHeX.Core/Legality/RNG/MethodFinder.cs index 8cd3f41bf..693f15135 100644 --- a/PKHeX.Core/Legality/RNG/MethodFinder.cs +++ b/PKHeX.Core/Legality/RNG/MethodFinder.cs @@ -884,7 +884,7 @@ namespace PKHeX.Core // TypeEncounter TallGrass discard any cave or city var ver = (GameVersion)pkm.Version; var IsDPPt = ver == GameVersion.D || ver == GameVersion.P || ver == GameVersion.Pt; - return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Encounters4.SafariZoneLocation_4.Contains(sl.Location); + return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Locations.IsSafariZoneLocation4(sl.Location); case PGT _: // manaphy return IsG4ManaphyPIDValid(val, pkm); case PCD d when d.Gift.PK.PID != 1: diff --git a/PKHeX.Core/Legality/Tables/Locations.cs b/PKHeX.Core/Legality/Tables/Locations.cs index ade36b4c3..49d4aae9d 100644 --- a/PKHeX.Core/Legality/Tables/Locations.cs +++ b/PKHeX.Core/Legality/Tables/Locations.cs @@ -97,5 +97,7 @@ public static bool IsPtHGSSLocation(int location) => 111 < location && location < 2000; public static bool IsPtHGSSLocationEgg(int location) => 2010 < location && location < 3000; public static bool IsEventLocation5(int location) => 40000 < location && location < 50000; + + public static bool IsSafariZoneLocation4(int loc) => loc == 52 || loc == 202; } } diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index ad0065ce4..3fcc6c557 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -388,7 +388,7 @@ namespace PKHeX.Core var bv = pk8.BattleVersion; if (bv != 0) { - if (bv != (int)GameVersion.SW && bv != (int)GameVersion.SH || pk8.SWSH) + if ((bv != (int)GameVersion.SW && bv != (int)GameVersion.SH) || pk8.SWSH) data.AddLine(GetInvalid(LStatBattleVersionInvalid)); } diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index 14cac3f18..2b6767d4a 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -192,12 +192,12 @@ namespace PKHeX.Core SeenFlagOffsets = SeenFlagOffsets.Where(z => z >= 0).ToArray(); } - private void LoadBlocks(out int[] blockOrder, out int[] blockOfs) + private void LoadBlocks(out short[] blockOrder, out int[] blockOfs) { - int[] o1 = GetBlockOrder(0); + var o1 = GetBlockOrder(0); if (Data.Length > SaveUtil.SIZE_G3RAWHALF) { - int[] o2 = GetBlockOrder(0xE000); + var o2 = GetBlockOrder(0xE000); ActiveSAV = GetActiveSaveIndex(o1, o2); blockOrder = ActiveSAV == 0 ? o1 : o2; } @@ -215,15 +215,15 @@ namespace PKHeX.Core } } - private int[] GetBlockOrder(int ofs) + private short[] GetBlockOrder(int ofs) { - int[] order = new int[BLOCK_COUNT]; + short[] order = new short[BLOCK_COUNT]; for (int i = 0; i < BLOCK_COUNT; i++) order[i] = BitConverter.ToInt16(Data, ofs + (i * SIZE_BLOCK) + 0xFF4); return order; } - private int GetActiveSaveIndex(int[] BlockOrder1, int[] BlockOrder2) + private int GetActiveSaveIndex(short[] BlockOrder1, short[] BlockOrder2) { int zeroBlock1 = Array.IndexOf(BlockOrder1, 0); int zeroBlock2 = Array.IndexOf(BlockOrder2, 0); @@ -276,7 +276,7 @@ namespace PKHeX.Core private int ActiveSAV; private int ABO => ActiveSAV*SIZE_BLOCK*0xE; - private readonly int[] BlockOrder; + private readonly short[] BlockOrder; private readonly int[] BlockOfs; public int GetBlockOffset(int block) => BlockOfs[block]; diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index 10c440d7a..6ba745b3f 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -452,9 +452,9 @@ namespace PKHeX.Core return false; } - private int[] MatchMysteryGifts(DataMysteryGift[] value) + private byte[] MatchMysteryGifts(DataMysteryGift[] value) { - int[] cardMatch = new int[8]; + byte[] cardMatch = new byte[8]; for (int i = 0; i < 8; i++) { if (!(value[i] is PGT pgt)) diff --git a/PKHeX.WinForms/Subforms/ReportGrid.cs b/PKHeX.WinForms/Subforms/ReportGrid.cs index d05b34812..49b7c8862 100644 --- a/PKHeX.WinForms/Subforms/ReportGrid.cs +++ b/PKHeX.WinForms/Subforms/ReportGrid.cs @@ -149,7 +149,7 @@ namespace PKHeX.WinForms int tabcount = lines[0].Count(c => c == '\t'); newlines[0] = lines[0].Replace('\t', '|'); - newlines[1] = string.Join(":--:", new int[tabcount + 2].Select(_ => '|')); // 2 pipes for each end + newlines[1] = string.Join(":--:", Enumerable.Repeat('|', tabcount + 2)); // 2 pipes for each end for (int i = 1; i < lines.Length; i++) newlines[i + 1] = lines[i].Replace('\t', '|'); return newlines;