From fefd3e6e72f5d64435eb3b096e064aa71fa512b3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 29 Jan 2017 09:26:40 -0800 Subject: [PATCH] Simplification changes remove dexlevel(lvl) call in favor of single species call, differentiate maxSpeciesOrigin from maxSpeciesTree --- PKHeX/Legality/Structures/EvolutionTree.cs | 42 ++++++++++------------ 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/PKHeX/Legality/Structures/EvolutionTree.cs b/PKHeX/Legality/Structures/EvolutionTree.cs index d618c1761..1d2c7af00 100644 --- a/PKHeX/Legality/Structures/EvolutionTree.cs +++ b/PKHeX/Legality/Structures/EvolutionTree.cs @@ -10,13 +10,13 @@ namespace PKHeX.Core private readonly EvolutionLineage[] Lineage; private readonly GameVersion Game; private readonly PersonalTable Personal; - private readonly int MaxSpecies; + private readonly int MaxSpeciesTree; - public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, int maxSpecies) + public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, int maxSpeciesTree) { Game = game; Personal = personal; - MaxSpecies = maxSpecies; + MaxSpeciesTree = maxSpeciesTree; switch (game) { case GameVersion.SM: @@ -32,7 +32,7 @@ namespace PKHeX.Core for (int i = 0; i < Entries.Count; i++) Lineage[i] = new EvolutionLineage(); if (Game == GameVersion.ORAS) - Array.Resize(ref Lineage, maxSpecies + 1); + Array.Resize(ref Lineage, maxSpeciesTree + 1); // Populate Lineages for (int i = 1; i < Lineage.Length; i++) @@ -149,7 +149,8 @@ namespace PKHeX.Core public IEnumerable getValidPreEvolutions(PKM pkm, int lvl, bool skipChecks = false) { int index = getIndex(pkm); - return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpecies); + int maxSpeciesOrigin = Legal.getMaxSpeciesOrigin(pkm); + return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpeciesTree, maxSpeciesOrigin); } } @@ -293,16 +294,6 @@ namespace PKHeX.Core } } - public DexLevel GetDexLevel(int lvl) - { - return new DexLevel - { - Species = Species, - Level = lvl, - Form = Form, - Flag = Method, - }; - } public DexLevel GetDexLevel(int species, int lvl) { @@ -352,9 +343,8 @@ namespace PKHeX.Core Chain.Insert(0, evo); } - public IEnumerable getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpecies) + public IEnumerable getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin) { - int maxSpeciesOrigin = Legal.getMaxSpeciesOrigin(pkm); List dl = new List { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } }; for (int i = Chain.Count-1; i >= 0; i--) // reverse evolution! { @@ -365,11 +355,14 @@ namespace PKHeX.Core continue; oneValid = true; - if (evo.Species > maxSpecies) // Gen7 Personal Formes -- unmap the forme personal entry to the actual species ID since species are consecutive - dl.Add(evo.GetDexLevel(pkm.Species - Chain.Count + i, lvl)); - else - dl.Add(evo.GetDexLevel(lvl)); + int species = evo.Species; + // Gen7 Personal Formes -- unmap the forme personal entry ID to the actual species ID since species are consecutive + if (evo.Species > maxSpeciesTree) + species = pkm.Species - Chain.Count + i; + + dl.Add(evo.GetDexLevel(species, lvl)); + if (evo.RequiresLevelUp) lvl--; break; @@ -377,8 +370,11 @@ namespace PKHeX.Core if (!oneValid) break; } - if (dl.Any(d=>d.Species <= maxSpeciesOrigin) && dl.Last().Species > maxSpeciesOrigin) - dl.RemoveAt(dl.Count - 1);//remove future gen preevolutions, no munchlax in a gen3 snorlax, no pichu in a gen1 vc raichu, etc + + // Remove future gen preevolutions, no munchlax in a gen3 snorlax, no pichu in a gen1 vc raichu, etc + if (dl.Any(d => d.Species <= maxSpeciesOrigin) && dl.Last().Species > maxSpeciesOrigin) + dl.RemoveAt(dl.Count - 1); + return dl; } }