PKHeX/PKHeX.Core/Legality/LearnSource/LearnMethod.cs
Kurt f632aedd15
Encounter Templates: Searching and Creating (#3955)
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.
2023-08-12 16:01:16 -07:00

69 lines
1.9 KiB
C#

namespace PKHeX.Core;
using static LearnMethod;
/// <summary>
/// Indicates the method of learning a move
/// </summary>
public enum LearnMethod : byte
{
// Invalid
None,
Duplicate,
EmptyInvalid,
Unobtainable,
UnobtainableExpect,
// Valid
Empty,
Initial,
LevelUp,
TMHM,
Tutor,
Sketch,
Special,
Shared,
ShedinjaEvo,
// Relearn
Relearn,
// Egg
EggMove,
InheritLevelUp,
SpecialEgg,
}
/// <summary>
/// Extension methods for <see cref="LearnMethod"/>.
/// </summary>
public static class LearnMethodExtensions
{
/// <summary>
/// Checks if the <see cref="LearnMethod"/> is a valid method of learning a move.
/// </summary>
/// <param name="method">Method to check</param>
/// <returns>True if the method is valid, false otherwise.</returns>
public static bool IsValid(this LearnMethod method) => method >= Empty;
/// <summary>
/// Checks if the <see cref="LearnMethod"/> is expecting another move instead.
/// </summary>
/// <param name="method">Method to check</param>
/// <returns>True if the method is valid, false otherwise.</returns>
public static bool HasExpectedMove(this LearnMethod method) => method is UnobtainableExpect;
/// <summary>
/// Checks if the <see cref="LearnMethod"/> is valid because of it being a Relearn move.
/// </summary>
/// <param name="method">Method to check</param>
/// <returns>True if the method is valid, false otherwise.</returns>
public static bool IsRelearn(this LearnMethod method) => method is Relearn;
/// <summary>
/// Checks if the <see cref="LearnMethod"/> is valid because of it being an egg move.
/// </summary>
/// <param name="method">Method to check</param>
/// <returns>True if the method is valid, false otherwise.</returns>
public static bool IsEggSource(this LearnMethod method) => method is EggMove or InheritLevelUp or SpecialEgg;
}