From fef1d6e0dd1bb20dfc5f0b48aa450bcb5186f0df Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 17 Apr 2018 19:56:43 -0700 Subject: [PATCH] de-linq some evolution dexlevel fetch use shared IList interface instead of IEnumerable --- PKHeX.Core/Legality/Core.cs | 26 +++++++++---------- .../Generator/EncounterMovesetGenerator.cs | 2 +- .../Legality/Evolutions/EvolutionTree.cs | 4 +-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index 36e1451e1..62f761976 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -301,14 +301,14 @@ internal static List[] GetValidMovesAllGens(PKM pkm, DexLevel[][] evoChains Moves[i] = new List(); return Moves; } - internal static IEnumerable GetValidMoves(PKM pkm, DexLevel[][] evoChains, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = true, bool Tutor = true, bool Machine = true, bool MoveReminder = true, bool RemoveTransferHM = true) + internal static IEnumerable GetValidMoves(PKM pkm, IList[] evoChains, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = true, bool Tutor = true, bool Machine = true, bool MoveReminder = true, bool RemoveTransferHM = true) { GameVersion version = (GameVersion)pkm.Version; if (!pkm.IsUntraded) version = GameVersion.Any; return GetValidMoves(pkm, version, evoChains, minLvLG1: minLvLG1, minLvLG2: minLvLG2, LVL: LVL, Relearn: false, Tutor: Tutor, Machine: Machine, MoveReminder: MoveReminder, RemoveTransferHM: RemoveTransferHM); } - internal static IEnumerable GetValidMoves(PKM pkm, DexLevel[] evoChain, int generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = true, bool Tutor = true, bool Machine = true, bool MoveReminder = true, bool RemoveTransferHM = true) + internal static IEnumerable GetValidMoves(PKM pkm, IList evoChain, int generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = true, bool Tutor = true, bool Machine = true, bool MoveReminder = true, bool RemoveTransferHM = true) { GameVersion version = (GameVersion)pkm.Version; if (!pkm.IsUntraded) @@ -1192,10 +1192,10 @@ public static int GetLowestLevel(PKM pkm, int startLevel) int count = 1; for (int i = 100; i >= startLevel; i--) { - var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks:true).ToArray(); - if (evos.Length < count) // lost an evolution, prior level was minimum current level + var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks:true); + if (evos.Count < count) // lost an evolution, prior level was minimum current level return evos.Max(evo => evo.Level) + 1; - count = evos.Length; + count = evos.Count; } return startLevel; } @@ -1270,13 +1270,13 @@ internal static int GetBaseSpecies(PKM pkm, int skipOption = 0, int generation = int tree = generation != -1 ? generation : pkm.Format; var table = EvolutionTree.GetEvolutionTree(tree); int maxSpeciesOrigin = generation != -1 ? GetMaxSpeciesOrigin(generation) : - 1; - var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks:true).ToArray(); + var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks:true); switch (skipOption) { case -1: return pkm.Species; - case 1: return evos.Length <= 1 ? pkm.Species : evos[evos.Length - 2].Species; - default: return evos.Length <= 0 ? pkm.Species : evos.Last().Species; + case 1: return evos.Count <= 1 ? pkm.Species : evos[evos.Count - 2].Species; + default: return evos.Count <= 0 ? pkm.Species : evos.Last().Species; } } private static int GetMaxLevelGeneration(PKM pkm) @@ -1556,22 +1556,22 @@ internal static IEnumerable GetValidPreEvolutions(PKM pkm, int maxspec var et = EvolutionTree.GetEvolutionTree(tree); return et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks); } - private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList vs, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) + private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList> vs, 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 (Relearn && pkm.Format >= 6) r.AddRange(pkm.RelearnMoves); for (int gen = pkm.GenNumber; gen <= pkm.Format; gen++) - if (vs[gen].Length != 0) + if (vs[gen].Count != 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(); } - 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) + private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IList 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.Length == 0) + if (vs.Count == 0) return r; int species = pkm.Species; @@ -1590,7 +1590,7 @@ private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, DexL return r.Distinct(); } - for (var i = 0; i < vs.Length; i++) + for (var i = 0; i < vs.Count; i++) { DexLevel evo = vs[i]; var minlvlevo1 = 1; diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs index 6cea66d1b..61226538a 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs @@ -79,7 +79,7 @@ public static IEnumerable GenerateVersionEncounters(PKM pk, IEnu { pk.Version = (int)version; var et = EvolutionTree.GetEvolutionTree(PKX.Generation); - var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true).ToArray(); + var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true); var gens = VerifyCurrentMoves.GetGenMovesCheckOrder(pk); var canlearn = gens.SelectMany(z => Legal.GetValidMoves(pk, dl, z)); diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index 6839f1ec3..047ea18ee 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -201,7 +201,7 @@ private int GetIndex(EvolutionMethod evo) return Personal.GetFormeIndex(evolvesToSpecies, evolvesToForm); } - public IEnumerable GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1) + public IList GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1) { int index = GetIndex(pkm); if (maxSpeciesOrigin <= 0) @@ -683,7 +683,7 @@ public void Insert(EvolutionStage evo) Chain.Insert(0, evo); } - public IEnumerable GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin, int minLevel) + public IList GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin, int minLevel) { int lvl = maxLevel; List dl = new List { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } };