From df02532697fe269398f15804eac3f4dcb19215c9 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 2 Jun 2022 20:05:27 -0700 Subject: [PATCH] Misc fixes Simplify HM memory check (bit permission superset, just check directly) Disallow BestFriends & Effort on PA8 exclusives PA8 techrecord permits none. --- .../Applicators/TechnicalRecordApplicator.cs | 3 --- .../Memories/MemoryContext6Data.cs | 19 +++++++-------- .../Legality/Verifiers/MemoryVerifier.cs | 10 +++++--- .../Verifiers/Ribbons/RibbonVerifier.cs | 24 +++++++++++++------ PKHeX.Core/PKM/PA8.cs | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/PKHeX.Core/Editing/Applicators/TechnicalRecordApplicator.cs b/PKHeX.Core/Editing/Applicators/TechnicalRecordApplicator.cs index 63a6de979..f37ba557f 100644 --- a/PKHeX.Core/Editing/Applicators/TechnicalRecordApplicator.cs +++ b/PKHeX.Core/Editing/Applicators/TechnicalRecordApplicator.cs @@ -33,9 +33,6 @@ namespace PKHeX.Core /// Moves to set flags for. If a move is not a Technical Record, it is skipped. public static void SetRecordFlags(this ITechRecord8 pk, IEnumerable moves) { - if (pk is PA8) - return; - var permit = pk.TechRecordPermitFlags; var moveIDs = pk.TechRecordPermitIndexes; if (permit.Length != moveIDs.Length) diff --git a/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext6Data.cs b/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext6Data.cs index 23b9f6171..73db49e84 100644 --- a/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext6Data.cs +++ b/PKHeX.Core/Legality/Restrictions/Memories/MemoryContext6Data.cs @@ -24,18 +24,15 @@ namespace PKHeX.Core 62, // {0} saw itself in a mirror in a mirror cave that it went to with {1}. {4} that {3}. }; - internal static readonly int[][] MoveSpecificMemories = + internal static readonly byte[] MoveSpecificMemoryHM = // Ordered by HM index for bitflag checks. { - new[] { - 20, // {0} surfed across the water, carrying {1} on its back. {4} that {3}. - 24, // {0} flew, carrying {1} on its back, to {2}. {4} that {3}. - 35, // {0} proudly used Strength at {1}’s instruction in... {2}. {4} that {3}. - 36, // {0} proudly used Cut at {1}’s instruction in... {2}. {4} that {3}. - 37, // {0} shattered rocks to its heart’s content at {1}’s instruction in... {2}. {4} that {3}. - 38, // {0} used Waterfall while carrying {1} on its back in... {2}. {4} that {3}. - 69, // {1} asked {0} to dive. Down it went, deep into the ocean, to explore the bottom of the sea. {4} that {3}. - }, - new[] { 57, 19, 70, 15, 249, 127, 291}, // Move IDs + 36, // {0} proudly used Cut at {1}’s instruction in... {2}. {4} that {3}. + 24, // {0} flew, carrying {1} on its back, to {2}. {4} that {3}. + 20, // {0} surfed across the water, carrying {1} on its back. {4} that {3}. + 35, // {0} proudly used Strength at {1}’s instruction in... {2}. {4} that {3}. + 38, // {0} used Waterfall while carrying {1} on its back in... {2}. {4} that {3}. + 37, // {0} shattered rocks to its heart’s content at {1}’s instruction in... {2}. {4} that {3}. + 69, // {1} asked {0} to dive. Down it went, deep into the ocean, to explore the bottom of the sea. {4} that {3}. }; /// diff --git a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs index c0fecaa02..ee4e8c945 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs @@ -37,15 +37,19 @@ namespace PKHeX.Core var memory = MemoryVariableSet.Read((ITrainerMemories)pkm, handler); // Actionable HM moves - int matchingMoveMemory = Array.IndexOf(MemoryContext6.MoveSpecificMemories[0], memory.MemoryID); - if (matchingMoveMemory != -1) + int hmIndex = Array.IndexOf(MemoryContext6.MoveSpecificMemoryHM, memory.MemoryID); + if (hmIndex != -1) { if (gen != 6) // Gen8 has no HMs, so this memory can never exist. return GetInvalid(string.Format(LMemoryArgBadMove, memory.Handler)); if (pkm.Species != (int)Species.Smeargle) { - if (!GetCanLearnMachineMove(pkm, info.EvoChainsAllGens[gen], MemoryContext6.MoveSpecificMemories[1][matchingMoveMemory], 6)) + // All AO hidden machine permissions are super-sets of Gen 3-5 games. + // Don't need to check the move history -- a learned HM in a prior game can still be learned in Gen6. + var evos = info.EvoChainsAllGens.Gen6; + var indexLearn = Array.FindIndex(evos, z => PersonalTable.AO.GetFormEntry(z.Species, 0).TMHM[100 + hmIndex]); + if (indexLearn == -1) return GetInvalid(string.Format(LMemoryArgBadMove, memory.Handler)); } } diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs index 7f704be85..d101da400 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifier.cs @@ -161,12 +161,8 @@ namespace PKHeX.Core yield return new RibbonResult(nameof(s6.RibbonCountMemoryBattle)); } - // Gen8+ replaced with Max Friendship. Gen6/7 uses affection. - if (pkm is IAffection a && s6.RibbonBestFriends) // can't lower affection - { - if (a.OT_Affection < 255 && pkm.IsUntraded) - yield return new RibbonResult(nameof(s6.RibbonBestFriends)); - } + if (s6.RibbonBestFriends && !IsRibbonValidBestFriend(pkm, evos, gen)) + yield return new RibbonResult(nameof(IRibbonSetCommon6.RibbonBestFriends)); } if (pkm is IRibbonSetCommon7 s7) { @@ -181,7 +177,7 @@ namespace PKHeX.Core yield return new RibbonResult(nameof(s3.RibbonChampionG3)); // RSE HoF if (s3.RibbonArtist && gen != 3) yield return new RibbonResult(nameof(s3.RibbonArtist)); // RSE Master Rank Portrait - if (s3.RibbonEffort && gen == 5 && pkm.Format == 5) // unobtainable in Gen 5 + if (s3.RibbonEffort && !IsRibbonValidEffort(pkm, evos, gen)) // unobtainable in Gen 5 yield return new RibbonResult(nameof(s3.RibbonEffort)); } if (pkm is IRibbonSetCommon8 s8) @@ -193,6 +189,20 @@ namespace PKHeX.Core } } + private static bool IsRibbonValidEffort(PKM pkm, EvolutionHistory evos, int gen) => gen switch + { + 5 when pkm.Format == 5 => false, + 8 when !pkm.HasVisitedSWSH(evos.Gen8) && !pkm.HasVisitedBDSP(evos.Gen8b) => false, + _ => true, + }; + + private static bool IsRibbonValidBestFriend(PKM pkm, EvolutionHistory evos, int gen) => gen switch + { + < 7 when pkm is { IsUntraded: true } and IAffection { OT_Affection: < 255 } => false, // Gen6/7 uses affection. Can't lower it on OT! + 8 when !pkm.HasVisitedSWSH(evos.Gen8) && !pkm.HasVisitedBDSP(evos.Gen8b) => false, // Gen8+ replaced with Max Friendship. + _ => true, + }; + private static IEnumerable GetMissingContestRibbons(IReadOnlyList bits, IReadOnlyList names) { for (int i = 0; i < bits.Count; i += 4) diff --git a/PKHeX.Core/PKM/PA8.cs b/PKHeX.Core/PKM/PA8.cs index 934e9d4a8..c18a36e0f 100644 --- a/PKHeX.Core/PKM/PA8.cs +++ b/PKHeX.Core/PKM/PA8.cs @@ -57,7 +57,7 @@ public sealed class PA8 : PKM, ISanityChecksum, IMoveReset, } // Simple Generated Attributes - public ReadOnlySpan TechRecordPermitFlags => PersonalInfo.TMHM.AsSpan(PersonalInfoSWSH.CountTM); + public ReadOnlySpan TechRecordPermitFlags => Span.Empty; public ReadOnlySpan TechRecordPermitIndexes => Legal.TMHM_SWSH.AsSpan(PersonalInfoSWSH.CountTM); public ReadOnlySpan MoveShopPermitFlags => PersonalInfo.SpecialTutors[0]; public ReadOnlySpan MoveShopPermitIndexes => Legal.MoveShop8_LA;