PKHeX/PKHeX.Core/Legality/Encounters/Verifiers/EggHatchLocation4.cs
Kurt 5bdc6b9ef8
Privatize some static fields, more robust legal helper classes. (#3865)
* Uses LearnSource more throughout the codebase when appropriate, rather than loosely coupled pivot methods.
* Hides Learnset/EggMove data inside the LearnSource classes.
* Extracts functionality from the large Legal class & partial Table*.cs files into better performing helper classes.
* Cleans up some code from prior LearnSource commits.
2023-04-20 21:23:15 -07:00

61 lines
2.2 KiB
C#

using System;
using static PKHeX.Core.GameVersion;
namespace PKHeX.Core;
public static class EggHatchLocation4
{
private const byte MaskDP = 1 << 0; // 1
private const byte MaskPt = 1 << 1; // 2
private const byte MaskHGSS = 1 << 2; // 4
private const byte MaskAll4 = MaskDP | MaskPt | MaskHGSS; // 7
public static bool IsValidMet4(int location, GameVersion game) => game switch
{
D or P => IsValidMet4DP(location),
Pt => IsValidMet4Pt(location),
HG or SS => IsValidMet4HGSS(location),
_ => false,
};
public static bool IsValidMet4DP(int location) => HasLocationFlag(LocationPermitted4, MaskDP, location);
public static bool IsValidMet4Pt(int location) => HasLocationFlag(LocationPermitted4, MaskPt, location);
public static bool IsValidMet4HGSS(int location) => HasLocationFlag(LocationPermitted4, MaskHGSS, location);
public static bool IsValidMet4Any(int location) => HasLocationFlag(LocationPermitted4, MaskAll4, location);
private static bool HasLocationFlag(ReadOnlySpan<byte> arr, byte mask, int location)
{
if ((uint)location >= arr.Length)
return false;
var flags = arr[location];
return (flags & mask) != 0;
}
private static ReadOnlySpan<byte> LocationPermitted4 => new byte[]
{
0, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 2, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 2,
7, 3, 3, 3, 3, 2, 0, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 6, 6, 6, 6, 6, 2, 2, 2,
2, 2, 2, 2, 2, 2, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 0, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 0, 4,
};
}