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;
|
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 (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
|
2019-09-10 07:21:51 +00:00
|
|
|
|
if (Legal.SpeciesEvolutionWithMove.Contains(species))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return Legal.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
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
|
|
|
|
public static bool IsEvolvedChangedFormValid(int species, int currentForm, int originalForm)
|
|
|
|
|
{
|
|
|
|
|
switch (currentForm)
|
|
|
|
|
{
|
|
|
|
|
case 0 when Legal.GalarForm0Evolutions.TryGetValue(species, out var val):
|
|
|
|
|
return originalForm == val;
|
|
|
|
|
case 1 when Legal.AlolanVariantEvolutions12.Contains(species):
|
|
|
|
|
case 1 when Legal.GalarVariantFormEvolutions.Contains(species):
|
|
|
|
|
return originalForm == 0;
|
|
|
|
|
case 2 when species == (int)Species.Darmanitan:
|
|
|
|
|
return originalForm == 1;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|