PKHeX/PKHeX.Core/Legality/Structures/IEncounterable.cs
Kurt 1e13220e6e Add IEncounterable -> pkm interface method
egg,slot,static,link,trade need to be implemented later

remove IEncounterable from PL6
2018-03-28 20:38:07 -07:00

35 lines
1.2 KiB
C#

namespace PKHeX.Core
{
/// <summary>
/// Common Encounter Properties base interface.
/// </summary>
public interface IEncounterable
{
int Species { get; }
string Name { get; }
bool EggEncounter { get; }
int LevelMin { get; }
int LevelMax { get; }
PKM ConvertToPKM(ITrainerInfo SAV);
}
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 == Legal.GetEggHatchLevel(pkm);
if (encounter is MysteryGift g)
return pkm.CurrentLevel == g.Level;
return pkm.CurrentLevel == pkm.Met_Level;
}
internal static string GetEncounterTypeName(this IEncounterable Encounter) => Encounter?.Name ?? "Unknown";
}
}