mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-03 09:21:04 -05:00
We implement simple state machine iterators to iterate through every split type encounter array, and more finely control the path we iterate through. And, by using generics, we can have the compiler generate optimized code to avoid virtual calls. In addition to this, we shift away from the big-5 encounter types and not inherit from an abstract class. This allows for creating a PK* of a specific type and directly writing properties (no virtual calls). Plus we can now fine-tune each encounter type to call specific code, and not have to worry about future game encounter types bothering the generation routines.
38 lines
912 B
C#
38 lines
912 B
C#
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Exposes details about an encounter with a specific location ID required.
|
|
/// </summary>
|
|
public interface ILocation
|
|
{
|
|
/// <summary>
|
|
/// Met Location ID the encounter is found at.
|
|
/// </summary>
|
|
int Location { get; }
|
|
|
|
/// <summary>
|
|
/// Egg Location ID the encounter is obtained with.
|
|
/// </summary>
|
|
int EggLocation { get; }
|
|
}
|
|
|
|
public static partial class Extensions
|
|
{
|
|
public static int GetLocation(this ILocation enc)
|
|
{
|
|
return enc.Location != 0
|
|
? enc.Location
|
|
: enc.EggLocation;
|
|
}
|
|
|
|
public static string? GetEncounterLocation(this ILocation enc, int gen, int version = -1)
|
|
{
|
|
int loc = enc.GetLocation();
|
|
if (loc < 0)
|
|
return null;
|
|
|
|
bool egg = loc != enc.Location;
|
|
return GameInfo.GetLocationName(egg, loc, gen, gen, (GameVersion)version);
|
|
}
|
|
}
|