2018-06-24 05:00:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.EVs"/>.
|
|
|
|
|
/// </summary>
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public sealed class EffortValueVerifier : Verifier
|
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.EVs;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-11-16 22:19:24 +00:00
|
|
|
|
if (pkm is IAwakened a)
|
|
|
|
|
{
|
|
|
|
|
VerifyAwakenedValues(data, a);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var EncounterMatch = data.EncounterMatch;
|
|
|
|
|
int sum = pkm.EVTotal;
|
|
|
|
|
if (sum > 0 && pkm.IsEgg)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEffortEgg));
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
|
|
|
|
// 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 = pkm.Format;
|
|
|
|
|
if (format < 3) // can abuse daycare for EV training without EXP gain
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (sum > 510) // format >= 3
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEffortAbove510));
|
2019-01-05 18:51:41 +00:00
|
|
|
|
var evs = pkm.EVs;
|
|
|
|
|
if (format >= 6 && evs.Any(ev => ev > 252))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEffortAbove252));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2019-01-05 18:51:41 +00:00
|
|
|
|
const int vitaMax = 100; // Vitamin Max
|
|
|
|
|
if (format < 5) // 3/4
|
|
|
|
|
{
|
|
|
|
|
if (EncounterMatch.LevelMin == 100) // only true for Gen4 and Format=4
|
|
|
|
|
{
|
|
|
|
|
// Cannot EV train at level 100 -- Certain events are distributed at level 100.
|
|
|
|
|
if (evs.Any(ev => ev > vitaMax)) // EVs can only be increased by vitamins to a max of 100.
|
|
|
|
|
data.AddLine(GetInvalid(LEffortCap100));
|
|
|
|
|
}
|
|
|
|
|
else // check for gained EVs without gaining EXP -- don't check gen5+ which have wings to boost above 100.
|
|
|
|
|
{
|
|
|
|
|
var growth = PersonalTable.HGSS[EncounterMatch.Species].EXPGrowth;
|
|
|
|
|
var baseEXP = Experience.GetEXP(EncounterMatch.LevelMin, growth);
|
|
|
|
|
if (baseEXP == pkm.EXP && evs.Any(ev => ev > vitaMax))
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEffortUntrainedCap, vitaMax)));
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only one of the following can be true: 0, 508, and x%6!=0
|
|
|
|
|
if (sum == 0 && !EncounterMatch.IsWithinRange(pkm))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LEffortEXPIncreased, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (sum == 508)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LEffort2Remaining, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (evs[0] != 0 && evs.All(ev => evs[0] == ev))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LEffortAllEqual, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-11-16 22:19:24 +00:00
|
|
|
|
|
|
|
|
|
private void VerifyAwakenedValues(LegalityAnalysis data, IAwakened awakened)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
int sum = pkm.EVTotal;
|
|
|
|
|
if (sum != 0)
|
|
|
|
|
data.AddLine(GetInvalid(LEffortShouldBeZero));
|
|
|
|
|
|
|
|
|
|
if (!awakened.AwakeningAllValid())
|
|
|
|
|
data.AddLine(GetInvalid(LAwakenedCap));
|
2020-11-14 20:55:30 +00:00
|
|
|
|
|
|
|
|
|
var enc = data.EncounterMatch;
|
|
|
|
|
if (enc is EncounterSlot7GO && Enumerable.Range(0, 6).Select(awakened.GetAV).Any(z => z < 2))
|
2018-12-02 17:08:42 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LAwakenedShouldBeValue, 2))); // go park transfers have 2 AVs for all stats.
|
2020-11-14 20:55:30 +00:00
|
|
|
|
else if (awakened.AwakeningSum() == 0 && !enc.IsWithinRange(pkm))
|
2018-11-16 22:19:24 +00:00
|
|
|
|
data.AddLine(Get(LAwakenedEXPIncreased, Severity.Fishy));
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|