diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs
index be3754aee..9708f6bbb 100644
--- a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs
+++ b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs
@@ -10,12 +10,16 @@ public sealed class EvolutionMethod
public int Method;
public int Species;
public int Argument;
- public int Form = -1;
+ public int Form = AnyForm;
public int Level;
+ public const int AnyForm = -1;
+
// Not stored in binary data
public bool RequiresLevelUp; // tracks if this method requires a Level Up, lazily set
+ public int GetDestinationForm(int form) => Form == AnyForm ? form : Method == (int)LevelUpFormFemale1 ? 1 : Form;
+
///
/// Checks the for validity by comparing against the data.
///
diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs
index 0d3b03b01..30647f3b0 100644
--- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs
+++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs
@@ -89,10 +89,40 @@ private EvolutionTree(IReadOnlyList data, GameVersion game, PersonalTabl
Personal = personal;
MaxSpeciesTree = maxSpeciesTree;
Entries = GetEntries(data);
- var connections = CreateTree();
+
+ // Starting in Generation 7, forms have separate evolution data.
+ int format = Game.GetGeneration();
+ var oldStyle = format < 7;
+ var connections = oldStyle ? CreateTreeOld() : CreateTree();
+
Lineage = connections.ToLookup(obj => obj.Key, obj => obj.Value);
}
+ private IEnumerable> CreateTreeOld()
+ {
+ for (int sSpecies = 1; sSpecies <= MaxSpeciesTree; sSpecies++)
+ {
+ var fc = Personal[sSpecies].FormeCount;
+ for (int sForm = 0; sForm < fc; sForm++)
+ {
+ var index = sSpecies;
+ var evos = Entries[index];
+ foreach (var evo in evos)
+ {
+ var dSpecies = evo.Species;
+ if (dSpecies == 0)
+ continue;
+
+ var dForm = sForm;
+ var key = GetLookupKey(dSpecies, dForm);
+
+ var link = new EvolutionLink(sSpecies, sForm, evo);
+ yield return new KeyValuePair(key, link);
+ }
+ }
+ }
+ }
+
private IEnumerable> CreateTree()
{
for (int sSpecies = 1; sSpecies <= MaxSpeciesTree; sSpecies++)
@@ -107,7 +137,12 @@ private EvolutionTree(IReadOnlyList data, GameVersion game, PersonalTabl
var dSpecies = evo.Species;
if (dSpecies == 0)
continue;
- var dForm = evo.Form < 0 ? sForm : evo.Form;
+
+ bool any = evo.Form == EvolutionMethod.AnyForm;
+ if (!any && evo.Form != sForm)
+ continue;
+
+ var dForm = evo.GetDestinationForm(sForm);
var key = GetLookupKey(dSpecies, dForm);
var link = new EvolutionLink(sSpecies, sForm, evo);
@@ -210,7 +245,7 @@ private IEnumerable GetPreEvolutions(int species, int form)
private IEnumerable GetEvolutions(int species, int form)
{
- int index = Personal.GetFormeIndex(species, form);
+ int index = GetLookupKey(species, form);
var node = Lineage[index];
foreach (var method in node)
{