2021-10-08 06:56:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-26 21:53:15 +00:00
|
|
|
|
var reqEXP = enc is EncounterStatic2Odd
|
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;
|
2022-03-05 17:12:43 +00:00
|
|
|
|
if (lvl >= 100)
|
|
|
|
|
{
|
|
|
|
|
var expect = Experience.GetEXP(100, pkm.PersonalInfo.EXPGrowth);
|
|
|
|
|
if (pkm.EXP != expect)
|
|
|
|
|
data.AddLine(GetInvalid(LLevelEXPTooHigh));
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (lvl < pkm.Met_Level)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LLevelMetBelow));
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
else if (!enc.IsWithinEncounterRange(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
|
|
|
|
}
|
|
|
|
|
|
2021-10-08 06:56:01 +00:00
|
|
|
|
if (IsTradeEvolutionRequired(data, enc))
|
|
|
|
|
{
|
|
|
|
|
// Pokemon has been traded illegally between games without evolving.
|
|
|
|
|
// Trade evolution species IDs for Gen1 are sequential dex numbers.
|
|
|
|
|
var species = enc.Species;
|
|
|
|
|
var evolved = ParseSettings.SpeciesStrings[species + 1];
|
|
|
|
|
var unevolved = ParseSettings.SpeciesStrings[species];
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved)));
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2021-10-08 06:56:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if a Gen1 trade evolution must have occurred.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static bool IsTradeEvolutionRequired(LegalityAnalysis data, IEncounterTemplate enc)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2021-10-08 06:56: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
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
var species = pkm.Species;
|
|
|
|
|
|
|
|
|
|
// This check is only applicable if it's a trade evolution that has not been evolved.
|
|
|
|
|
if (!GBRestrictions.Trade_Evolution1.Contains(enc.Species) || enc.Species != species)
|
|
|
|
|
return false;
|
|
|
|
|
|
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.
|
2021-10-08 06:56:01 +00:00
|
|
|
|
// Ignore this check if the environment's loaded trainer is not from Gen1/2 or is from GB Era.
|
2020-11-01 23:27:54 +00:00
|
|
|
|
if (ParseSettings.ActiveTrainer.Generation >= 3 || ParseSettings.AllowGBCartEra)
|
2021-10-08 06:56:01 +00:00
|
|
|
|
return false;
|
2020-11-01 23:27:54 +00:00
|
|
|
|
|
2021-10-08 06:56:01 +00:00
|
|
|
|
// Gen2 stuff can be traded between Gen2 games holding an Everstone, assuming it hasn't been transferred to Gen1 for special moves.
|
|
|
|
|
if (enc.Generation == 2)
|
2022-05-20 05:07:09 +00:00
|
|
|
|
return data.Info.Moves.Any(z => z.Generation != 2);
|
2021-10-08 06:56:01 +00:00
|
|
|
|
// Gen1 stuff can only be un-evolved if it was never traded from the OT.
|
|
|
|
|
if (data.Info.Moves.Any(z => z.Generation != 1))
|
|
|
|
|
return true; // traded to Gen2 for special moves
|
|
|
|
|
if (pkm.Format != 1)
|
|
|
|
|
return true; // traded to Gen2 (current state)
|
|
|
|
|
return !ParseSettings.IsFromActiveTrainer(pkm); // not with OT
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|