2018-05-19 19:07:50 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Informatics pertaining to a <see cref="PKM"/>'s evolution lineage.
|
|
|
|
/// </summary>
|
|
|
|
public class EvolutionLineage
|
|
|
|
{
|
|
|
|
public readonly List<EvolutionStage> Chain = new List<EvolutionStage>();
|
|
|
|
|
|
|
|
public void Insert(EvolutionMethod entry)
|
|
|
|
{
|
|
|
|
int matchChain = -1;
|
|
|
|
for (int i = 0; i < Chain.Count; i++)
|
2018-06-10 21:45:25 +00:00
|
|
|
if (Chain[i].StageEntryMethods.Any(e => e.Species == entry.Species))
|
2018-05-19 19:07:50 +00:00
|
|
|
matchChain = i;
|
|
|
|
|
|
|
|
if (matchChain != -1)
|
|
|
|
Chain[matchChain].StageEntryMethods.Add(entry);
|
|
|
|
else
|
|
|
|
Chain.Insert(0, new EvolutionStage { StageEntryMethods = new List<EvolutionMethod> {entry}});
|
|
|
|
}
|
|
|
|
public void Insert(EvolutionStage evo)
|
|
|
|
{
|
|
|
|
Chain.Insert(0, evo);
|
|
|
|
}
|
|
|
|
|
2018-06-19 02:10:21 +00:00
|
|
|
public List<EvoCriteria> GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin, int minLevel)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
int lvl = maxLevel;
|
2018-06-19 02:10:21 +00:00
|
|
|
List<EvoCriteria> dl = new List<EvoCriteria> { new EvoCriteria { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } };
|
2018-05-19 19:07:50 +00:00
|
|
|
for (int i = Chain.Count - 1; i >= 0; i--) // reverse evolution!
|
|
|
|
{
|
|
|
|
bool oneValid = false;
|
|
|
|
foreach (var evo in Chain[i].StageEntryMethods)
|
|
|
|
{
|
|
|
|
if (!evo.Valid(pkm, lvl, skipChecks))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (evo.RequiresLevelUp && minLevel >= lvl)
|
|
|
|
break; // impossible evolution
|
|
|
|
|
|
|
|
oneValid = true;
|
|
|
|
UpdateMinValues(dl, evo);
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (evo.RequiresLevelUp)
|
|
|
|
lvl--;
|
2018-06-19 02:10:21 +00:00
|
|
|
dl.Add(evo.GetEvoCriteria(species, lvl));
|
2018-05-19 19:07:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!oneValid)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove future gen preevolutions, no munchlax in a gen3 snorlax, no pichu in a gen1 vc raichu, etc
|
|
|
|
var last = dl[dl.Count - 1];
|
|
|
|
if (last.Species > maxSpeciesOrigin && dl.Any(d => d.Species <= maxSpeciesOrigin))
|
|
|
|
dl.RemoveAt(dl.Count - 1);
|
|
|
|
|
|
|
|
// Last species is the wild/hatched species, the minimum is 1 because it has not evolved from previous species
|
|
|
|
last = dl[dl.Count - 1];
|
|
|
|
last.MinLevel = 1;
|
|
|
|
last.RequiresLvlUp = false;
|
|
|
|
return dl;
|
|
|
|
}
|
2018-06-19 02:10:21 +00:00
|
|
|
private static void UpdateMinValues(IReadOnlyList<EvoCriteria> dl, EvolutionMethod evo)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
|
|
|
var last = dl[dl.Count - 1];
|
|
|
|
if (evo.Level == 0 || !evo.RequiresLevelUp) // Evolutions like elemental stones, trade, etc
|
|
|
|
{
|
|
|
|
if (!evo.RequiresLevelUp)
|
|
|
|
last.MinLevel = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Evolutions like frienship, pichu -> pikachu, eevee -> umbreon, etc
|
|
|
|
last.MinLevel = 2;
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // level up evolutions
|
|
|
|
{
|
|
|
|
last.MinLevel = evo.Level;
|
|
|
|
|
|
|
|
var first = dl[0];
|
|
|
|
if (dl.Count > 1)
|
|
|
|
{
|
|
|
|
if (first.MinLevel < evo.Level && !first.RequiresLvlUp)
|
|
|
|
first.MinLevel = evo.Level; // Pokemon like Nidoqueen, its minimum level is Nidorina minimum level
|
|
|
|
if (first.MinLevel <= evo.Level && first.RequiresLvlUp)
|
|
|
|
first.MinLevel = evo.Level + 1; // Pokemon like Crobat, its minimum level is Golbat minimum level + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last.RequiresLvlUp = evo.RequiresLevelUp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|