PKHeX/PKHeX.Core/Legality/RNG/PIDIV.cs
Kurt 95fbf66a6e
Refactor: Gen3/4 Lead Encounters, property fixing (#4193)
In addition to the Method 1 (and other sibling PIDIV types) correlation, an encounter can only be triggered if the calls prior land on the Method {1} seed. The RNG community has dubbed these patterns as "Method J" (D/P/Pt), "Method K" (HG/SS), and "Method H" (Gen3, coined by yours truly). The basic gist of these is that they are pre-requisites, like the Shadow locks of Colosseum/XD. 

Rename/re-type a bunch of properties to get the codebase more in line with correct property names & more obvious underlying types.
2024-02-22 21:20:54 -06:00

58 lines
2.1 KiB
C#

using System.Runtime.InteropServices;
namespace PKHeX.Core;
/// <summary>
/// Stores details about a <see cref="PKM.EncryptionConstant"/> (PID) and any associated details being traced to a known correlation.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 10)]
public readonly struct PIDIV
{
internal static readonly PIDIV None = new();
internal static readonly PIDIV CuteCharm = new(PIDType.CuteCharm); // can be one of many seeds!
internal static readonly PIDIV Pokewalker = new(PIDType.Pokewalker);
internal static readonly PIDIV G5MGShiny = new(PIDType.G5MGShiny);
/// <summary>The RNG seed which immediately generates the PIDIV (starting with PID or IVs, whichever comes first)</summary>
[field: FieldOffset(0)]
public uint OriginSeed { get; }
/// <summary>The RNG seed which starts the encounter generation routine.</summary>
[field: FieldOffset(4)]
public uint EncounterSeed { get; init; }
/// <summary>The RNG seed which immediately generates the PIDIV (starting with PID or IVs, whichever comes first)</summary>
[field: FieldOffset(0)]
public ulong Seed64 { get; }
/// <summary>Type of PIDIV correlation</summary>
[field: FieldOffset(8)]
public PIDType Type { get; }
[field: FieldOffset(9)]
public LeadRequired Lead { get; init; }
public PIDIV(PIDType type, uint seed = 0)
{
Type = type;
OriginSeed = seed;
}
public PIDIV(PIDType type, ulong seed)
{
Type = type;
Seed64 = seed;
}
/// <remarks> Some PIDIVs may be generated without a single seed, but may follow a traceable pattern. </remarks>
/// <summary> Indicates that there is no <see cref="OriginSeed"/> to refer to. </summary>
public bool NoSeed => Type is PIDType.None or PIDType.Pokewalker or PIDType.G5MGShiny;
#if DEBUG
public override string ToString() => NoSeed ? Type.ToString() : $"{Type} - 0x{OriginSeed:X8}";
#endif
public bool IsClassicMethod() => Type.IsClassicMethod();
public bool IsSeed64() => false;
public PIDIV AsEncounteredVia(LeadSeed condition) => this with { Lead = condition.Lead, EncounterSeed = condition.Seed };
}