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)
|
2017-05-29 22:21:39 +00:00
|
|
|
|
: new CheckResult(Severity.Invalid, V86, 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
|
|
|
|
{
|
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;
|
2017-11-15 16:36:09 +00:00
|
|
|
|
if (info.EncounterMatch.EggEncounter && species == 350 && pkm.Format >= 5 && !pkm.IsUntraded) // Prism Scale
|
2017-05-29 22:21:39 +00:00
|
|
|
|
return true;
|
2018-06-23 04:40:41 +00:00
|
|
|
|
|
|
|
|
|
if (EvolutionChain.GetEvoChainSpeciesIndex(info.EvoChainsAllGens[pkm.Format], pkm.Species) < 0)
|
|
|
|
|
return false; // Can't exist as current species
|
|
|
|
|
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
|
2017-06-07 03:10:05 +00:00
|
|
|
|
if (Legal.SpeciesEvolutionWithMove.Contains(pkm.Species))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return Legal.IsEvolutionValidWithMove(pkm, info);
|
2017-06-07 03:10:05 +00:00
|
|
|
|
return true;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|