2022-11-25 01:42:17 +00:00
|
|
|
using System;
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies the <see cref="IHyperTrain"/> values.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class HyperTrainingVerifier : 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
|
|
|
var pk = data.Entity;
|
|
|
|
if (pk is not IHyperTrain t)
|
|
|
|
return; // No Hyper Training before Gen7
|
|
|
|
|
|
|
|
if (!t.IsHyperTrained())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!t.IsHyperTrainingAvailable(data.Info.EvoChainsAllGens))
|
|
|
|
{
|
|
|
|
data.AddLine(GetInvalid(LHyperPerfectUnavailable));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-04 01:19:16 +00:00
|
|
|
var minLevel = t.GetHyperTrainMinLevel(data.Info.EvoChainsAllGens, pk.Context);
|
2022-11-25 01:42:17 +00:00
|
|
|
if (pk.CurrentLevel < minLevel)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LHyperTooLow_0, minLevel)));
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int max = pk.MaxIV;
|
|
|
|
if (pk.IVTotal == max * 6)
|
|
|
|
{
|
|
|
|
data.AddLine(GetInvalid(LHyperPerfectAll));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
// already checked for 6IV, therefore we're flawed on at least one IV
|
|
|
|
if (t.IsHyperTrainedAll())
|
|
|
|
{
|
2023-04-15 08:58:37 +00:00
|
|
|
if (HasVisitedGoldBottleFlawless(data.Info.EvoChainsAllGens))
|
2022-11-25 01:42:17 +00:00
|
|
|
return;
|
2023-04-15 08:58:37 +00:00
|
|
|
// Otherwise, could not have hyper trained a flawless IV. Flag a flawless IV with the usual logic.
|
2022-11-25 01:42:17 +00:00
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2023-04-15 08:58:37 +00:00
|
|
|
if (IsFlawlessHyperTrained(pk, t, max))
|
|
|
|
data.AddLine(GetInvalid(LHyperPerfectOne));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool HasVisitedGoldBottleFlawless(EvolutionHistory evos)
|
|
|
|
{
|
|
|
|
// S/V gold bottle cap applies to all IVs regardless
|
|
|
|
// LGP/E gold bottle cap applies to all IVs regardless
|
|
|
|
foreach (ref var x in evos.Gen9.AsSpan())
|
|
|
|
{
|
|
|
|
if (x.LevelMax >= 50)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
foreach (ref var x in evos.Gen7b.AsSpan())
|
|
|
|
{
|
|
|
|
if (x.LevelMax >= 100)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsFlawlessHyperTrained(PKM pk, IHyperTrain t, int max)
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < 6; i++) // Check individual IVs
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2023-04-15 08:58:37 +00:00
|
|
|
if (pk.GetIV(i) == max && t.IsHyperTrained(i))
|
|
|
|
return true;
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2023-04-15 08:58:37 +00:00
|
|
|
return false;
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
|
|
|
}
|