PKHeX/PKHeX.Core/Legality/Structures/ILocation.cs

38 lines
912 B
C#
Raw Normal View History

2022-08-21 08:39:16 +00:00
namespace PKHeX.Core;
2022-08-21 08:39:16 +00:00
/// <summary>
/// Exposes details about an encounter with a specific location ID required.
/// </summary>
public interface ILocation
{
2022-08-21 08:39:16 +00:00
/// <summary>
/// Met Location ID the encounter is found at.
/// </summary>
int Location { get; }
2022-08-21 08:39:16 +00:00
/// <summary>
/// Egg Location ID the encounter is obtained with.
/// </summary>
int EggLocation { get; }
}
public static partial class Extensions
{
2022-08-21 08:39:16 +00:00
public static int GetLocation(this ILocation enc)
{
2022-08-21 08:39:16 +00:00
return enc.Location != 0
? enc.Location
: enc.EggLocation;
}
2022-08-21 08:39:16 +00:00
public static string? GetEncounterLocation(this ILocation enc, int gen, int version = -1)
{
2022-08-21 08:39:16 +00:00
int loc = enc.GetLocation();
if (loc < 0)
return null;
2022-08-21 08:39:16 +00:00
bool egg = loc != enc.Location;
return GameInfo.GetLocationName(egg, loc, gen, gen, (GameVersion)version);
}
}