diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index 773228603..2cf4ba21f 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -121,7 +121,8 @@ namespace PKHeX.Core pkm = pk; if (!pkm.IsOriginValid) { AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; } - + + verifyPreRelearn(); updateEncounterChain(); updateMoveLegality(); updateEncounterInfo(); @@ -133,7 +134,8 @@ namespace PKHeX.Core pkm = pk; if (!pkm.IsOriginValid) { AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; } - + + verifyPreRelearn(); updateEncounterChain(); updateMoveLegality(); updateEncounterInfo(); diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index 87da39a66..32a86c271 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -241,7 +241,7 @@ namespace PKHeX.Core { // Can't have another language name if it hasn't evolved or wasn't a language-traded egg. bool match = PKX.getSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format) == nickname; - match |= (pkm.WasTradedEgg || Legal.getHasEvolved(pkm)) && PKX.getIsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format); + match |= (pkm.WasTradedEgg || Legal.getHasEvolved(pkm)) && !PKX.getIsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format); if (!match) { @@ -1107,7 +1107,7 @@ namespace PKHeX.Core if (3 <= pkm.Format && pkm.Format <= 5) // 3-5 { - if (pkm.Version != (int) GameVersion.CXD && abilities[0] != abilities[1] && pkm.PIDAbility != abilval) + if (pkm.Version != (int) GameVersion.CXD && abilities[0] != abilities[1] && pkm.AbilityNumber != 1 << abilval) { AddLine(Severity.Invalid, V113, CheckIdentifier.Ability); return; @@ -2149,6 +2149,16 @@ namespace PKHeX.Core return res; } + private void verifyPreRelearn() + { + // For origins prior to relearn moves, need to try to match a mystery gift if applicable. + + if (pkm.WasEvent || pkm.WasEventEgg) + { + EventGiftMatch = new List(Legal.getValidGifts(pkm)); + EncounterMatch = EventGiftMatch.FirstOrDefault(); + } + } private CheckResult[] verifyRelearn() { RelearnBase = null; diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 740176a23..559b32356 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -1071,13 +1071,13 @@ namespace PKHeX.Core { if (pkm.Egg_Location == 0) // Not Egg { - if (wc.CardID != pkm.SID) continue; + if (wc.SID != pkm.SID) continue; if (wc.TID != pkm.TID) continue; if (wc.OT != pkm.OT_Name) continue; if (wc.OTGender != pkm.OT_Gender) continue; - if (wc.PIDType == 0 && pkm.PID != wc.PID) continue; + if (wc.PID != 0 && pkm.PID != wc.PID) continue; + if (wc.PIDType == 0 && pkm.IsShiny) continue; if (wc.PIDType == 2 && !pkm.IsShiny) continue; - if (wc.PIDType == 3 && pkm.IsShiny) continue; if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) continue; if (wc.Language != 0 && wc.Language != pkm.Language) continue; } diff --git a/PKHeX/PKM/PK4.cs b/PKHeX/PKM/PK4.cs index 3a3343e22..a89bfa843 100644 --- a/PKHeX/PKM/PK4.cs +++ b/PKHeX/PKM/PK4.cs @@ -29,6 +29,7 @@ namespace PKHeX.Core public override int Nature { get { return (int)(PID%25); } set { } } public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } public override int CurrentHandler { get { return 0; } set { } } + public override int AbilityNumber { get { return 1 << PIDAbility; } set { } } // Structure public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } diff --git a/PKHeX/PKM/PK5.cs b/PKHeX/PKM/PK5.cs index a3751b519..fe9e63d4e 100644 --- a/PKHeX/PKM/PK5.cs +++ b/PKHeX/PKM/PK5.cs @@ -29,6 +29,7 @@ namespace PKHeX.Core public override uint EncryptionConstant { get { return PID; } set { } } public override int CurrentFriendship { get { return OT_Friendship; } set { OT_Friendship = value; } } public override int CurrentHandler { get { return 0; } set { } } + public override int AbilityNumber { get { return HiddenAbility ? 4 : 1 << PIDAbility; } set { } } // Structure public override uint PID { get { return BitConverter.ToUInt32(Data, 0x00); } set { BitConverter.GetBytes(value).CopyTo(Data, 0x00); } } diff --git a/PKHeX/PKM/PKM.cs b/PKHeX/PKM/PKM.cs index 190857cb2..1b9b3dd10 100644 --- a/PKHeX/PKM/PKM.cs +++ b/PKHeX/PKM/PKM.cs @@ -360,9 +360,10 @@ namespace PKHeX.Core { if (GenNumber > 5 || Format > 5) return -1; - if (GenNumber == 5) - return (int)((PID >> 16) & 1); - return (int)(PID & 1); + + if (Version == (int) GameVersion.CXD) + return Array.IndexOf(PersonalInfo.Abilities, Ability); + return (int)((GenNumber == 5 ? PID >> 16 : PID) & 1); } }