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>
|
2019-09-21 03:55:36 +00:00
|
|
|
|
/// Verifies the <see cref="ISuperTrain.SuperTrainingMedalCount"/> and associated values.
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// </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;
|
2019-09-21 03:55:36 +00:00
|
|
|
|
var train = (ISuperTrain)pkm;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var Info = data.Info;
|
2019-09-21 03:55:36 +00:00
|
|
|
|
uint value = BitConverter.ToUInt32(data.pkm.Data, 0x2C);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if ((value & 3) != 0) // 2 unused flags
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperUnused));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
int TrainCount = train.SuperTrainingMedalCount();
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2019-07-07 22:04:58 +00:00
|
|
|
|
if (pkm.IsEgg)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2019-07-07 22:04:58 +00:00
|
|
|
|
// Can't have any super training data as an egg.
|
|
|
|
|
if (TrainCount > 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperEgg));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
2019-07-07 22:04:58 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.SecretSuperTrainingComplete)
|
2019-07-07 22:04:58 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-07-07 22:04:58 +00:00
|
|
|
|
|
2020-12-25 20:30:26 +00:00
|
|
|
|
if (Info.Generation is >= 7 or <= 2)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2019-07-07 22:04:58 +00:00
|
|
|
|
// Can't have any super training data if it never visited Gen6.
|
|
|
|
|
if (TrainCount > 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperUnavailable));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
2019-07-07 22:04:58 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.SecretSuperTrainingComplete)
|
2019-07-07 22:04:58 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoComplete));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-07-07 22:04:58 +00:00
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (pkm.Format >= 7)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2019-07-07 22:04:58 +00:00
|
|
|
|
// Gen6->Gen7 transfer wipes the two Secret flags.
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.SecretSuperTrainingUnlocked)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LSuperNoUnlocked));
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (train.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
|
|
|
|
}
|
2019-07-07 22:04:58 +00:00
|
|
|
|
|
|
|
|
|
// Only reach here if Format==6.
|
2019-09-21 03:55:36 +00:00
|
|
|
|
if (TrainCount == 30 ^ train.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;
|
|
|
|
|
byte value = pkm.Data[0x3A];
|
2019-07-08 19:12:16 +00:00
|
|
|
|
if (value != 0)
|
|
|
|
|
data.AddLine(GetInvalid(LSuperDistro));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|