diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index 1ad901904..10e951fda 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -77,38 +77,17 @@ public LegalityAnalysis(PKM pk, PersonalTable table = null) #endif { PersonalInfo = table?.GetFormeEntry(pk.Species, pk.AltForm) ?? pk.PersonalInfo; - switch (pk.Format) // prior to storing GameVersion - { - case 1: ParsePK1(pk); break; - case 2: ParsePK1(pk); break; - } + ParseLegality(pk); - if (!Parse.Any()) - switch (pk.GenNumber) - { - case 3: ParsePK3(pk); break; - case 4: ParsePK4(pk); break; - case 5: ParsePK5(pk); break; - case 6: ParsePK6(pk); break; + if (Parse.Count <= 0) + return; - case 1: case 2: - case 7: ParsePK7(pk); break; - } + Valid = Parse.All(chk => chk.Valid) + && Info.Moves.All(m => m.Valid) + && Info.Relearn.All(m => m.Valid); - if (Parse.Count > 0) - { - if (Parse.Any(chk => !chk.Valid)) - Valid = false; - else if (Info.Moves.Any(m => m.Valid != true)) - Valid = false; - else if (Info.Relearn.Any(m => m.Valid != true)) - Valid = false; - else - Valid = true; - - if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null) - AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful); - } + if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null) + AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful); } #if SUPPRESS catch (Exception e) @@ -122,6 +101,24 @@ public LegalityAnalysis(PKM pk, PersonalTable table = null) #endif Parsed = true; } + private void ParseLegality(PKM pk) + { + if (pk.Format == 1 || pk.Format == 2) // prior to storing GameVersion + { + ParsePK1(pk); + return; + } + switch (pk.GenNumber) + { + case 3: ParsePK3(pk); return; + case 4: ParsePK4(pk); return; + case 5: ParsePK5(pk); return; + case 6: ParsePK6(pk); return; + + case 1: case 2: + case 7: ParsePK7(pk); return; + } + } private void AddLine(Severity s, string c, CheckIdentifier i) { @@ -289,8 +286,6 @@ private void UpdateChecks() VerifyConsoleRegion(); VerifyVersionEvolution(); } - - // SecondaryChecked = true; } private string GetLegalityReport() { diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 4881e888e..54b7590d3 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -964,7 +964,7 @@ private void VerifyRibbons() } List result = RibbonVerifier.GetIncorrectRibbons(pkm, encounterContent, Info.Generation); - if (result.Any()) + if (result.Count != 0) AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s => !string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon); else AddLine(Severity.Valid, V602, CheckIdentifier.Ribbon); diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index aa3814903..29964e451 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -400,7 +400,7 @@ internal static List[] GetValidMovesAllGens(PKM pkm, DexLevel[][] evoChains { List[] Moves = new List[evoChains.Length]; for (int i = 1; i < evoChains.Length; i++) - if (evoChains[i].Any()) + if (evoChains[i].Length != 0) Moves[i] = GetValidMoves(pkm, evoChains[i], i, minLvLG1, minLvLG2, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM).ToList(); else Moves[i] = new List(); @@ -577,7 +577,7 @@ internal static List GetValidPostEvolutionMoves(PKM pkm, int Species, DexLe // Return moves that the pokemon could learn after evolving var moves = new List(); for (int i = 1; i < evoChains.Length; i++) - if (evoChains[i].Any()) + if (evoChains[i].Length != 0) moves.AddRange(GetValidPostEvolutionMoves(pkm, Species, evoChains[i], i, Version)); if (pkm.GenNumber >= 6) moves.AddRange(pkm.RelearnMoves.Where(m => m != 0)); @@ -1502,30 +1502,30 @@ internal static DexLevel[][] GetEvolutionChainsAllGens(PKM pkm, IEncounterable E // Remove future gen evolutions after a few special considerations, // it the pokemon origin is illegal like a "gen 3" Infernape the list will be emptied, it didnt existed in gen 3 in any evolution phase - while (CompleteEvoChain.Any() && CompleteEvoChain.First().Species > maxspeciesgen) + while (CompleteEvoChain.Length != 0 && CompleteEvoChain[0].Species > maxspeciesgen) { // Eevee requires to level one time to be Sylveon, it can be deduced in gen 5 and before it existed with maximum one level bellow current - if (CompleteEvoChain.First().Species == 700 && gen == 5) + if (CompleteEvoChain[0].Species == 700 && gen == 5) lvl--; // This is a gen 3 pokemon in a gen 4 phase evolution that requieres level up and then transfered to gen 5+ // We can deduce that it existed in gen 4 until met level, // but if current level is met level we can also deduce it existed in gen 3 until maximum met level -1 - if (gen == 3 && pkm.Format > 4 && lvl == pkm.CurrentLevel && CompleteEvoChain.First().Species > MaxSpeciesID_3 && CompleteEvoChain.First().RequiresLvlUp) + if (gen == 3 && pkm.Format > 4 && lvl == pkm.CurrentLevel && CompleteEvoChain[0].Species > MaxSpeciesID_3 && CompleteEvoChain[0].RequiresLvlUp) lvl--; // The same condition for gen2 evolution of gen 1 pokemon, level of the pokemon in gen 1 games would be CurrentLevel -1 one level bellow gen 2 level - if (gen == 1 && pkm.Format == 2 && lvl == pkm.CurrentLevel && CompleteEvoChain.First().Species > MaxSpeciesID_1 && CompleteEvoChain.First().RequiresLvlUp) + if (gen == 1 && pkm.Format == 2 && lvl == pkm.CurrentLevel && CompleteEvoChain[0].Species > MaxSpeciesID_1 && CompleteEvoChain[0].RequiresLvlUp) lvl--; CompleteEvoChain = CompleteEvoChain.Skip(1).ToArray(); } // Alolan form evolutions, remove from gens 1-6 chains - if (gen < 7 && pkm.Format >= 7 && CompleteEvoChain.Any() && CompleteEvoChain.First().Form > 0 && EvolveToAlolanForms.Contains(CompleteEvoChain.First().Species)) + if (gen < 7 && pkm.Format >= 7 && CompleteEvoChain.Length != 0 && CompleteEvoChain[0].Form > 0 && EvolveToAlolanForms.Contains(CompleteEvoChain[0].Species)) CompleteEvoChain = CompleteEvoChain.Skip(1).ToArray(); - if (!CompleteEvoChain.Any()) + if (CompleteEvoChain.Length == 0) continue; - GensEvoChains[gen] = GetEvolutionChain(pkm, Encounter, CompleteEvoChain.First().Species, lvl); + GensEvoChains[gen] = GetEvolutionChain(pkm, Encounter, CompleteEvoChain[0].Species, lvl); if (gen > 2 && !pkm.HasOriginalMetLocation && gen >= pkm.GenNumber) //Remove previous evolutions bellow transfer level //For example a gen3 charizar in format 7 with current level 36 and met level 36 @@ -1560,12 +1560,12 @@ private static DexLevel[] GetEvolutionChain(PKM pkm, IEncounterable Encounter, i int minindex = Math.Max(0, Array.FindIndex(vs, p => p.Species == minspec)); Array.Resize(ref vs, minindex + 1); - var last = vs.Last(); + var last = vs[vs.Length - 1]; if (last.MinLevel > 1) // Last entry from vs is removed, turn next entry into the wild/hatched pokemon { last.MinLevel = Encounter.LevelMin; last.RequiresLvlUp = false; - var first = vs.First(); + var first = vs[0]; if (!first.RequiresLvlUp) { if (first.MinLevel == 2) @@ -1645,7 +1645,7 @@ private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IRea r.AddRange(pkm.RelearnMoves); for (int gen = pkm.GenNumber; gen <= pkm.Format; gen++) - if (vs[gen].Any()) + if (vs[gen].Length != 0) r.AddRange(GetValidMoves(pkm, Version, vs[gen], gen, minLvLG1: minLvLG1, minLvLG2: minLvLG2, LVL: LVL, Relearn: false, Tutor: Tutor, Machine: Machine, MoveReminder: MoveReminder, RemoveTransferHM: RemoveTransferHM)); return r.Distinct(); @@ -1653,7 +1653,7 @@ private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IRea private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, DexLevel[] vs, int Generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) { List r = new List { 0 }; - if (!vs.Any()) + if (vs.Length == 0) return r; int species = pkm.Species; @@ -1667,7 +1667,7 @@ private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, DexL // In gen 3 deoxys has different forms depending on the current game, in personal info there is no alter form info formcount = 4; for (int i = 0; i < formcount; i++) - r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs.First().Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation)); + r.AddRange(GetMoves(pkm, species, minLvLG1, minLvLG2, vs[0].Level, i, moveTutor, Version, LVL, Tutor, Machine, MoveReminder, RemoveTransferHM, Generation)); if (Relearn) r.AddRange(pkm.RelearnMoves); return r.Distinct(); } diff --git a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs index 207b5c85c..ee295bf18 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs @@ -1489,7 +1489,7 @@ internal static EncounterArea GetCaptureLocation(PKM pkm) var vs = GetValidPreEvolutions(pkm); return (from area in GetEncounterSlots(pkm) let slots = GetValidEncounterSlots(pkm, area, vs, DexNav: pkm.AO, ignoreLevel: true).ToArray() - where slots.Any() + where slots.Length != 0 select new EncounterArea { Location = area.Location, diff --git a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs index b63d01806..8422969d5 100644 --- a/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs +++ b/PKHeX.Core/Legality/Encounters/VerifyCurrentMoves.cs @@ -322,7 +322,7 @@ private static void ParseMovesByGeneration(PKM pkm, CheckMoveResult[] res, int g if (res[m].Valid && gen == 1) { learnInfo.Gen1Moves.Add(m); - if (learnInfo.Gen2PreevoMoves.Any()) + if (learnInfo.Gen2PreevoMoves.Count != 0) learnInfo.MixedGen12NonTradeback = true; } @@ -368,7 +368,7 @@ private static void ParseEggMovesInherited(PKM pkm, CheckMoveResult[] res, int g if (!learnInfo.Source.EggLevelUpSource.Contains(moves[m])) // Check if contains level-up egg moves from parents continue; - if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1) + if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1) { res[m] = new CheckMoveResult(MoveSource.InheritLevelUp, gen, Severity.Invalid, V334, CheckIdentifier.Move); learnInfo.MixedGen12NonTradeback = true; @@ -396,7 +396,7 @@ private static void ParseEggMoves(PKM pkm, CheckMoveResult[] res, int gen, Learn { // To learn exclusive generation 1 moves the pokemon was tradeback, but it can't be trade to generation 1 // without removing moves above MaxMoveID_1, egg moves above MaxMoveID_1 and gen 1 moves are incompatible - if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1) + if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1) { res[m] = new CheckMoveResult(MoveSource.EggMove, gen, Severity.Invalid, V334, CheckIdentifier.Move) { Flag = true }; learnInfo.MixedGen12NonTradeback = true; @@ -413,7 +413,7 @@ private static void ParseEggMoves(PKM pkm, CheckMoveResult[] res, int gen, Learn if (!learnInfo.Source.EggMoveSource.Contains(moves[m])) { - if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Any() && moves[m] > Legal.MaxMoveID_1) + if (learnInfo.IsGen2Pkm && learnInfo.Gen1Moves.Count != 0 && moves[m] > Legal.MaxMoveID_1) { res[m] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, V334, CheckIdentifier.Move) { Flag = true }; learnInfo.MixedGen12NonTradeback = true; @@ -431,11 +431,11 @@ private static void ParseEggMovesRemaining(PKM pkm, CheckMoveResult[] res, Learn // A pokemon could have normal egg moves and regular egg moves // Only if all regular egg moves are event egg moves or all event egg moves are regular egg moves var RegularEggMovesLearned = learnInfo.EggMovesLearned.Union(learnInfo.LevelUpEggMoves).ToList(); - if (RegularEggMovesLearned.Any() && learnInfo.EventEggMoves.Any()) + if (RegularEggMovesLearned.Count != 0 && learnInfo.EventEggMoves.Count != 0) { // Moves that are egg moves or event egg moves but not both var IncompatibleEggMoves = RegularEggMovesLearned.Except(learnInfo.EventEggMoves).Union(learnInfo.EventEggMoves.Except(RegularEggMovesLearned)).ToList(); - if (!IncompatibleEggMoves.Any()) + if (IncompatibleEggMoves.Count == 0) return; foreach (int m in IncompatibleEggMoves) { @@ -448,7 +448,7 @@ private static void ParseEggMovesRemaining(PKM pkm, CheckMoveResult[] res, Learn } } // If there is no incompatibility with event egg check that there is no inherited move in gift eggs and event eggs - else if (RegularEggMovesLearned.Any() && (pkm.WasGiftEgg || pkm.WasEventEgg)) + else if (RegularEggMovesLearned.Count != 0 && (pkm.WasGiftEgg || pkm.WasEventEgg)) { foreach (int m in RegularEggMovesLearned) { @@ -474,7 +474,7 @@ private static void ParseRedYellowIncompatibleMoves(PKM pkm, IList area.Slots.Any()).ToArray(); + return areas.Where(area => area.Slots.Length != 0).ToArray(); } /// /// Gets the encounter areas with information from Pokémon Yellow (Generation 1) Fishing data. @@ -944,7 +944,7 @@ public static EncounterArea[] GetArray3(byte[][] entries) foreach (byte[] t in entries) { EncounterArea Area = GetArea3(t); - if (Area.Slots.Any()) + if (Area.Slots.Length != 0) Areas.Add(Area); } return Areas.ToArray(); diff --git a/PKHeX.Core/Legality/Structures/EvolutionTree.cs b/PKHeX.Core/Legality/Structures/EvolutionTree.cs index 56006f00a..67465d015 100644 --- a/PKHeX.Core/Legality/Structures/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Structures/EvolutionTree.cs @@ -724,7 +724,7 @@ public IEnumerable GetExplicitLineage(PKM pkm, int maxLevel, bool skip dl.Last().RequiresLvlUp = false; return dl; } - private static void UpdateMinValues(IReadOnlyCollection dl, EvolutionMethod evo) + private static void UpdateMinValues(IReadOnlyList dl, EvolutionMethod evo) { var last = dl.Last(); if (evo.Level == 0 || !evo.RequiresLevelUp) // Evolutions like elemental stones, trade, etc @@ -736,7 +736,7 @@ private static void UpdateMinValues(IReadOnlyCollection dl, EvolutionM // Evolutions like frienship, pichu -> pikachu, eevee -> umbreon, etc last.MinLevel = 2; - var first = dl.First(); + var first = dl[0]; if (dl.Count > 1 && !first.RequiresLvlUp) first.MinLevel = 2; // Raichu from Pikachu would have minimum level 1, but with Pichu included Raichu minimum level is 2 } @@ -745,7 +745,7 @@ private static void UpdateMinValues(IReadOnlyCollection dl, EvolutionM { last.MinLevel = evo.Level; - var first = dl.First(); + var first = dl[0]; if (dl.Count > 1) { if (first.MinLevel < evo.Level && !first.RequiresLvlUp) diff --git a/PKHeX.Core/Saves/SAV3.cs b/PKHeX.Core/Saves/SAV3.cs index dd17f5942..d03c7962c 100644 --- a/PKHeX.Core/Saves/SAV3.cs +++ b/PKHeX.Core/Saves/SAV3.cs @@ -253,7 +253,7 @@ public override string ChecksumInfo if (chk != BitConverter.ToUInt16(Data, ofs + 0xFF6)) list.Add($"Block {BlockOrder[i]:00} @ {i*SIZE_BLOCK:X5} invalid."); } - return list.Any() ? string.Join(Environment.NewLine, list) : "Checksums are valid."; + return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid."; } } diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index 51ff567af..e252b447a 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -123,7 +123,7 @@ public override string ChecksumInfo if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO)) list.Add("Large block checksum is invalid"); - return list.Any() ? string.Join(Environment.NewLine, list) : "Checksums are valid."; + return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid."; } } diff --git a/PKHeX.Core/Saves/SAV4BR.cs b/PKHeX.Core/Saves/SAV4BR.cs index f329b330b..f8abd6efa 100644 --- a/PKHeX.Core/Saves/SAV4BR.cs +++ b/PKHeX.Core/Saves/SAV4BR.cs @@ -47,7 +47,7 @@ public SAV4BR(byte[] data = null) } } - CurrentSlot = SaveSlots.First(); + CurrentSlot = SaveSlots[0]; Personal = PersonalTable.DP; HeldItems = Legal.HeldItems_DP; diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index b6ab17433..723addf74 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -625,7 +625,7 @@ public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1) public byte[] GetBoxBinary(int box) => BoxData.Skip(box*BoxSlotCount).Take(BoxSlotCount).SelectMany(pk => pk.EncryptedBoxData).ToArray(); public bool SetPCBinary(byte[] data) { - if (LockedSlots.Any()) + if (LockedSlots.Length != 0) return false; if (data.Length != PCBinary.Length) return false; diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index 55ad372ee..980300e72 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -245,7 +245,7 @@ public static List GetUnsortedCBList(string textfile) } public static List GetCBList(string[] inStrings, params int[][] allowed) { - if (allowed?.First() == null) + if (allowed?[0] == null) allowed = new[] { Enumerable.Range(0, inStrings.Length).ToArray() }; return allowed.SelectMany(list => list