From 1ece844f788a057fd02b9b07672cdc2cec583bac Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 31 Jan 2021 13:05:36 -0800 Subject: [PATCH] Partial match HA species without a HA possible A captured metapod cannot have hidden ability via ability patch, but a captured caterpie evolved into metapod can, assuming it existed as caterpie. --- .../Encounters/EncounterSlot/EncounterSlot.cs | 12 +++++++++-- .../EncounterSlot/EncounterSlot3.cs | 6 ++---- .../EncounterSlot/EncounterSlot4.cs | 4 +--- .../EncounterSlot/GO/EncounterSlot8GO.cs | 7 ++----- .../EncounterStatic/EncounterStatic.cs | 2 ++ .../Legality/Encounters/IEncounterMatch.cs | 21 ++++++++++++++++++- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs index ea6148d57..730ed5b27 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs @@ -203,8 +203,16 @@ public virtual EncounterMatchRating GetMatchRating(PKM pkm) { if (IsDeferredWurmple(pkm)) return EncounterMatchRating.PartialMatch; - if (IsDeferredHiddenAbility(pkm.AbilityNumber == 4)) - return EncounterMatchRating.Deferred; + + if (pkm.Format >= 5) + { + bool isHidden = pkm.AbilityNumber == 4; + if (isHidden && this.IsPartialMatchHidden(Species)) + return EncounterMatchRating.PartialMatch; + if (IsDeferredHiddenAbility(isHidden)) + return EncounterMatchRating.Deferred; + } + return EncounterMatchRating.Match; } diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot3.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot3.cs index 1173ac096..de9faa2bc 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot3.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot3.cs @@ -28,11 +28,9 @@ public EncounterSlot3(EncounterArea3 area, int species, int form, int min, int m public override EncounterMatchRating GetMatchRating(PKM pkm) { - if (IsDeferredWurmple(pkm)) + if (IsDeferredSafari3(pkm.Ball == (int)Ball.Safari)) return EncounterMatchRating.PartialMatch; - if (IsDeferredSafari3(pkm.Ball == (int) Ball.Safari)) - return EncounterMatchRating.PartialMatch; - return EncounterMatchRating.Match; + return base.GetMatchRating(pkm); } private bool IsDeferredSafari3(bool IsSafariBall) => IsSafariBall != Locations.IsSafariZoneLocation3(Location); diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot4.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot4.cs index 19117b981..2d7e8037e 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot4.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot4.cs @@ -31,8 +31,6 @@ public EncounterSlot4(EncounterArea4 area, int species, int form, int min, int m public override EncounterMatchRating GetMatchRating(PKM pkm) { - if (IsDeferredWurmple(pkm)) - return EncounterMatchRating.PartialMatch; if ((pkm.Ball == (int)Ball.Safari) != Locations.IsSafariZoneLocation4(Location)) return EncounterMatchRating.PartialMatch; if ((pkm.Ball == (int)Ball.Sport) != (Area.Type == SlotType.BugContest)) @@ -41,7 +39,7 @@ public override EncounterMatchRating GetMatchRating(PKM pkm) if (pkm.Species != (int)Core.Species.Shedinja || pkm.Ball != (int)Ball.Poke) return EncounterMatchRating.PartialMatch; } - return EncounterMatchRating.Match; + return base.GetMatchRating(pkm); } } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs index a8e19b2c2..2dcaacfcb 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/GO/EncounterSlot8GO.cs @@ -55,7 +55,7 @@ public override EncounterMatchRating GetMatchRating(PKM pkm) { if (IsMatchPartial(pkm)) return EncounterMatchRating.PartialMatch; - return EncounterMatchRating.Match; + return base.GetMatchRating(pkm); } private bool IsMatchPartial(PKM pk) @@ -65,14 +65,11 @@ private bool IsMatchPartial(PKM pk) return true; if (!GetIVsAboveMinimum(pk)) return true; - + // Eevee & Glaceon have different base friendships. Make sure if it is invalid that we yield the other encounter before. if (PersonalTable.SWSH.GetFormEntry(Species, Form).BaseFriendship != pk.OT_Friendship) return true; - if (Species == (int)Core.Species.Wurmple) - return !WurmpleUtil.IsWurmpleEvoValid(pk); - return Species switch { (int)Core.Species.Yamask when pk.Species != Species && Form == 1 => pk is IFormArgument { FormArgument: 0 }, diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs index eed7ca1a9..c8047b6c5 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs @@ -305,6 +305,8 @@ public EncounterMatchRating GetMatchRating(PKM pkm) protected virtual bool IsMatchPartial(PKM pkm) { + if (pkm.Format >= 5 && pkm.AbilityNumber == 4 && this.IsPartialMatchHidden(Species)) + return true; return pkm.FatefulEncounter != Fateful; } } diff --git a/PKHeX.Core/Legality/Encounters/IEncounterMatch.cs b/PKHeX.Core/Legality/Encounters/IEncounterMatch.cs index b556f9c23..a1e671bd6 100644 --- a/PKHeX.Core/Legality/Encounters/IEncounterMatch.cs +++ b/PKHeX.Core/Legality/Encounters/IEncounterMatch.cs @@ -1,8 +1,27 @@ -namespace PKHeX.Core +using static PKHeX.Core.Species; + +namespace PKHeX.Core { public interface IEncounterMatch { bool IsMatchExact(PKM pkm, DexLevel dl); EncounterMatchRating GetMatchRating(PKM pkm); } + + internal static class EncounterMatchExtensions + { + /// + /// Some species do not have a Hidden Ability, but can be altered to have the HA slot via pre-evolution. + /// + /// Match object + /// Species ID + /// True if it should not originate as this species. + public static bool IsPartialMatchHidden(this IEncounterMatch _, int species) + { + return species is (int)Metapod or (int)Kakuna + or (int)Pupitar + or (int)Silcoon or (int)Cascoon + or (int)Vibrava or (int)Flygon; + } + } }