PKHeX/PKHeX.Core/Legality/Verifiers/MedalVerifier.cs
Kurt fef4dbb9dc More super training checks
Check the secret unlocked/complete flags for eggs
Check the count for VC, and flags too (even though they're checked
later, just do it here)
#2353
2019-07-07 15:04:58 -07:00

90 lines
3.2 KiB
C#

using System;
using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
/// <summary>
/// Verifies the <see cref="PKM.SuperTrainingMedalCount"/> and associated values.
/// </summary>
public sealed class MedalVerifier : Verifier
{
protected override CheckIdentifier Identifier => CheckIdentifier.Training;
public override void Verify(LegalityAnalysis data)
{
VerifyMedalsRegular(data);
VerifyMedalsEvent(data);
}
private void VerifyMedalsRegular(LegalityAnalysis data)
{
var pkm = data.pkm;
var Info = data.Info;
uint value = BitConverter.ToUInt32(pkm.Data, 0x2C);
if ((value & 3) != 0) // 2 unused flags
data.AddLine(GetInvalid(LSuperUnused));
int TrainCount = pkm.SuperTrainingMedalCount();
if (pkm.IsEgg)
{
// Can't have any super training data as an egg.
if (TrainCount > 0)
data.AddLine(GetInvalid(LSuperEgg));
if (pkm.SecretSuperTrainingUnlocked)
data.AddLine(GetInvalid(LSuperNoUnlocked));
if (pkm.SecretSuperTrainingComplete)
data.AddLine(GetInvalid(LSuperNoComplete));
return;
}
if (Info.Generation >= 7 || Info.Generation <= 2)
{
// Can't have any super training data if it never visited Gen6.
if (TrainCount > 0)
data.AddLine(GetInvalid(LSuperUnavailable));
if (pkm.SecretSuperTrainingUnlocked)
data.AddLine(GetInvalid(LSuperNoUnlocked));
if (pkm.SecretSuperTrainingComplete)
data.AddLine(GetInvalid(LSuperNoComplete));
return;
}
if (pkm.Format >= 7)
{
// Gen6->Gen7 transfer wipes the two Secret flags.
if (pkm.SecretSuperTrainingUnlocked)
data.AddLine(GetInvalid(LSuperNoUnlocked));
if (pkm.SecretSuperTrainingComplete)
data.AddLine(GetInvalid(LSuperNoComplete));
return;
}
// Only reach here if Format==6.
if (TrainCount == 30 ^ pkm.SecretSuperTrainingComplete)
data.AddLine(GetInvalid(LSuperComplete));
}
private void VerifyMedalsEvent(LegalityAnalysis data)
{
var pkm = data.pkm;
var Info = data.Info;
byte value = pkm.Data[0x3A];
if ((value & 0xC0) != 0) // 2 unused flags highest bits
data.AddLine(GetInvalid(LSuperUnused));
int TrainCount = 0;
for (int i = 0; i < 6; i++)
{
if ((value & 1) != 0)
TrainCount++;
value >>= 1;
}
if (pkm.IsEgg && TrainCount > 0)
data.AddLine(GetInvalid(LSuperEgg));
else if (TrainCount > 0 && Info.Generation > 6)
data.AddLine(GetInvalid(LSuperUnavailable));
else if (TrainCount > 0)
data.AddLine(Get(LSuperDistro, Severity.Fishy));
}
}
}