Update form destination handling

espurr-F evolves to form-1 from form0, even tho the form arg is -1 (gen7
consideration)
gen8 has 0/1 for the two evolutions, dictating the destination form
This commit is contained in:
Kurt 2019-12-06 17:36:36 -08:00
parent f7620908df
commit 314d8f6b58
2 changed files with 43 additions and 4 deletions

View file

@ -10,12 +10,16 @@ namespace PKHeX.Core
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;
/// <summary>
/// Checks the <see cref="EvolutionMethod"/> for validity by comparing against the <see cref="PKM"/> data.
/// </summary>

View file

@ -89,10 +89,40 @@ namespace PKHeX.Core
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<KeyValuePair<int, EvolutionLink>> 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<int, EvolutionLink>(key, link);
}
}
}
}
private IEnumerable<KeyValuePair<int, EvolutionLink>> CreateTree()
{
for (int sSpecies = 1; sSpecies <= MaxSpeciesTree; sSpecies++)
@ -107,7 +137,12 @@ namespace PKHeX.Core
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 @@ namespace PKHeX.Core
private IEnumerable<int> 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)
{