2018-06-24 05:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="ISuperTrain.SuperTrainingMedalCount"/> and associated values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class MedalVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Training;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
VerifyMedalsRegular(data);
|
|
|
|
|
VerifyMedalsEvent(data);
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void VerifyMedalsRegular(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pk = data.Entity;
|
|
|
|
|
var train = (ISuperTrain)pk;
|
|
|
|
|
var Info = data.Info;
|
|
|
|
|
uint value = System.Buffers.Binary.BinaryPrimitives.ReadUInt32LittleEndian(data.Entity.Data.AsSpan(0x2C));
|
|
|
|
|
if ((value & 3) != 0) // 2 unused flags
|
|
|
|
|
data.AddLine(GetInvalid(LSuperUnused));
|
|
|
|
|
int TrainCount = train.SuperTrainingMedalCount();
|
|
|
|
|
|
|
|
|
|
if (pk.IsEgg)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// Can't have any super training data as an egg.
|
|
|
|
|
if (TrainCount > 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperEgg));
|
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
|
|
|
|
if (train.SecretSuperTrainingComplete)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (Info.Generation is >= 7 or <= 2)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// Can't have any super training data if it never visited Gen6.
|
|
|
|
|
if (TrainCount > 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperUnavailable));
|
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
|
|
|
|
if (train.SecretSuperTrainingComplete)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (pk.Format >= 7)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// Gen6->Gen7 transfer wipes the two Secret flags.
|
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
|
|
|
|
if (train.SecretSuperTrainingComplete)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
// Only reach here if Format==6.
|
|
|
|
|
if (TrainCount == 30 ^ train.SecretSuperTrainingComplete)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperComplete));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyMedalsEvent(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pk = data.Entity;
|
|
|
|
|
byte value = pk.Data[0x3A];
|
|
|
|
|
if (value != 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperDistro));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|