2017-06-07 03:52:21 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
2017-05-28 04:17:53 +00:00
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2017-07-30 19:31:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verify Evolution Information for a matched <see cref="IEncounterable"/>
|
|
|
|
|
/// </summary>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static class EvolutionVerifier
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-07-30 19:31:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies Evolution scenarios of an <see cref="IEncounterable"/> for an input <see cref="PKM"/> and relevant <see cref="LegalInfo"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkm">Source data to verify</param>
|
|
|
|
|
/// <param name="info">Source supporting information to verify with</param>
|
|
|
|
|
/// <returns></returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static CheckResult VerifyEvolution(PKM pkm, LegalInfo info)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2018-06-23 04:40:41 +00:00
|
|
|
|
return IsValidEvolution(pkm, info)
|
2018-05-12 15:13:39 +00:00
|
|
|
|
? new CheckResult(CheckIdentifier.Evolution)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
: new CheckResult(Severity.Invalid, LEvoInvalid, CheckIdentifier.Evolution);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-07-30 19:31:17 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the Evolution from the source <see cref="IEncounterable"/> is valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkm">Source data to verify</param>
|
|
|
|
|
/// <param name="info">Source supporting information to verify with</param>
|
|
|
|
|
/// <returns>Evolution is valid or not</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool IsValidEvolution(PKM pkm, LegalInfo info)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2018-07-19 23:42:45 +00:00
|
|
|
|
if (info.EvoChainsAllGens[pkm.Format].Count == 0)
|
|
|
|
|
return false; // Can't exist as current species
|
2019-09-10 07:21:51 +00:00
|
|
|
|
|
2017-05-29 22:21:39 +00:00
|
|
|
|
int species = pkm.Species;
|
2017-06-07 03:10:05 +00:00
|
|
|
|
if (info.EncounterMatch.Species == species)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
return true;
|
2019-12-09 01:39:19 +00:00
|
|
|
|
if (info.EncounterMatch.EggEncounter && species == (int)Species.Milotic && pkm.Format >= 5 && !pkm.IsUntraded) // Prism Scale
|
2017-05-29 22:21:39 +00:00
|
|
|
|
return true;
|
2019-12-28 03:17:08 +00:00
|
|
|
|
if (species == (int)Species.Vespiquen && info.Generation < 6 && (pkm.PID & 0xFF) >= 0x1F) // Combee->Vespiquen Invalid Evolution
|
2019-12-22 00:52:56 +00:00
|
|
|
|
return false;
|
2018-06-23 04:40:41 +00:00
|
|
|
|
|
|
|
|
|
if (info.Generation > 0 && info.EvoChainsAllGens[info.Generation].All(z => z.Species != info.EncounterMatch.Species))
|
|
|
|
|
return false; // Can't exist as origin species
|
|
|
|
|
|
2017-06-07 03:10:05 +00:00
|
|
|
|
// If current species evolved with a move evolution and encounter species is not current species check if the evolution by move is valid
|
2017-06-18 01:37:19 +00:00
|
|
|
|
// Only the evolution by move is checked, if there is another evolution before the evolution by move is covered in IsEvolutionValid
|
2020-11-02 21:11:51 +00:00
|
|
|
|
if (EvolutionRestrictions.SpeciesEvolutionWithMove.Contains(species))
|
|
|
|
|
return EvolutionRestrictions.IsEvolutionValidWithMove(pkm, info);
|
2019-09-10 07:21:51 +00:00
|
|
|
|
|
2017-06-07 03:10:05 +00:00
|
|
|
|
return true;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|