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.Gender"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class GenderVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Gender;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
var pi = pkm.PersonalInfo;
|
|
|
|
|
if (pi.Genderless != (pkm.Gender == 2))
|
|
|
|
|
{
|
|
|
|
|
// DP/HGSS shedinja glitch -- only generation 4 spawns
|
|
|
|
|
bool ignore = pkm.Format == 4 && pkm.Species == 292 && pkm.Met_Level != pkm.CurrentLevel;
|
|
|
|
|
if (!ignore)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LGenderInvalidNone));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for PID relationship to Gender & Nature if applicable
|
|
|
|
|
int gen = data.Info.Generation;
|
|
|
|
|
|
|
|
|
|
if (3 <= gen && gen <= 5)
|
|
|
|
|
{
|
|
|
|
|
// Gender-PID & Nature-PID relationship check
|
2018-09-01 21:11:12 +00:00
|
|
|
|
var result = IsValidGenderPID(data) ? GetValid(LPIDGenderMatch) : GetInvalid(LPIDGenderMismatch);
|
2018-07-22 19:00:03 +00:00
|
|
|
|
data.AddLine(result);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
if (gen != 5)
|
|
|
|
|
VerifyNaturePID(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check fixed gender cases
|
|
|
|
|
if ((pi.OnlyFemale && pkm.Gender != 1) || (pi.OnlyMale && pkm.Gender != 0))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LGenderInvalidNone));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 19:00:03 +00:00
|
|
|
|
private static void VerifyNaturePID(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
var result = pkm.EncryptionConstant % 25 == pkm.Nature
|
2018-09-01 21:11:12 +00:00
|
|
|
|
? GetValid(LPIDNatureMatch, CheckIdentifier.Nature)
|
|
|
|
|
: GetInvalid(LPIDNatureMismatch, CheckIdentifier.Nature);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
data.AddLine(result);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 19:00:03 +00:00
|
|
|
|
private static bool IsValidGenderPID(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
bool genderValid = pkm.IsGenderValid();
|
|
|
|
|
if (!genderValid)
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return IsValidGenderMismatch(pkm);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
// check for mixed->fixed gender incompatibility by checking the gender of the original species
|
2018-06-30 22:01:16 +00:00
|
|
|
|
int original = data.EncounterMatch.Species;
|
|
|
|
|
if (Legal.FixedGenderFromBiGender.Contains(original))
|
|
|
|
|
return IsValidFixedGenderFromBiGender(pkm, original);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsValidFixedGenderFromBiGender(PKM pkm, int original)
|
|
|
|
|
{
|
|
|
|
|
var current = pkm.Gender;
|
|
|
|
|
if (current == 2) // shedinja, genderless
|
|
|
|
|
return true;
|
|
|
|
|
var gender = PKX.GetGenderFromPID(original, pkm.EncryptionConstant);
|
|
|
|
|
return gender == current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsValidGenderMismatch(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
switch (pkm.Species)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Shedinja when pkm.Format == 4: // Shedinja evolution gender glitch, should match original Gender
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return pkm.Gender == PKX.GetGenderFromPIDAndRatio(pkm.EncryptionConstant, 0x7F); // 50M-50F
|
|
|
|
|
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Marill when pkm.Format >= 6:
|
|
|
|
|
case (int)Species.Azumarill when pkm.Format >= 6: // evolved from azurill after transferring to keep gender
|
2018-06-30 22:01:16 +00:00
|
|
|
|
return pkm.Gender == 1 && (pkm.EncryptionConstant & 0xFF) > 0x3F;
|
|
|
|
|
|
|
|
|
|
default: return false;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|