mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-30 07:50:32 +00:00
f632aedd15
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.
33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Verifies the <see cref="PK4.GroundTile"/>.
|
|
/// </summary>
|
|
public sealed class GroundTileVerifier : Verifier
|
|
{
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Encounter;
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
{
|
|
if (data.Entity is not IGroundTile e)
|
|
return;
|
|
var enc = data.EncounterMatch;
|
|
bool valid = IsGroundTileValid(enc, e);
|
|
var result = !valid ? GetInvalid(LEncTypeMismatch) : GetValid(LEncTypeMatch);
|
|
data.AddLine(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates if the <see cref="IGroundTile"/> is valid for the <see cref="IEncounterTemplate"/>.
|
|
/// </summary>
|
|
/// <param name="enc">Encounter Template</param>
|
|
/// <param name="e">Entity with a stored <see cref="IGroundTile.GroundTile"/> value.</param>
|
|
/// <returns>True if stored ground tile value is permitted.</returns>
|
|
public static bool IsGroundTileValid(IEncounterTemplate enc, IGroundTile e)
|
|
{
|
|
var type = enc is IGroundTypeTile t ? t.GroundTile : GroundTileAllowed.None;
|
|
return type.Contains(e.GroundTile);
|
|
}
|
|
}
|