2018-06-24 05:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.SuperTrainingMedalCount"/> and associated values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class MedalVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Training;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
VerifyMedalsRegular(data);
|
|
|
|
|
VerifyMedalsEvent(data);
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
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
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperUnused));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
int TrainCount = pkm.SuperTrainingMedalCount();
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg && TrainCount > 0)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperEgg));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (TrainCount > 0 && Info.Generation > 6)
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperUnavailable));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pkm.Format >= 7)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (pkm.SecretSuperTrainingUnlocked)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (pkm.SecretSuperTrainingComplete)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (TrainCount == 30 ^ pkm.SecretSuperTrainingComplete)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperComplete));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperUnused));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
int TrainCount = 0;
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
if ((value & 1) != 0)
|
|
|
|
|
TrainCount++;
|
|
|
|
|
value >>= 1;
|
|
|
|
|
}
|
|
|
|
|
if (pkm.IsEgg && TrainCount > 0)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperEgg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (TrainCount > 0 && Info.Generation > 6)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperUnavailable));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (TrainCount > 0)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LSuperDistro, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|