2020-09-06 17:53:13 +00:00
|
|
|
|
using System.Collections.Generic;
|
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.Ability"/> values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AbilityVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Ability;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
{
|
|
|
|
|
var result = VerifyAbility(data);
|
|
|
|
|
data.AddLine(result);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-01 21:11:12 +00:00
|
|
|
|
private CheckResult VALID => GetValid(LAbilityFlag);
|
|
|
|
|
private CheckResult INVALID => GetInvalid(LAbilityMismatch);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
private enum AbilityState : byte
|
|
|
|
|
{
|
|
|
|
|
CanMismatch,
|
|
|
|
|
MustMatch,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CheckResult VerifyAbility(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-09-06 17:53:13 +00:00
|
|
|
|
var pi = data.PersonalInfo;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// Check ability is possible (within bounds)
|
|
|
|
|
int ability = pkm.Ability;
|
2020-09-06 17:53:13 +00:00
|
|
|
|
int abilval = pi.GetAbilityIndex(ability);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (abilval < 0)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityUnexpected);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2020-09-19 14:52:50 +00:00
|
|
|
|
var abilities = pi.Abilities;
|
2020-10-10 19:30:57 +00:00
|
|
|
|
int format = pkm.Format;
|
|
|
|
|
if (format >= 6)
|
|
|
|
|
{
|
|
|
|
|
// Check AbilityNumber is a single set bit
|
|
|
|
|
var num = pkm.AbilityNumber;
|
|
|
|
|
if (!(num != 0 && (num & (num - 1)) == 0)) // not [!zero, and power of 2]
|
|
|
|
|
return GetInvalid(LAbilityMismatchFlag);
|
|
|
|
|
|
|
|
|
|
// Check AbilityNumber points to ability
|
|
|
|
|
int an = num >> 1;
|
|
|
|
|
if (an >= abilities.Count || abilities[an] != ability)
|
|
|
|
|
return GetInvalid(LAbilityMismatchFlag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (format >= 8) // Ability Patch
|
|
|
|
|
{
|
2020-11-04 02:48:29 +00:00
|
|
|
|
if (pkm.AbilityNumber == 4 && CanAbilityPatch(format, abilities, pkm.Species))
|
2020-10-10 19:30:57 +00:00
|
|
|
|
return GetValid(LAbilityPatchUsed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var enc = data.EncounterMatch;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (enc is MysteryGift g && g.Format >= 4)
|
|
|
|
|
return VerifyAbilityMG(data, g, abilities);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2020-10-10 19:30:57 +00:00
|
|
|
|
if (format < 6)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
return VerifyAbility345(data, enc, abilities, abilval);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return VerifyAbility(data, abilities, abilval);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
private CheckResult VerifyAbility(LegalityAnalysis data, IReadOnlyList<int> abilities, int abilnum)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
var enc = data.EncounterMatch;
|
|
|
|
|
var eabil = GetEncounterFixedAbilityNumber(enc);
|
2018-10-10 23:31:40 +00:00
|
|
|
|
if (eabil >= 0)
|
|
|
|
|
{
|
|
|
|
|
if ((data.pkm.AbilityNumber == 4) != (eabil == 4))
|
|
|
|
|
return GetInvalid(LAbilityHiddenFail);
|
|
|
|
|
if (eabil > 0)
|
|
|
|
|
return VerifyFixedAbility(data, abilities, AbilityState.CanMismatch, eabil, abilnum);
|
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
var gen = data.Info.Generation;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return gen switch
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
5 => VerifyAbility5(data, enc, abilities),
|
|
|
|
|
6 => VerifyAbility6(data, enc),
|
|
|
|
|
7 => VerifyAbility7(data, enc),
|
|
|
|
|
8 => VerifyAbility8(data, enc),
|
2019-10-08 01:40:09 +00:00
|
|
|
|
_ => CheckMatch(data.pkm, abilities, gen, AbilityState.CanMismatch)
|
|
|
|
|
};
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbility345(LegalityAnalysis data, IEncounterable enc, IReadOnlyList<int> abilities, int abilnum)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-10-19 18:36:57 +00:00
|
|
|
|
int format = pkm.Format;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
var state = AbilityState.MustMatch;
|
2020-10-19 18:36:57 +00:00
|
|
|
|
if (3 <= format && format <= 5 && abilities[0] != abilities[1]) // 3-4/5 and have 2 distinct abilities now
|
2018-07-03 03:34:41 +00:00
|
|
|
|
state = VerifyAbilityPreCapsule(data, abilities);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
var EncounterMatch = data.EncounterMatch;
|
|
|
|
|
int eabil = GetEncounterFixedAbilityNumber(EncounterMatch);
|
2018-10-10 23:31:40 +00:00
|
|
|
|
if (eabil >= 0)
|
|
|
|
|
{
|
2020-10-19 18:36:57 +00:00
|
|
|
|
if ((pkm.AbilityNumber == 4) != (eabil == 4))
|
2018-10-10 23:31:40 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenFail);
|
|
|
|
|
if (eabil > 0)
|
|
|
|
|
return VerifyFixedAbility(data, abilities, state, eabil, abilnum);
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
int gen = data.Info.Generation;
|
|
|
|
|
if (gen == 5)
|
2020-08-30 17:23:22 +00:00
|
|
|
|
return VerifyAbility5(data, enc, abilities);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return CheckMatch(pkm, abilities, gen, state);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
private CheckResult VerifyFixedAbility(LegalityAnalysis data, IReadOnlyList<int> abilities, AbilityState state, int EncounterAbility, int abilval)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-07-03 03:34:41 +00:00
|
|
|
|
var pkm = data.pkm;
|
2020-05-17 19:32:28 +00:00
|
|
|
|
if (data.Info.EncounterMatch.Generation >= 6)
|
2018-10-06 18:24:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (IsAbilityCapsuleModified(pkm, abilities, EncounterAbility))
|
|
|
|
|
return GetValid(LAbilityCapsuleUsed);
|
|
|
|
|
if (pkm.AbilityNumber != EncounterAbility)
|
|
|
|
|
return INVALID;
|
|
|
|
|
return VALID;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if ((pkm.AbilityNumber == 4) != (EncounterAbility == 4))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenFail);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
2018-07-16 23:12:19 +00:00
|
|
|
|
if (data.EncounterMatch.Species != pkm.Species && state != AbilityState.CanMismatch) // evolved
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return CheckMatch(pkm, abilities, data.Info.Generation, AbilityState.MustMatch);
|
|
|
|
|
|
|
|
|
|
if (EncounterAbility == 1 << abilval)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetValid(LAbilityFlag);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.AbilityNumber == EncounterAbility)
|
|
|
|
|
return VALID;
|
|
|
|
|
|
|
|
|
|
if (state == AbilityState.CanMismatch || EncounterAbility == 0)
|
|
|
|
|
return CheckMatch(pkm, abilities, data.Info.Generation, AbilityState.MustMatch);
|
|
|
|
|
|
|
|
|
|
if (IsAbilityCapsuleModified(pkm, abilities, EncounterAbility))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetValid(LAbilityCapsuleUsed);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return INVALID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
private AbilityState VerifyAbilityPreCapsule(LegalityAnalysis data, IReadOnlyList<int> abilities)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// CXD pokemon can have any ability without matching PID
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.Version == (int)GameVersion.CXD && pkm.Format == 3)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return AbilityState.CanMismatch;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// Gen3 native or Gen4/5 origin
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.Format == 3 || !pkm.InhabitedGeneration(3))
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return AbilityState.MustMatch;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// Evovled in Gen4/5
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.Species > Legal.MaxSpeciesID_3)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return AbilityState.MustMatch;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// If the species could not exist in Gen3, must match.
|
|
|
|
|
if (data.Info.EvoChainsAllGens[3].Count == 0)
|
|
|
|
|
return AbilityState.MustMatch;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
// Fall through when gen3 pkm transferred to gen4/5
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return VerifyAbilityGen3Transfer(data, abilities, data.Info.EvoChainsAllGens[3][0].Species);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
private AbilityState VerifyAbilityGen3Transfer(LegalityAnalysis data, IReadOnlyList<int> abilities, int maxGen3Species)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
var pers = (PersonalInfoG3)PersonalTable.E[maxGen3Species];
|
|
|
|
|
if (pers.Ability1 != pers.Ability2) // Excluding Colosseum/XD, a Gen3 pkm must match PID if it has 2 unique abilities
|
|
|
|
|
return pkm.Version == (int) GameVersion.CXD ? AbilityState.CanMismatch : AbilityState.MustMatch;
|
|
|
|
|
|
|
|
|
|
if (pkm.Species != maxGen3Species) // it has evolved in either gen 4 or gen 5; the ability must match PID
|
|
|
|
|
return AbilityState.MustMatch;
|
|
|
|
|
|
|
|
|
|
var chain = data.Info.EvoChainsAllGens;
|
|
|
|
|
bool evolved45 = chain[4].Count > 1 || (pkm.Format == 5 && chain[5].Count > 1);
|
|
|
|
|
if (evolved45)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if (pkm.Ability == pers.Ability1) // Could evolve in Gen4/5 and have a Gen3 only ability
|
|
|
|
|
return AbilityState.CanMismatch; // Not evolved in Gen4/5, doesn't need to match PIDAbility
|
|
|
|
|
|
|
|
|
|
if (pkm.Ability == abilities[1]) // It could evolve in Gen4/5 and have Gen4 second ability
|
|
|
|
|
return AbilityState.MustMatch; // Evolved in Gen4/5, must match PIDAbility
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
// If we reach here, it has not evolved in Gen4/5 games or has an invalid ability.
|
|
|
|
|
// The ability does not need to match the PIDAbility, but only Gen3 ability is allowed.
|
|
|
|
|
if (pkm.Ability != pers.Ability1) // Not evolved in Gen4/5, but doesn't have Gen3 only ability
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LAbilityMismatch3)); // probably bad to do this here
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return AbilityState.CanMismatch;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbilityMG(LegalityAnalysis data, MysteryGift g, IReadOnlyList<int> abilities)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (g is PCD d)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return VerifyAbilityPCD(data, abilities, d);
|
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var pkm = data.pkm;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (g is PGT) // Ranger Manaphy
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return (pkm.Format >= 6 ? (pkm.AbilityNumber == 1) : (pkm.AbilityNumber < 4)) ? VALID : GetInvalid(LAbilityMismatchGift);
|
2018-07-10 00:33:31 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
var cardType = g.AbilityType;
|
|
|
|
|
if (cardType == 4) // 1/2/H
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return VALID;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
int abilNumber = pkm.AbilityNumber;
|
|
|
|
|
if (cardType == 3) // 1/2
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return abilNumber == 4 ? GetInvalid(LAbilityMismatchGift) : VALID;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
2018-07-10 00:08:26 +00:00
|
|
|
|
// Only remaining matches are fixed index abilities
|
2020-08-30 17:23:22 +00:00
|
|
|
|
int cardAbilIndex = 1 << cardType;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if (abilNumber == cardAbilIndex)
|
|
|
|
|
return VALID;
|
|
|
|
|
|
2018-07-10 00:08:26 +00:00
|
|
|
|
// Can still match if the ability was changed via ability capsule...
|
|
|
|
|
// However, it can't change to/from Hidden Abilities.
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (abilNumber == 4 || cardType == 2)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenFail);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
// Ability can be flipped 0/1 if Ability Capsule is available, is not Hidden Ability, and Abilities are different.
|
|
|
|
|
if (pkm.Format >= 6 && abilities[0] != abilities[1])
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetValid(LAbilityCapsuleUsed);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(pkm.Format < 6 ? LAbilityMismatchPID : LAbilityMismatchFlag);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
private CheckResult VerifyAbilityPCD(LegalityAnalysis data, IReadOnlyList<int> abilities, PCD pcd)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-10-10 19:30:57 +00:00
|
|
|
|
var format = pkm.Format;
|
|
|
|
|
if (format >= 6)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-10-10 19:30:57 +00:00
|
|
|
|
if (CanAbilityCapsule(format, abilities))
|
2018-07-03 03:34:41 +00:00
|
|
|
|
{
|
|
|
|
|
// Gen3-5 transfer with same ability -> 1st ability that matches
|
|
|
|
|
if (pkm.AbilityNumber == 1)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetValid(LAbilityFlag);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
return CheckMatch(pkm, abilities, 4, AbilityState.MustMatch); // evolved, must match
|
|
|
|
|
}
|
|
|
|
|
if (pkm.AbilityNumber < 4) // Ability Capsule can change between 1/2
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetValid(LAbilityCapsuleUsed);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pcd.Species != pkm.Species)
|
|
|
|
|
return CheckMatch(pkm, abilities, 4, AbilityState.MustMatch); // evolved, must match
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
// Edge case (PID ability gift mismatch) -- must match gift ability.
|
|
|
|
|
return pkm.Ability == pcd.Gift.PK.Ability ? VALID : INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbility5(LegalityAnalysis data, IEncounterable enc, IReadOnlyList<int> abilities)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
switch (enc)
|
2018-07-03 03:34:41 +00:00
|
|
|
|
{
|
2018-06-24 05:00:01 +00:00
|
|
|
|
case EncounterSlot w:
|
|
|
|
|
// Hidden Abilities for Wild Encounters are only available at a Hidden Grotto
|
2020-08-30 17:23:22 +00:00
|
|
|
|
bool grotto = w.Area.Type == SlotType.HiddenGrotto;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (pkm.AbilityNumber == 4 ^ grotto)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(grotto ? LAbilityMismatchGrotto : LAbilityHiddenFail);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EncounterEgg e when pkm.AbilityNumber == 4:
|
2018-07-17 04:53:46 +00:00
|
|
|
|
// Hidden Abilities for some are unbreedable or unreleased
|
|
|
|
|
if (Legal.Ban_BreedHidden5.Contains(e.Species))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
var state = pkm.Format == 5 ? AbilityState.MustMatch : AbilityState.CanMismatch;
|
|
|
|
|
return CheckMatch(data.pkm, abilities, 5, state);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbility6(LegalityAnalysis data, IEncounterable enc)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-07-04 01:43:11 +00:00
|
|
|
|
if (pkm.AbilityNumber != 4)
|
|
|
|
|
return VALID;
|
|
|
|
|
|
|
|
|
|
// hidden abilities
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (enc is EncounterSlot slot)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
bool valid = (slot is EncounterSlot6AO ao && ao.CanDexNav) || slot.Area.Type == SlotType.FriendSafari || slot.Area.Type == SlotType.Horde;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (!valid)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityMismatchHordeSafari);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-04 01:43:11 +00:00
|
|
|
|
if (Legal.Ban_NoHidden6.Contains(pkm.SpecForm))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return VALID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbility7(LegalityAnalysis data, IEncounterable enc)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (enc is EncounterSlot slot && pkm.AbilityNumber == 4)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2020-08-30 17:23:22 +00:00
|
|
|
|
bool valid = slot.Area.Type == SlotType.SOS;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (!valid)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityMismatchSOS);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if (Legal.Ban_NoHidden7.Contains(pkm.SpecForm) && pkm.AbilityNumber == 4)
|
2019-09-23 23:56:47 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
|
|
|
|
|
|
|
|
|
return VALID;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 17:23:22 +00:00
|
|
|
|
private CheckResult VerifyAbility8(LegalityAnalysis data, IEncounterable enc)
|
2019-09-23 23:56:47 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2020-08-30 17:23:22 +00:00
|
|
|
|
if (enc is EncounterSlot && pkm.AbilityNumber == 4)
|
2019-09-23 23:56:47 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
|
|
|
|
if (Legal.Ban_NoHidden8.Contains(pkm.SpecForm) && pkm.AbilityNumber == 4)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return VALID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Final checks assuming nothing else has flagged the ability.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkm">Pokémon</param>
|
|
|
|
|
/// <param name="abilities">Current abilities</param>
|
|
|
|
|
/// <param name="gen">Generation</param>
|
|
|
|
|
/// <param name="state">Permissive to allow ability to deviate under special circumstances</param>
|
|
|
|
|
private CheckResult CheckMatch(PKM pkm, IReadOnlyList<int> abilities, int gen, AbilityState state)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if (3 <= gen && gen <= 4 && pkm.AbilityNumber == 4)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LAbilityHiddenUnavailable);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
// other cases of hidden ability already flagged, all that is left is 1/2 mismatching
|
2020-10-19 18:36:57 +00:00
|
|
|
|
if (state != AbilityState.MustMatch)
|
|
|
|
|
return VALID;
|
|
|
|
|
|
|
|
|
|
// Check that the ability bit is correct.
|
|
|
|
|
if (pkm is G3PKM g3)
|
|
|
|
|
{
|
|
|
|
|
var abit = g3.AbilityBit;
|
|
|
|
|
if (abilities[0] == abilities[1]) // Not a dual ability
|
|
|
|
|
{
|
|
|
|
|
// Must not have the Ability bit flag set.
|
|
|
|
|
if (abit)
|
|
|
|
|
return GetInvalid(LAbilityMismatchFlag, CheckIdentifier.PID);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Gen3 mainline origin sets the Ability index based on the PID, but only if it has two abilities.
|
|
|
|
|
// Version value check isn't factually correct, but there are no C/XD gifts with (Version!=15) that have two abilities.
|
|
|
|
|
// Pikachu, Celebi, Ho-Oh
|
|
|
|
|
if (pkm.Version != (int)GameVersion.CXD && abit != ((pkm.PID & 1) == 1))
|
|
|
|
|
return GetInvalid(LAbilityMismatchPID, CheckIdentifier.PID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (pkm.Format >= 6)
|
|
|
|
|
{
|
|
|
|
|
// 6+ already checked at the top of the verifier call stack
|
|
|
|
|
return VALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3-5
|
|
|
|
|
var abil = abilities[pkm.AbilityNumber >> 1];
|
|
|
|
|
if (abil != pkm.Ability)
|
|
|
|
|
return GetInvalid(LAbilityMismatchPID);
|
2018-07-03 03:34:41 +00:00
|
|
|
|
|
|
|
|
|
return VALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ability Capsule can change between 1/2
|
|
|
|
|
private static bool IsAbilityCapsuleModified(PKM pkm, IReadOnlyList<int> abilities, int EncounterAbility)
|
|
|
|
|
{
|
2020-10-10 19:30:57 +00:00
|
|
|
|
if (!CanAbilityCapsule(pkm.Format, abilities))
|
|
|
|
|
return false;
|
2018-07-03 03:34:41 +00:00
|
|
|
|
if (pkm.AbilityNumber == 4)
|
|
|
|
|
return false; // Cannot alter to hidden ability.
|
|
|
|
|
if (EncounterAbility == 4)
|
|
|
|
|
return false; // Cannot alter from hidden ability.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-10-10 19:30:57 +00:00
|
|
|
|
private static bool CanAbilityCapsule(int format, IReadOnlyList<int> abilities)
|
|
|
|
|
{
|
|
|
|
|
if (format < 6) // Ability Capsule does not exist
|
|
|
|
|
return false;
|
|
|
|
|
return abilities[0] != abilities[1]; // Cannot alter ability index if it is the same as the other ability.
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 02:48:29 +00:00
|
|
|
|
public static bool CanAbilityPatch(int format, IReadOnlyList<int> abilities, int species)
|
2020-10-10 19:30:57 +00:00
|
|
|
|
{
|
|
|
|
|
if (format < 8) // Ability Patch does not exist
|
|
|
|
|
return false;
|
2020-11-04 02:48:29 +00:00
|
|
|
|
|
|
|
|
|
// Can alter ability index if it is different from the other abilities.
|
2020-10-10 19:30:57 +00:00
|
|
|
|
var h = abilities[2];
|
2020-11-04 02:48:29 +00:00
|
|
|
|
if (h != abilities[0] || h != abilities[1])
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Some species have a distinct hidden ability only on another form, and can change between that form and its current form.
|
|
|
|
|
switch (species)
|
|
|
|
|
{
|
|
|
|
|
case (int)Species.Giratina:
|
|
|
|
|
case (int)Species.Tornadus:
|
|
|
|
|
case (int)Species.Thundurus:
|
|
|
|
|
case (int)Species.Landorus:
|
|
|
|
|
return true; // Form-0 is a/a/h
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2020-10-10 19:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 03:34:41 +00:00
|
|
|
|
private static int GetEncounterFixedAbilityNumber(IEncounterable enc)
|
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return enc switch
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
EncounterStatic s => s.Ability,
|
|
|
|
|
EncounterTrade t => t.Ability,
|
|
|
|
|
_ => -1
|
|
|
|
|
};
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|