PKHeX/PKHeX.Core/Legality/Encounters/IEncounterable.cs
Kurt e04b96a9b3 Fix dizzy punch egg recognition & gen2 hatch conter verification
Closes #2939
Fixes #2938

Inline some logic where appropriate for egg levels
2020-07-12 20:58:07 -05:00

39 lines
1.2 KiB
C#

namespace PKHeX.Core
{
/// <summary>
/// Common Encounter Properties base interface.
/// </summary>
public interface IEncounterable : IVersion
{
int Species { get; }
int Form { get; }
string Name { get; }
string LongName { get; }
bool EggEncounter { get; }
int LevelMin { get; }
int LevelMax { get; }
int Generation { get; }
PKM ConvertToPKM(ITrainerInfo sav);
PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria);
}
public static partial class Extensions
{
private static bool IsWithinRange(this IEncounterable encounter, int lvl)
{
return encounter.LevelMin <= lvl && lvl <= encounter.LevelMax;
}
public static bool IsWithinRange(this IEncounterable encounter, PKM pkm)
{
if (!pkm.HasOriginalMetLocation)
return encounter.IsWithinRange(pkm.CurrentLevel);
if (encounter.EggEncounter)
return pkm.CurrentLevel == encounter.LevelMin;
if (encounter is MysteryGift g)
return pkm.CurrentLevel == g.Level;
return pkm.CurrentLevel == pkm.Met_Level;
}
}
}