From b1ecdde41d776941fe5e7c0c0fc2702be16b6bdd Mon Sep 17 00:00:00 2001 From: javierhimura Date: Wed, 15 Feb 2017 22:12:06 +0100 Subject: [PATCH] getEvolutionChain adapted to get evolution chains from previous generations Excluded future gen evolutions, both evolutions of species that does not exits in the generation expected in the chain, but also evolutions impossible because it requires a level above transfer level --- PKHeX/Legality/Core.cs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 27fd13c3e..bb529e2e7 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -742,9 +742,13 @@ internal static int getBaseSpecies(PKM pkm, int skipOption = 0) } } internal static DexLevel[] getEvolutionChain(PKM pkm, object Encounter) + { + return getEvolutionChain(pkm, Encounter,pkm.Species, 100); + } + public static DexLevel[] getEvolutionChain(PKM pkm, object Encounter,int maxspec, int maxlevel) { int minspec; - var vs = getValidPreEvolutions(pkm).ToArray(); + DexLevel[] vs = getValidPreEvolutions(pkm).ToArray(); // Evolution chain is in reverse order (devolution) @@ -757,8 +761,29 @@ internal static DexLevel[] getEvolutionChain(PKM pkm, object Encounter) else minspec = vs.Last().Species; - int index = Math.Max(0, Array.FindIndex(vs, p => p.Species == minspec)); - Array.Resize(ref vs, index + 1); + int minindex = Math.Max(0, Array.FindIndex(vs, p => p.Species == minspec)); + Array.Resize(ref vs, minindex + 1); + if(vs.Last().MinLevel > 1) //Last entry from vs is removed, turn next entry into the wild/hatched pokemon + { + vs.Last().MinLevel = 1; + vs.Last().RequiresLvlUp = false; + if (vs.First().MinLevel == 2 && !vs.First().RequiresLvlUp) + { + //Example Raichu in gen 2 or later, + //because Pichu requires level up minimun level of Raichu would be 2 + //but after removing Pichu because the origin species is Pikachu, Raichu min level should be 1 + vs.First().MinLevel = 1; + vs.First().RequiresLvlUp = false; + } + } + //Maxspec is used to remove future gen evolutions, to gather evolution chain of a pokemon in previous generations + int skip = Math.Max(0, Array.FindIndex(vs, p => p.Species == maxspec)); + //Maxlevel is also used for previous generations, it removes evolutions imposible before the transfer level + //For example a fire red charizard whose current level in XY is 50 but met level is 20, it couldnt be a Charizard in gen 3 and 4 games + vs = vs.Skip(skip).Where(e=>e.MinLevel <= maxlevel).ToArray(); + //Reduce the evolution chain levels to max level, because met level is the las one when the pokemon could be and learn moves in that generation + foreach (DexLevel d in vs) + d.Level = Math.Min(d.Level, maxlevel); return vs; } internal static string getEncounterTypeName(PKM pkm, object Encounter)