diff --git a/.gitignore b/.gitignore index 07b3f6db4..cedfb9207 100644 --- a/.gitignore +++ b/.gitignore @@ -227,38 +227,6 @@ $RECYCLE.BIN/ pingme.txt -############# -## Python -############# - -*.py[cod] -__pycache__/ - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg - ################# ## MonoDevelop ################# diff --git a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs index 7b6c61d50..1f4685279 100644 --- a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs @@ -1,3 +1,4 @@ +using System; using static PKHeX.Core.LegalityCheckStrings; namespace PKHeX.Core; @@ -25,10 +26,34 @@ public sealed class PIDVerifier : Verifier data.AddLine(Get(LPIDZero, Severity.Fishy)); if (!pk.Nature.IsFixed()) // out of range data.AddLine(GetInvalid(LPIDNatureMismatch)); + if (data.Info.EncounterMatch is EncounterEgg egg) + VerifyEggPID(data, pk, egg); VerifyShiny(data); } + private static void VerifyEggPID(LegalityAnalysis data, PKM pk, EncounterEgg egg) + { + if (egg.Generation is 4 && pk.EncryptionConstant == 0) + { + // Gen4 Eggs are "egg available" based on the stored PID value in the save file. + // If this value is 0 or is generated as 0 (possible), the game will see "false" and no egg is available. + // Only a non-zero value is possible to obtain. + data.AddLine(GetInvalid(LPIDEncryptZero, CheckIdentifier.EC)); + return; + } + + if (egg.Generation is 3 or 4 && Breeding.IsGenderSpeciesDetermination(egg.Species)) + { + var gender = pk.Gender; + if (!Breeding.IsValidSpeciesBit34(pk.EncryptionConstant, gender)) // 50/50 chance! + { + if (gender == 1 || IsEggBitRequiredMale34(data.Info.Moves)) + data.AddLine(GetInvalid(LPIDGenderMismatch, CheckIdentifier.EC)); + } + } + } + private void VerifyShiny(LegalityAnalysis data) { var pk = data.Entity; @@ -126,11 +151,6 @@ public sealed class PIDVerifier : Verifier // Gen3-5 => Gen6 have PID==EC with an edge case exception. if (Info.Generation is 3 or 4 or 5) { - if (Info.Generation is 3 or 4 && Info.EncounterMatch is EncounterEgg egg && Breeding.IsGenderSpeciesDetermination(egg.Species)) - { - if (!Breeding.IsValidSpeciesBit34(pk.EncryptionConstant, pk.Gender)) - data.AddLine(GetInvalid(LPIDGenderMismatch, CheckIdentifier.EC)); - } VerifyTransferEC(data); return; } @@ -214,4 +234,19 @@ public sealed class PIDVerifier : Verifier expect = (xorPID ? (ec ^ 0x80000000) : ec); return xorPID; } + + private static bool IsEggBitRequiredMale34(ReadOnlySpan moves) + { + // If female, it must match the correlation. + // If Ditto was used with a Male Nidoran / Volbeat, it'll always be that gender. + // If Ditto was not used and a Male was obtained, it must match the correlation. + // This not-Ditto scenario is detectable if the entity has any Inherited level up moves. + foreach (var move in moves) + { + // Egg Moves (passed via Male) are allowed. Check only for inherited level up moves. + if (move.Info.Method is LearnMethod.InheritLevelUp) + return true; + } + return false; + } } diff --git a/Tests/PKHeX.Core.Tests/Legality/Illegal/Gen3/0032 - NIDORAN♂ - 92A9F5C939C9 - edited issue4356.pk3 b/Tests/PKHeX.Core.Tests/Legality/Illegal/Gen3/0032 - NIDORAN♂ - 92A9F5C939C9 - edited issue4356.pk3 new file mode 100644 index 000000000..b53a66708 Binary files /dev/null and b/Tests/PKHeX.Core.Tests/Legality/Illegal/Gen3/0032 - NIDORAN♂ - 92A9F5C939C9 - edited issue4356.pk3 differ diff --git a/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - 92A9F5C9B9C9 - NidoranF parent issue4356.pk3 b/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - 92A9F5C9B9C9 - NidoranF parent issue4356.pk3 new file mode 100644 index 000000000..c49e267a2 Binary files /dev/null and b/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - 92A9F5C9B9C9 - NidoranF parent issue4356.pk3 differ diff --git a/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - F436F4EF3BFC - Ditto parent issue4356.pk3 b/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - F436F4EF3BFC - Ditto parent issue4356.pk3 new file mode 100644 index 000000000..e61e2949c Binary files /dev/null and b/Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - F436F4EF3BFC - Ditto parent issue4356.pk3 differ