2018-06-24 05:00:01 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.CurrentLevel"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class LevelVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Level;
|
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-08-02 03:39:20 +00:00
|
|
|
|
var EncounterMatch = data.EncounterOriginal;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (EncounterMatch is MysteryGift gift)
|
|
|
|
|
{
|
|
|
|
|
if (gift.Level != pkm.Met_Level && pkm.HasOriginalMetLocation)
|
|
|
|
|
{
|
|
|
|
|
switch (gift)
|
|
|
|
|
{
|
|
|
|
|
case WC3 wc3 when wc3.Met_Level == pkm.Met_Level || wc3.IsEgg:
|
|
|
|
|
break;
|
|
|
|
|
case WC7 wc7 when wc7.MetLevel == pkm.Met_Level:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LLevelMetGift));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (gift.Level > pkm.CurrentLevel)
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LLevelMetGiftFail));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
{
|
2020-07-13 01:58:07 +00:00
|
|
|
|
int elvl = EncounterMatch.LevelMin;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (elvl != pkm.CurrentLevel)
|
2018-07-29 01:09:29 +00:00
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, elvl)));
|
2018-07-29 01:09:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var reqEXP = EncounterMatch is EncounterStatic s && s.Version == GameVersion.C
|
|
|
|
|
? 125 // Gen2 Dizzy Punch gifts always have 125 EXP, even if it's more than the Lv5 exp required.
|
2019-11-16 01:34:18 +00:00
|
|
|
|
: Experience.GetEXP(elvl, pkm.PersonalInfo.EXPGrowth);
|
2018-07-29 01:09:29 +00:00
|
|
|
|
if (reqEXP != pkm.EXP)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEggEXP));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lvl = pkm.CurrentLevel;
|
|
|
|
|
if (lvl < pkm.Met_Level)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LLevelMetBelow));
|
2019-11-16 01:34:18 +00:00
|
|
|
|
else if (!EncounterMatch.IsWithinRange(pkm) && lvl != 100 && pkm.EXP == Experience.GetEXP(lvl, pkm.PersonalInfo.EXPGrowth))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LLevelEXPThreshold, Severity.Fishy));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetValid(LLevelMetSane));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public void VerifyG1(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-08-02 03:39:20 +00:00
|
|
|
|
var EncounterMatch = data.EncounterOriginal;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
{
|
2020-07-13 01:58:07 +00:00
|
|
|
|
const int elvl = 5;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (elvl != pkm.CurrentLevel)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, elvl)));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pkm.Met_Location != 0) // crystal
|
|
|
|
|
{
|
|
|
|
|
int lvl = pkm.CurrentLevel;
|
|
|
|
|
if (lvl < pkm.Met_Level)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LLevelMetBelow));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// There is no way to prevent a gen1 trade evolution as held items (everstone) did not exist.
|
|
|
|
|
// Machoke, Graveler, Haunter and Kadabra captured in the second phase evolution, excluding in-game trades, are already checked
|
2018-10-10 23:32:02 +00:00
|
|
|
|
if (pkm.Format <= 2 && !(EncounterMatch is EncounterTrade) && EncounterMatch.Species == pkm.Species && GBRestrictions.Trade_Evolution1.Contains(EncounterMatch.Species))
|
2018-06-24 05:00:01 +00:00
|
|
|
|
VerifyG1TradeEvo(data);
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
private void VerifyG1TradeEvo(LegalityAnalysis data)
|
|
|
|
|
{
|
2019-01-09 16:52:56 +00:00
|
|
|
|
if (ParseSettings.ActiveTrainer.Generation >= 3)
|
|
|
|
|
return; // context check is only applicable to gen1/2; transferring to gen2 is a trade.
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var pkm = data.pkm;
|
2018-10-10 04:07:13 +00:00
|
|
|
|
var mustevolve = pkm.TradebackStatus == TradebackType.WasTradeback || (pkm.Format == 1 && !ParseSettings.IsFromActiveTrainer(pkm)) || GBRestrictions.IsTradedKadabraG1(pkm);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (!mustevolve)
|
|
|
|
|
return;
|
|
|
|
|
// Pokemon have been traded but it is not evolved, trade evos are sequential dex numbers
|
|
|
|
|
var evolved = LegalityAnalysis.SpeciesStrings[pkm.Species + 1];
|
2019-01-12 01:44:51 +00:00
|
|
|
|
var unevolved = LegalityAnalysis.SpeciesStrings[pkm.Species];
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved)));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|