From a3fcb315309e31a094a0ded351dfa47a4de5d86c Mon Sep 17 00:00:00 2001 From: javierhimura Date: Mon, 27 Mar 2017 21:10:30 +0200 Subject: [PATCH 1/2] Fix issue #1001 Changed verifyEncounterG3Transfer, when both Egg Result and other Result happens Egg only overwrite if is the only valid encounter Corrections in verifyEncounterG3Transfer also adding code to check gen 3 WasEvent pokemon, but for now it will return Mistery Gift not found Changed verifyEncounterG3Transfer and verifyEncounterG4Transfer to return both message error for InvalidTransfer and G3/G4 invalid encounter if both errors happen at the same time Excluded fateful encounter pokemon from getWasEgg23, it can be WasEgg pokemon because FatefulEncounter from eggs is lost when hatch --- PKHeX/Legality/Checks.cs | 80 +++++++++++++++++++++++++--------------- PKHeX/Legality/Core.cs | 2 + PKHeX/PKM/PK4.cs | 2 +- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index af97f7cbc..7859e9d42 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -781,9 +781,11 @@ private CheckResult verifyEncounter() private CheckResult verifyEncounterG3Transfer() { + // WasEventEgg is not possible in gen 3 pal park pokemon, are indistinguible from normal eggs + bool wasEvent = pkm.WasEvent; CheckResult InvalidTransferResult = null; CheckResult EggResult = null; - CheckResult NonEggResult = null; + CheckResult G3Result = null; bool WasEgg = Legal.getWasEgg23(pkm) && !Legal.NoHatchFromEgg.Contains(pkm.Species); if (WasEgg) { @@ -792,54 +794,66 @@ private CheckResult verifyEncounterG3Transfer() if (pkm.IsEgg) return EggResult; } - + if (pkm.Format == 4 && pkm.Met_Location != 0x37) // Pal Park InvalidTransferResult = new CheckResult(Severity.Invalid, V60, CheckIdentifier.Encounter); if (pkm.Format != 4 && pkm.Met_Location != 30001) InvalidTransferResult = new CheckResult(Severity.Invalid, V61, CheckIdentifier.Encounter); - - // TODO: Include also gen 3 events + if (null != (EncounterMatch = Legal.getValidStaticEncounter(pkm))) { - NonEggResult = verifyEncounterStatic(); + G3Result = verifyEncounterStatic(); } - if (NonEggResult !=null) + if (G3Result !=null) { EncounterMatch = null; // Reset Encounter Object, test for remaining encounters if (null != (EncounterMatch = Legal.getValidWildEncounters(pkm))) - NonEggResult = verifyEncounterWild(); + G3Result = verifyEncounterWild(); if (null != (EncounterMatch = Legal.getValidIngameTrade(pkm))) - NonEggResult = verifyEncounterTrade(); + G3Result = verifyEncounterTrade(); } - // InvalidTransferResult have preference, because is invalid that from the current generation - if (InvalidTransferResult != null) - return InvalidTransferResult; + // Check events after static, to match Mew/Deoxys static encounters + if (wasEvent && G3Result == null && pkm.Species != 151 && pkm.Species != 386) + { + G3Result = verifyEncounterEvent() ?? new CheckResult(Severity.Invalid, V78, CheckIdentifier.Encounter); + } + + // Now check Mew and Deoxys, return only Event Result if a valid gen 3 event is found, if not return static encounter result + if (pkm.Species != 151 || pkm.Species != 386) + { + var EventResult = verifyEncounterEvent(); + if (EventResult?.Valid ?? false) + G3Result = EventResult; + } // Even if EggResult is not returned WasEgg is keep true to check in verifymoves first the // non egg encounter moves and after that egg encounter moves, because there is no way to tell // what of the two encounters was the real origin - if (EggResult != null && NonEggResult!=null) + if (EggResult != null && G3Result!=null) { - // InvalidTransferResult have preference, because is invalid data from the current generation - if (NonEggResult.Valid) - return NonEggResult; - if (EggResult.Valid) - return EggResult; - // if both are invalid returns non egg information, because + // keep the valid encounter, also if both are valid returns non egg information, because // there is more data in the pokemon to found normal encounter - return NonEggResult; + if (EggResult.Valid && !G3Result.Valid) + G3Result = EggResult; } - // No egg result then it can be from egg, no non egg result then return there is no valid encounter found - if (EggResult == null && NonEggResult == null) + // No gen 3 result + if (G3Result == null) { - return new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter); + // Return both errors, invalid transfer and not a valid encounter found in G3 + return InvalidTransferResult != null? + new CheckResult(Severity.Invalid, V80 + Environment.NewLine + InvalidTransferResult.Comment, CheckIdentifier.Encounter) + : new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter); } - return NonEggResult ?? InvalidTransferResult; + // If Gen 3 encounter is invalid and transfer also invalid return both errors + if (!G3Result.Valid && InvalidTransferResult != null) + return new CheckResult(Severity.Invalid, G3Result.Comment + Environment.NewLine + InvalidTransferResult.Comment, CheckIdentifier.Encounter); + + return InvalidTransferResult ?? G3Result; } private CheckResult verifyEncounterG4Transfer() { @@ -883,14 +897,20 @@ private CheckResult verifyEncounterG4Transfer() if (Gen4Result == null && null != (EncounterMatch = Legal.getValidIngameTrade(pkm))) Gen4Result = verifyEncounterTrade(); - if (Gen4Result != null && InvalidTransferResult != null) - return Gen4Result.Valid ? InvalidTransferResult : Gen4Result; - if (Gen4Result != null || InvalidTransferResult != null) - return Gen4Result ?? InvalidTransferResult; + if (Gen4Result == null) + Gen4Result = wasEvent + ? new CheckResult(Severity.Invalid, V78, CheckIdentifier.Encounter) + : new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter); - return wasEvent - ? new CheckResult(Severity.Invalid, V78, CheckIdentifier.Encounter) - : new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter); + if (InvalidTransferResult != null) + { + if (Gen4Result.Valid) + return InvalidTransferResult; + // If there is an error in G5 transfer and G4 encounter return both erros + return new CheckResult(Severity.Invalid, Gen4Result.Comment + Environment.NewLine + InvalidTransferResult.Comment, CheckIdentifier.Encounter); + } + + return Gen4Result; } private CheckResult verifyVCEncounter(int baseSpecies) { diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 387532c8b..bbf10a5a5 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -1163,6 +1163,8 @@ internal static bool getWasEgg23(PKM pkm) if(pkm.Format > 3 && pkm.Met_Level <5) return false; + if (pkm.Format > 3 && pkm.FatefulEncounter) + return false; return getEvolutionValid(pkm); } diff --git a/PKHeX/PKM/PK4.cs b/PKHeX/PKM/PK4.cs index 0b75e248d..db3d33f05 100644 --- a/PKHeX/PKM/PK4.cs +++ b/PKHeX/PKM/PK4.cs @@ -385,7 +385,7 @@ public override int Characteristic } // Legality Extensions public override bool WasEgg => GenNumber < 4 ? base.WasEgg : Egg_Location > 0; - public override bool WasEvent => Met_Location >= 3000 && Met_Location <= 3076 || FatefulEncounter && Species != 386; + public override bool WasEvent => Met_Location >= 3000 && Met_Location <= 3076 || FatefulEncounter; // Methods public override byte[] Encrypt() { From 56eaaf229973a2df3a997446b254fb045702b43b Mon Sep 17 00:00:00 2001 From: javierhimura Date: Mon, 27 Mar 2017 21:20:54 +0200 Subject: [PATCH 2/2] Mew and Deoxys correction --- PKHeX/Legality/Checks.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index 7859e9d42..80dd58cef 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -821,10 +821,11 @@ private CheckResult verifyEncounterG3Transfer() G3Result = verifyEncounterEvent() ?? new CheckResult(Severity.Invalid, V78, CheckIdentifier.Encounter); } - // Now check Mew and Deoxys, return only Event Result if a valid gen 3 event is found, if not return static encounter result - if (pkm.Species != 151 || pkm.Species != 386) + // Now check Mew and Deoxys, they can be event or static encounters both with fatefull encounter + if (pkm.Species == 151 || pkm.Species == 386) { var EventResult = verifyEncounterEvent(); + // Only return event if is valid, if not return result from static encounter if (EventResult?.Valid ?? false) G3Result = EventResult; }