From 76e52fa2cdf760fbdc568bbb257f9aea42df49bf Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 22 Jun 2018 20:16:31 -0700 Subject: [PATCH] Simplifications Rearrange some logic, track decrement, remove unnecessary checks --- .../Legality/Evolutions/EvolutionChain.cs | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs index 6cdde4bd2..b49ba3559 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs @@ -12,7 +12,7 @@ public static class EvolutionChain internal static IReadOnlyList[] GetEvolutionChainsAllGens(PKM pkm, IEncounterable Encounter) { var CompleteEvoChain = GetEvolutionChain(pkm, Encounter, pkm.Species, pkm.CurrentLevel); - if (Encounter is EncounterInvalid || pkm.IsEgg) + if (Encounter is EncounterInvalid || pkm.IsEgg || CompleteEvoChain.Count == 0) return GetChainSingle(pkm, CompleteEvoChain); return GetChainAll(pkm, Encounter, CompleteEvoChain); @@ -48,6 +48,7 @@ private static List[] GetChainAll(PKM pkm, IEncounterable Encounter // Iterate generations backwards // Maximum level of an earlier generation (GenX) will never be greater than a later generation (GenX+Y). int mingen = (pkm is PK2 || pkm.VC2) && !pkm.Gen2_NotTradeback ? 1 : pkGen; + bool noxfrDecremented = true; for (int g = GensEvoChains.Length - 1; g >= mingen; g--) { if (pkGen == 1 && pkm.Gen1_NotTradeback && g == 2) @@ -71,14 +72,10 @@ private static List[] GetChainAll(PKM pkm, IEncounterable Encounter return GensEvoChains; if (mostEvolved.RequiresLvlUp) { - // Eevee requires a single levelup to be Sylveon, it can be deduced in gen 5 and before it existed with maximum one level below current - if (g == 5 && mostEvolved.Species == 700) - lvl--; - - // This is a gen 3 pokemon in a gen 4 phase evolution that requieres level up and then transfered to gen 5+ + // This is a gen 3 pokemon in a gen 4 phase evolution that requires 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 - else if (g == 3 && pkm.Format > 4 && lvl == maxLevel) + if (g == 3 && pkm.Format > 4 && lvl == maxLevel) 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 below gen 2 level @@ -103,12 +100,14 @@ private static List[] GetChainAll(PKM pkm, IEncounterable Encounter if (GensEvoChains[g].Count == 0) continue; - if (g > 2 && !pkm.HasOriginalMetLocation && g >= pkGen) + if (g > 2 && !pkm.HasOriginalMetLocation && g >= pkGen && noxfrDecremented) { - bool isTransferred = GetCanPruneChainTransfer(pkm, pkGen, g); + bool isTransferred = HasMetLocationUpdatedTransfer(pkGen, g); if (!isTransferred) continue; + noxfrDecremented = false; + // Remove previous evolutions below transfer level // For example a gen3 Charizard in format 7 with current level 36 and met level 36, thus could never be Charmander / Charmeleon in Gen5+. // chain level for charmander is 35, is below met level. @@ -250,16 +249,6 @@ internal static List GetValidPreEvolutions(PKM pkm, int maxspecieso var et = EvolutionTree.GetEvolutionTree(tree); return et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks); } - - private static bool GetCanPruneChainTransfer(PKM pkm, int originGen, int currentGen) - { - // For transferred species, rule out pre-evolutions where their max level is not obtainable in the specified generation. - // Only prune entries for gen values that would overwrite the met data. - bool isTransferred = HasMetLocationUpdatedTransfer(originGen, currentGen); - if (pkm.Format >= 5 && currentGen == 4 && originGen == 3) - return false; // can't prune as the 3->4 data is overwritten again 4->5 - return isTransferred; - } private static int GetMinLevelGeneration(PKM pkm, int generation) { if (!pkm.InhabitedGeneration(generation))