mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
dcc0e79435
Like move validation, evolutions are the earliest thing we wish to traverse when determining what encounters may have originated the current Pokémon. To determine the permitted species-form-levels a Pokémon could originate with, we must devolve a Pokémon by traveling down-generation to origin. Once we have an encounter, we can then evolve it to the current species, traversing upwards from origin to the current format.
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Evolution Info tracking how an evolution was performed, and the end result species and form.
|
|
/// </summary>
|
|
public readonly record struct EvoCriteria : ISpeciesForm
|
|
{
|
|
public required ushort Species { get; init; }
|
|
public byte Form { get; init; }
|
|
|
|
public byte LevelUpRequired { get; init; }
|
|
public byte LevelMax { get; init; }
|
|
public byte LevelMin { get; init; }
|
|
|
|
public EvolutionType Method { get; init; }
|
|
|
|
public bool RequiresLvlUp => LevelUpRequired != 0;
|
|
|
|
public bool InsideLevelRange(int level) => LevelMin <= level && level <= LevelMax;
|
|
|
|
public override string ToString() => $"{(Species) Species}{(Form != 0 ? $"-{Form}" : "")}}} [{LevelMin},{LevelMax}] via {Method}";
|
|
|
|
internal const EvolutionType SentinelNotReached = EvolutionType.Invalid;
|
|
|
|
public bool IsBetterDevolution(EvoCriteria reference)
|
|
{
|
|
if (reference.Species == 0)
|
|
return true;
|
|
|
|
return LevelMin + LevelUpRequired < reference.LevelMin + reference.LevelUpRequired;
|
|
}
|
|
|
|
public bool IsBetterEvolution(EvoCriteria reference)
|
|
{
|
|
if (reference.Method == SentinelNotReached)
|
|
return true;
|
|
|
|
if (LevelMin + LevelUpRequired > reference.LevelMin + reference.LevelUpRequired)
|
|
return false;
|
|
|
|
return LevelMax > reference.LevelMax;
|
|
}
|
|
}
|