2022-03-14 05:33:17 +00:00
|
|
|
|
using System;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.EVs"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class EffortValueVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.EVs;
|
|
|
|
|
|
|
|
|
|
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 IAwakened a)
|
|
|
|
|
{
|
|
|
|
|
VerifyAwakenedValues(data, a);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var enc = data.EncounterMatch;
|
|
|
|
|
if (pk.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (pk.EVTotal is not 0)
|
|
|
|
|
data.AddLine(GetInvalid(LEffortEgg));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In Generations I and II, when a Pokémon is taken out of the Day Care, its experience will lower to the minimum value for its current level.
|
|
|
|
|
int format = pk.Format;
|
|
|
|
|
if (format < 3) // can abuse daycare for EV training without EXP gain
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int sum = pk.EVTotal;
|
|
|
|
|
if (sum > 510) // format >= 3
|
|
|
|
|
data.AddLine(GetInvalid(LEffortAbove510));
|
|
|
|
|
Span<int> evs = stackalloc int[6];
|
|
|
|
|
pk.GetEVs(evs);
|
|
|
|
|
if (format >= 6 && evs.Find(ev => ev > 252) != default)
|
|
|
|
|
data.AddLine(GetInvalid(LEffortAbove252));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
const int vitaMax = 100; // Vitamin Max
|
|
|
|
|
if (format < 5) // 3/4
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (enc.LevelMin == 100) // only true for Gen4 and Format=4
|
2018-11-16 22:19:24 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// Cannot EV train at level 100 -- Certain events are distributed at level 100.
|
|
|
|
|
if (evs.Find(ev => ev > vitaMax) != default) // EVs can only be increased by vitamins to a max of 100.
|
|
|
|
|
data.AddLine(GetInvalid(LEffortCap100));
|
2018-11-16 22:19:24 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
else // check for gained EVs without gaining EXP -- don't check gen5+ which have wings to boost above 100.
|
2022-03-14 05:33:17 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var growth = PersonalTable.HGSS[enc.Species].EXPGrowth;
|
|
|
|
|
var baseEXP = Experience.GetEXP(enc.LevelMin, growth);
|
|
|
|
|
if (baseEXP == pk.EXP && evs.Find(ev => ev > vitaMax) != default)
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEffortUntrainedCap, vitaMax)));
|
2022-03-14 05:33:17 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
}
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// Only one of the following can be true: 0, 508, and x%6!=0
|
|
|
|
|
if (sum == 0 && !enc.IsWithinEncounterRange(pk))
|
|
|
|
|
data.AddLine(Get(LEffortEXPIncreased, Severity.Fishy));
|
|
|
|
|
else if (sum == 508)
|
|
|
|
|
data.AddLine(Get(LEffort2Remaining, Severity.Fishy));
|
|
|
|
|
else if (evs[0] != 0 && evs.Count(evs[0]) == evs.Length)
|
|
|
|
|
data.AddLine(Get(LEffortAllEqual, Severity.Fishy));
|
|
|
|
|
}
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private void VerifyAwakenedValues(LegalityAnalysis data, IAwakened awakened)
|
|
|
|
|
{
|
|
|
|
|
var pk = data.Entity;
|
|
|
|
|
int sum = pk.EVTotal;
|
|
|
|
|
if (sum != 0)
|
|
|
|
|
data.AddLine(GetInvalid(LEffortShouldBeZero));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (!awakened.AwakeningAllValid())
|
|
|
|
|
data.AddLine(GetInvalid(LAwakenedCap));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
var enc = data.EncounterMatch;
|
2018-11-16 22:19:24 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// go park transfers have 2 AVs for all stats.
|
|
|
|
|
if (enc is EncounterSlot7GO)
|
2018-11-16 22:19:24 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
Span<byte> avs = stackalloc byte[6];
|
|
|
|
|
awakened.GetAVs(avs);
|
|
|
|
|
foreach (var av in avs)
|
2022-03-14 05:33:17 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
if (av >= 2)
|
|
|
|
|
continue;
|
2022-03-14 05:33:17 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LAwakenedShouldBeValue, 2)));
|
|
|
|
|
break;
|
2022-03-14 05:33:17 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
return;
|
2018-11-16 22:19:24 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
if (awakened.AwakeningSum() == 0 && !enc.IsWithinEncounterRange(pk))
|
|
|
|
|
data.AddLine(Get(LAwakenedEXPIncreased, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|