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;
|
2021-01-02 22:47:39 +00:00
|
|
|
|
var enc = data.EncounterOriginal;
|
|
|
|
|
if (enc is MysteryGift gift)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2020-12-22 06:33:48 +00:00
|
|
|
|
case PGT {IsManaphyEgg: true} when pkm.Met_Level == 0:
|
2020-08-10 03:02:28 +00:00
|
|
|
|
break;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-01-02 22:47:39 +00:00
|
|
|
|
int elvl = enc.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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 22:47:39 +00:00
|
|
|
|
var reqEXP = enc is EncounterStatic {Version: GameVersion.C}
|
2018-07-29 01:09:29 +00:00
|
|
|
|
? 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));
|
2021-01-02 22:47:39 +00:00
|
|
|
|
else if (!enc.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;
|
2021-01-02 22:47:39 +00:00
|
|
|
|
var enc = data.EncounterMatch;
|
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
|
2021-01-02 22:47:39 +00:00
|
|
|
|
if (pkm.Format <= 2 && enc is not EncounterTrade && enc.Species == pkm.Species && GBRestrictions.Trade_Evolution1.Contains(enc.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)
|
|
|
|
|
{
|
2020-11-01 23:27:54 +00:00
|
|
|
|
// Context check is only applicable to gen1/2; transferring to Gen2 is a trade.
|
|
|
|
|
// Stadium 2 can transfer across game/generation boundaries without initiating a trade.
|
|
|
|
|
if (ParseSettings.ActiveTrainer.Generation >= 3 || ParseSettings.AllowGBCartEra)
|
|
|
|
|
return;
|
|
|
|
|
|
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;
|
2020-11-01 23:27:54 +00:00
|
|
|
|
|
|
|
|
|
// Pokemon have been traded but it is not evolved, trade evolutions are sequential dex numbers
|
2020-11-28 02:45:06 +00:00
|
|
|
|
var evolved = ParseSettings.SpeciesStrings[pkm.Species + 1];
|
|
|
|
|
var unevolved = ParseSettings.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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|