From 617914b257377ad44622c5abd89e11be24bfb51d Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 5 Sep 2024 23:55:46 -0500 Subject: [PATCH] Allow some nidoran/volbeat to mismatch correlation https://github.com/kwsch/PKHeX/issues/4356#issuecomment-2333031493 fix flow so it is called in format3+ Closes #4356 ty @abcboy101 add another check for EC=0 eggs from Gen4 -- game uses the PID value as the "is egg available" flag, so can't obtain a 0-pid egg from gen4! remove python paths from gitignore, so I can call one of the test folders `Eggs` --- .gitignore | 32 ------------- PKHeX.Core/Legality/Verifiers/PIDVerifier.cs | 45 ++++++++++++++++-- ...N♂ - 92A9F5C939C9 - edited issue4356.pk3 | Bin 0 -> 100 bytes ...A9F5C9B9C9 - NidoranF parent issue4356.pk3 | Bin 0 -> 100 bytes ... F436F4EF3BFC - Ditto parent issue4356.pk3 | Bin 0 -> 100 bytes 5 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 Tests/PKHeX.Core.Tests/Legality/Illegal/Gen3/0032 - NIDORAN♂ - 92A9F5C939C9 - edited issue4356.pk3 create mode 100644 Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - 92A9F5C9B9C9 - NidoranF parent issue4356.pk3 create mode 100644 Tests/PKHeX.Core.Tests/Legality/Legal/Generation 3/Eggs/0032 - NIDORAN♂ - F436F4EF3BFC - Ditto parent issue4356.pk3 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 0000000000000000000000000000000000000000..b53a66708f0625f4a51d95db31607582e177c278 GIT binary patch literal 100 zcmX?UdGc#O%fGh?`Q87&cx$K@`7yE`-+lQ%5HPHq#K54yz`)QB#0pl4 hjLLG#A|N3+P-s}lV!0{|#%E;^210HIPB7+V005KF7EJ&E literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c49e267a2802c1ebd68b7aed428a069f0210b32e GIT binary patch literal 100 zcmX@P^W@inmVa*(^1J_k@zzi+@?&H>zWefjAYfQIiGe|Zfq|hNh#7bp7#tWR7&I98 f7?tIeML