mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +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.
56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Verifies the specific origin data of <see cref="GameVersion.CXD"/> encounters.
|
|
/// </summary>
|
|
public sealed class CXDVerifier : Verifier
|
|
{
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Misc;
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
{
|
|
var pk = data.Entity;
|
|
if (data.EncounterMatch is EncounterStatic3Colo { IsColoStarter: true })
|
|
VerifyStarterColo(data);
|
|
else if (data.EncounterMatch is EncounterStatic3XD { Species: (ushort)Species.Eevee })
|
|
VerifyStarterXD(data);
|
|
|
|
if (pk.OT_Gender == 1)
|
|
data.AddLine(GetInvalid(LG3OTGender, CheckIdentifier.Trainer));
|
|
}
|
|
|
|
private static void VerifyStarterColo(LegalityAnalysis data)
|
|
{
|
|
var type = data.Info.PIDIV.Type;
|
|
if (type is not (PIDType.CXD or PIDType.CXDAnti or PIDType.CXD_ColoStarter))
|
|
return; // already flagged as invalid
|
|
if (type != PIDType.CXD_ColoStarter)
|
|
data.AddLine(GetInvalid(LEncConditionBadRNGFrame, CheckIdentifier.PID));
|
|
}
|
|
|
|
private static void VerifyStarterXD(LegalityAnalysis data)
|
|
{
|
|
var (type, seed) = data.Info.PIDIV;
|
|
if (type is not (PIDType.CXD or PIDType.CXDAnti or PIDType.CXD_ColoStarter))
|
|
return; // already flagged as invalid
|
|
|
|
bool valid;
|
|
var pk = data.Entity;
|
|
if (type == PIDType.CXD_ColoStarter && pk.Species == (int)Species.Umbreon)
|
|
{
|
|
// reset pidiv type to be CXD -- ColoStarter is same correlation as Eevee->Umbreon
|
|
data.Info.PIDIV = new PIDIV(PIDType.CXD, seed);
|
|
valid = true;
|
|
}
|
|
else
|
|
{
|
|
valid = LockFinder.IsXDStarterValid(seed, pk.TID16, pk.SID16);
|
|
if (valid) // unroll seed to origin that generated TID16/SID16->pkm
|
|
data.Info.PIDIV = new PIDIV(PIDType.CXD, XDRNG.Prev4(seed));
|
|
}
|
|
if (!valid)
|
|
data.AddLine(GetInvalid(LEncConditionBadRNGFrame, CheckIdentifier.PID));
|
|
}
|
|
}
|