From 41a3989b534257b2a7012bffd1d7f5797fa780a6 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 12 Jan 2019 23:50:31 -0800 Subject: [PATCH] Consolidate encounterlink into mysterygift use synthetic wondercards to match link gifts --- PKHeX.Core/Editing/CommonEdits.cs | 5 +- .../Legality/Encounters/Data/Encounters6.cs | 18 ---- .../Legality/Encounters/EncounterLink.cs | 97 ------------------- .../Generator/EncounterGenerator.cs | 9 +- .../Generator/EncounterLinkGenerator.cs | 27 ------ .../Generator/EncounterMovesetGenerator.cs | 23 ----- .../Encounters/Generator/EncounterOrder.cs | 1 - .../Encounters/Verifiers/EncounterVerifier.cs | 20 ---- .../Verifiers/VerifyRelearnMoves.cs | 2 - .../Legality/Verifiers/AbilityVerifier.cs | 1 - PKHeX.Core/Legality/Verifiers/BallVerifier.cs | 2 - .../Legality/Verifiers/MemoryVerifier.cs | 13 +-- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 2 +- PKHeX.Core/MysteryGifts/WC6.cs | 12 ++- 14 files changed, 16 insertions(+), 216 deletions(-) delete mode 100644 PKHeX.Core/Legality/Encounters/EncounterLink.cs delete mode 100644 PKHeX.Core/Legality/Encounters/Generator/EncounterLinkGenerator.cs diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs index 6db31b384..8f844540a 100644 --- a/PKHeX.Core/Editing/CommonEdits.cs +++ b/PKHeX.Core/Editing/CommonEdits.cs @@ -254,10 +254,11 @@ namespace PKHeX.Core public static int[] GetSuggestedRelearnMoves(this PKM pk, LegalityAnalysis legal) { int[] m = legal.GetSuggestedRelearn(); - if (!m.All(z => z == 0)) + if (m.Any(z => z != 0)) return m; - if (pk.WasEgg || pk.WasEvent || pk.WasEventEgg || pk.WasLink) + var enc = legal.EncounterMatch; + if (enc is MysteryGift || enc is EncounterEgg) return m; var encounter = legal.GetSuggestedMetInfo(); diff --git a/PKHeX.Core/Legality/Encounters/Data/Encounters6.cs b/PKHeX.Core/Legality/Encounters/Data/Encounters6.cs index b74396934..325991ddb 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Encounters6.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Encounters6.cs @@ -401,23 +401,5 @@ namespace PKHeX.Core new EncounterTrade { Species = 222, Level = 50, Ability = 4, Gender = 1, TID = 00325, Nature = Nature.Calm, IVs = new[] {31, -1, -1, -1, -1, 31}, }, // Corsola }; #endregion - #region Pokémon Link Gifts - - internal static readonly EncounterLink[] LinkGifts6 = - { - new EncounterLink { Species = 154, Level = 50, Ability = 4, Moves = new[] {076, 241, 235, 034} }, // Meganium - new EncounterLink { Species = 157, Level = 50, Ability = 4, Moves = new[] {315, 172, 488, 129} }, // Typhlosion - new EncounterLink { Species = 160, Level = 50, Ability = 4, Moves = new[] {008, 242, 127, 103} }, // Feraligatr with Ice Punch (not relearn) - - new EncounterLink { Species = 251, Level = 10, Ability = 1, Moves = new[] {105, 215, 610, 219}, RelearnMoves = new[] {610, 0, 0, 0}, Ball = 11, Version = GameVersion.XY }, // Celebi - - new EncounterLink { Species = 377, Level = 50, Ability = 4, Moves = new[] {153, 008, 444, 359}, RelearnMoves = new[] {153, 008, 444, 359}, }, // Regirock - new EncounterLink { Species = 378, Level = 50, Ability = 4, Moves = new[] {085, 133, 058, 258}, RelearnMoves = new[] {085, 133, 058, 258}, }, // Regice - new EncounterLink { Species = 379, Level = 50, Ability = 4, Moves = new[] {442, 157, 356, 334}, RelearnMoves = new[] {442, 157, 356, 334}, }, // Registeel - - new EncounterLink { Species = 208, Level = 40, Ability = 1, Moves = new[] {231, 242, 157, 103}, RibbonClassic = false, Version = GameVersion.ORAS, OT = false }, // Steelix - new EncounterLink { Species = 362, Level = 40, Ability = 1, Moves = new[] {423, 029, 182, 524}, RibbonClassic = false, Version = GameVersion.ORAS, OT = false }, // Glalie - }; - #endregion } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterLink.cs b/PKHeX.Core/Legality/Encounters/EncounterLink.cs deleted file mode 100644 index 9720fb89d..000000000 --- a/PKHeX.Core/Legality/Encounters/EncounterLink.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; - -namespace PKHeX.Core -{ - /// - /// Pokémon Link Encounter Data - /// - public sealed class EncounterLink : IEncounterable, IRibbonSetEvent4, IMoveset, ILocation, IVersion - { - public int Species { get; set; } - public int Level { get; set; } - public int LevelMin => Level; - public int LevelMax => Level; - public int Location { get; set; } = 30011; - public int Ability { get; set; } = 1; - public int Ball { get; set; } = 4; // Pokéball - public int[] RelearnMoves { get; set; } = Array.Empty(); - public bool OT { get; set; } = true; // Receiver is OT? - - public bool EggEncounter => false; - public int EggLocation { get => 0; set { } } - public GameVersion Version { get; set; } = GameVersion.Gen6; - - public int[] Moves { get; set; } = Array.Empty(); - - public string Name => "Pokémon Link Gift"; - - public bool RibbonClassic { get; set; } = true; - - // Unused - public bool RibbonWishing { get; set; } - public bool RibbonPremier { get; set; } - public bool RibbonEvent { get; set; } - public bool RibbonBirthday { get; set; } - public bool RibbonSpecial { get; set; } - public bool RibbonWorld { get; set; } - public bool RibbonChampionWorld { get; set; } - public bool RibbonSouvenir { get; set; } - - public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted); - - public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) - { - const int gen = 6; - var version = this.GetCompatibleVersion((GameVersion)SAV.Game); - int lang = (int)Legal.GetSafeLanguage(6, (LanguageID)SAV.Language); - var pk = new PK6 - { - EncryptionConstant = Util.Rand32(), - Species = Species, - Language = lang, - CurrentLevel = Level, - Version = (int)version, - PID = Util.Rand32(), - Nickname = PKX.GetSpeciesNameGeneration(Species, lang, gen), - Ball = Ball, - }; - - SAV.ApplyToPKM(pk); - SetMetData(pk); - SetNatureGender(pk, criteria); - pk.RefreshAbility(Ability >> 1); - pk.SetRandomIVs(flawless: 3); - - pk.Version = (int)version; - pk.Language = lang; - - pk.Moves = Moves; - pk.SetMaximumPPCurrent(Moves); - pk.OT_Friendship = pk.PersonalInfo.BaseFriendship; - - if (RelearnMoves.Length > 0) - pk.RelearnMoves = RelearnMoves; - if (RibbonClassic) - pk.RibbonClassic = true; - - pk.SetRandomMemory6(); - if (!OT) - SAV.ApplyHandlingTrainerInfo(pk); - - return pk; - } - - private static void SetNatureGender(PKM pk, EncounterCriteria criteria) - { - pk.Nature = (int)criteria.GetNature(Nature.Random); - pk.Gender = criteria.GetGender(-1, pk.PersonalInfo); - } - - private void SetMetData(PKM pk) - { - pk.MetDate = DateTime.Today; - pk.Met_Level = Level; - pk.Met_Location = Location; - } - } -} diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs index 4f50cd2ba..17e66854c 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs @@ -7,7 +7,6 @@ using static PKHeX.Core.MysteryGiftGenerator; using static PKHeX.Core.EncounterTradeGenerator; using static PKHeX.Core.EncounterSlotGenerator; using static PKHeX.Core.EncounterStaticGenerator; -using static PKHeX.Core.EncounterLinkGenerator; using static PKHeX.Core.EncounterEggGenerator; namespace PKHeX.Core @@ -305,14 +304,8 @@ namespace PKHeX.Core private static IEnumerable GenerateRawEncounters(PKM pkm) { int ctr = 0; - if (pkm.WasLink) - { - foreach (var z in GetValidLinkGifts(pkm)) - { yield return z; ++ctr; } - if (ctr != 0) yield break; - } - if (pkm.WasEvent || pkm.WasEventEgg) + if (pkm.WasEvent || pkm.WasEventEgg || pkm.WasLink) { foreach (var z in GetValidGifts(pkm)) { yield return z; ++ctr; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterLinkGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterLinkGenerator.cs deleted file mode 100644 index e25c12916..000000000 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterLinkGenerator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace PKHeX.Core -{ - public static class EncounterLinkGenerator - { - public static IEnumerable GetPossible(PKM pkm) - { - if (!pkm.Gen6) - return Enumerable.Empty(); - return Encounters6.LinkGifts6.Where(g => g.Species == pkm.Species); - } - - public static IEnumerable GetPossible(PKM pkm, IReadOnlyList vs) - { - if (!pkm.Gen6) - return Enumerable.Empty(); - return Encounters6.LinkGifts6.Where(g => vs.Any(z => z.Species == g.Species)); - } - - public static IEnumerable GetValidLinkGifts(PKM pkm) - { - return GetPossible(pkm).Where(g => g.Level == pkm.Met_Level); - } - } -} diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs index cfae4e1b7..8d286a629 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs @@ -133,7 +133,6 @@ namespace PKHeX.Core { case EncounterOrder.Egg: return GetEggs(pk, needs, version); case EncounterOrder.Mystery: return GetGifts(pk, needs); - case EncounterOrder.Link: return GetLink(pk, needs); case EncounterOrder.Static: return GetStatic(pk, needs); case EncounterOrder.Trade: return GetTrades(pk, needs); case EncounterOrder.Slot: return GetSlots(pk, needs); @@ -195,28 +194,6 @@ namespace PKHeX.Core } } - /// - /// Gets possible encounters that allow all moves requested to be learned. - /// - /// Rough Pokémon data which contains the requested species, gender, and form. - /// Moves which cannot be taught by the player. - /// A consumable list of possible encounters. - private static IEnumerable GetLink(PKM pk, IReadOnlyCollection needs) - { - var gifts = EncounterLinkGenerator.GetPossible(pk); - foreach (var gift in gifts) - { - if (needs.Count == 0) - { - yield return gift; - continue; - } - var em = gift.Moves; - if (!needs.Except(em).Any()) - yield return gift; - } - } - /// /// Gets possible encounters that allow all moves requested to be learned. /// diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterOrder.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterOrder.cs index 7d8c3175a..9c44ac181 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterOrder.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterOrder.cs @@ -4,7 +4,6 @@ namespace PKHeX.Core { Egg, Mystery, - Link, Static, Trade, Slot, diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs b/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs index 022a53d14..c146fff8c 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/EncounterVerifier.cs @@ -29,7 +29,6 @@ namespace PKHeX.Core switch (info.EncounterMatch) { case EncounterEgg _: return VerifyEncounterEgg(pkm); - case EncounterLink l: return VerifyEncounterLink(pkm, l); case EncounterTrade t: return VerifyEncounterTrade(pkm, t); case EncounterSlot w: return VerifyEncounterWild(pkm, w); case EncounterStatic s: return VerifyEncounterStatic(pkm, s); @@ -342,25 +341,6 @@ namespace PKHeX.Core return new CheckResult(Severity.Valid, LEncTradeMatch, CheckIdentifier.Encounter); } - private static CheckResult VerifyEncounterLink(PKM pkm, EncounterLink enc) - { - // Should NOT be Fateful, and should be in Database - if (enc == null) - return new CheckResult(Severity.Invalid, LLinkNone, CheckIdentifier.Encounter); - - if (pkm.XY && !enc.CanBeReceivedBy(GameVersion.XY)) - return new CheckResult(Severity.Invalid, LLinkXY, CheckIdentifier.Encounter); - if (pkm.AO && !enc.CanBeReceivedBy(GameVersion.ORAS)) - return new CheckResult(Severity.Invalid, LLinkAO, CheckIdentifier.Encounter); - - if (pkm.IsShiny) - return new CheckResult(Severity.Invalid, LLinkShiny, CheckIdentifier.Encounter); - - return pkm.FatefulEncounter - ? new CheckResult(Severity.Invalid, LLinkFateful, CheckIdentifier.Encounter) - : new CheckResult(Severity.Valid, LLinkValid, CheckIdentifier.Encounter); - } - private static CheckResult VerifyEncounterEvent(PKM pkm, MysteryGift MatchedGift) { switch (MatchedGift) diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs index e6d1f710f..701fe8cc1 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/VerifyRelearnMoves.cs @@ -20,8 +20,6 @@ namespace PKHeX.Core switch (info.EncounterMatch) { - case EncounterLink l when l.RelearnMoves.Length > 0: - return VerifyRelearnSpecifiedMoveset(pkm, info, l.RelearnMoves); case MysteryGift g: return VerifyRelearnSpecifiedMoveset(pkm, info, g.RelearnMoves); case EncounterStatic s when s.Relearn.Length > 0: diff --git a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs index 1707ea9d3..746e8d7c0 100644 --- a/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/AbilityVerifier.cs @@ -335,7 +335,6 @@ namespace PKHeX.Core { case EncounterStatic s: return s.Ability; case EncounterTrade t: return t.Ability; - case EncounterLink l: return l.Ability; default: return -1; } } diff --git a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs index 2eb700f52..4fae848f7 100644 --- a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs @@ -30,8 +30,6 @@ namespace PKHeX.Core { case MysteryGift g: return VerifyBallMysteryGift(data, g); - case EncounterLink l: - return VerifyBallEquals(data, l.Ball); case EncounterTrade t: return VerifyBallEquals(data, t.Ball); case EncounterStatic s when s.Gift: diff --git a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs index 0559b7ef6..e0370e8c3 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs @@ -270,10 +270,10 @@ namespace PKHeX.Core break; } return; - case WC6 g when !g.IsEgg: + case WC6 g when !g.IsEgg && g.OTGender != 3: VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling); return; - case WC7 g when !g.IsEgg: + case WC7 g when !g.IsEgg && g.OTGender != 3: VerifyOTMemoryIs(data, g.OT_Memory, g.OT_Intensity, g.OT_TextVar, g.OT_Feeling); return; } @@ -387,15 +387,10 @@ namespace PKHeX.Core { if (generation < 6) return false; - if (EncounterMatch is EncounterLink link && !link.OT) - return false; bool untraded = pkm.HT_Name.Length == 0 || (pkm is IGeoTrack g && g.Geo1_Country == 0); - if (!(EncounterMatch is MysteryGift gift)) - return untraded; - - untraded |= !pkm.WasEventEgg; - untraded &= gift.IsEgg; + if (EncounterMatch is WC6 gift) + return gift.OTGender == 3 && untraded; return untraded; } diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index 082daf673..d678f7487 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -209,7 +209,7 @@ namespace PKHeX.Core data.AddLine(GetInvalid(LPIDTypeMismatch, CheckIdentifier.PID)); } - var result = pkm.FatefulEncounter + var result = pkm.FatefulEncounter != pkm.WasLink ? GetValid(LFatefulMystery, CheckIdentifier.Fateful) : GetInvalid(LFatefulMysteryMissing, CheckIdentifier.Fateful); data.AddLine(result); diff --git a/PKHeX.Core/MysteryGifts/WC6.cs b/PKHeX.Core/MysteryGifts/WC6.cs index 154a60418..865a8bb81 100644 --- a/PKHeX.Core/MysteryGifts/WC6.cs +++ b/PKHeX.Core/MysteryGifts/WC6.cs @@ -352,7 +352,7 @@ namespace PKHeX.Core OT_Memory = OT_Memory, OT_TextVar = OT_TextVar, OT_Feeling = OT_Feeling, - FatefulEncounter = true, + FatefulEncounter = MetLocation != 30011, // Link gifts do not set fateful encounter EVs = EVs, }; @@ -457,10 +457,12 @@ namespace PKHeX.Core { if (pkm.Egg_Location == 0) // Not Egg { - if (CardID != pkm.SID) return false; - if (TID != pkm.TID) return false; - if (OT_Name != pkm.OT_Name) return false; - if (OTGender != pkm.OT_Gender) return false; + if (OTGender != 3) + { + if (SID != pkm.SID) return false; + if (TID != pkm.TID) return false; + if (OTGender != pkm.OT_Gender) return false; + } if (PIDType == Shiny.FixedValue && pkm.PID != PID) return false; if (!PIDType.IsValid(pkm)) return false; if (OriginGame != 0 && OriginGame != pkm.Version) return false;