From f7d66db7e282bc3c4b4fb5406d67c174c7ed778b Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 19 Aug 2023 11:13:20 -0700 Subject: [PATCH] Misc tweaks Check HT move memories in Gen9 appropriately for deferral cases Add missing ID32 set for GO8->PKM Slight pre-work for Mightiest Mark Mew method signatures --- .../Encounters/Generator/EncounterFinder.cs | 15 +++++++++++---- .../Encounters/Templates/GO/EncounterSlot8GO.cs | 1 + .../Legality/Restrictions/Memories/Memories.cs | 8 -------- PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs | 2 +- .../Legality/Verifiers/Ribbons/MarkRules.cs | 12 ++++++++++++ .../Verifiers/Ribbons/RibbonVerifierMark9.cs | 2 +- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs index 76397e375..2da30ca51 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterFinder.cs @@ -45,7 +45,8 @@ public static void FindVerifiedEncounter(PKM pk, LegalInfo info) // Looks like we might have a good enough match. Check if this is really a good match. info.EncounterMatch = enc; - info.Parse.Add(e); + if (e.Comment.Length > 0) + info.Parse.Add(e); if (!VerifySecondaryChecks(pk, info, encounter)) continue; @@ -117,14 +118,20 @@ private static bool VerifySecondaryChecks(PKM pk, LegalInfo info, PeekEnumerator if (m is IMemoryOT o && MemoryPermissions.IsMemoryOfKnownMove(o.OT_Memory)) { var mem = MemoryVariableSet.Read(m, 0); - if (!MemoryPermissions.CanKnowMove(pk, mem, info.EncounterMatch.Context, info)) + bool valid = MemoryPermissions.CanKnowMove(pk, mem, info.EncounterMatch.Context, info); + if (!valid && iterator.PeekIsNext()) return false; } if (m is IMemoryHT h && MemoryPermissions.IsMemoryOfKnownMove(h.HT_Memory) && !pk.HasMove(h.HT_TextVar)) { var mem = MemoryVariableSet.Read(m, 1); - var context = Memories.GetContextHandler(pk.Context); - if (!MemoryPermissions.CanKnowMove(pk, mem, context, info)) + + var sources = MemoryRules.GetPossibleSources(info.EvoChainsAllGens); + sources = MemoryRules.ReviseSourcesHandler(pk, sources, info.EncounterOriginal); + + bool valid = (sources.HasFlag(MemorySource.Gen6) && MemoryPermissions.CanKnowMove(pk, mem, EntityContext.Gen6, info)) + || (sources.HasFlag(MemorySource.Gen8) && MemoryPermissions.CanKnowMove(pk, mem, EntityContext.Gen8, info)); + if (!valid && iterator.PeekIsNext()) return false; } } diff --git a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs index 55481098d..87b9e694b 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs @@ -129,6 +129,7 @@ public PKM ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria) pk.MetDate = this.GetRandomValidDate(); pk.OT_Name = tr.OT; + pk.ID32 = tr.ID32; pk.OT_Gender = tr.Gender; pk.HT_Name = "PKHeX"; pk.CurrentHandler = 1; diff --git a/PKHeX.Core/Legality/Restrictions/Memories/Memories.cs b/PKHeX.Core/Legality/Restrictions/Memories/Memories.cs index 77fbaa6a9..5c7f506ad 100644 --- a/PKHeX.Core/Legality/Restrictions/Memories/Memories.cs +++ b/PKHeX.Core/Legality/Restrictions/Memories/Memories.cs @@ -33,14 +33,6 @@ public static MemoryArgType GetMemoryArgType(byte memory, int memoryGen) return (MemoryArgType)type; } - public static EntityContext GetContextHandler(EntityContext current) => current switch - { - EntityContext.Gen7 => EntityContext.Gen6, - EntityContext.Gen8a => EntityContext.Gen8, - EntityContext.Gen8b => EntityContext.Gen8, - _ => current, - }; - public static MemoryContext GetContext(EntityContext context) => context.Generation() switch { <=7 => MemoryContext6.Instance, diff --git a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs index e23ff1edd..e09757bff 100644 --- a/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MemoryVerifier.cs @@ -70,7 +70,7 @@ private void VerifyHTMemoryContextVisited(LegalityAnalysis data, MemorySource so if (ValidSet(results, start)) return; } - if (sources.HasFlag(MemorySource.Deleted) ) + if (sources.HasFlag(MemorySource.Deleted)) { results.RemoveRange(start, results.Count - start); VerifyHTMemoryNone(data, (ITrainerMemories)data.Entity); diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/MarkRules.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/MarkRules.cs index 9fd8326f9..99da856c3 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/MarkRules.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/MarkRules.cs @@ -185,6 +185,18 @@ public static bool IsMarkPresentMightiest(IEncounterTemplate enc) return enc is EncounterMight9 { Stars: 7 }; } + /// + /// Checks if the input's mark state is valid. + /// + public static bool IsMarkValidMightiest(IEncounterTemplate enc, bool hasMark, EvolutionHistory evos) + { + if (IsMarkPresentMightiest(enc)) + return hasMark; + //if (enc.Species == (int)Species.Mew && evos.HasVisitedGen9) + // return true; // Can be awarded the mark for battling Mewtwo. + return !hasMark; + } + /// /// Checks if the input should have the mark. /// diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifierMark9.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifierMark9.cs index 2de30c6b3..52b546e69 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifierMark9.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonVerifierMark9.cs @@ -17,7 +17,7 @@ public static void Parse(this IRibbonSetMark9 r, RibbonVerifierArguments args, r list.Add(MarkItemfinder); if (r.RibbonMarkJumbo && !MarkRules.IsMarkAllowedJumbo(args.History, args.Entity)) list.Add(MarkJumbo); - if (r.RibbonMarkMightiest != MarkRules.IsMarkPresentMightiest(args.Encounter)) + if (!MarkRules.IsMarkValidMightiest(args.Encounter, r.RibbonMarkMightiest, args.History)) list.Add(MarkMightiest, !r.RibbonMarkMightiest); if (r.RibbonMarkMini && !MarkRules.IsMarkAllowedMini(args.History, args.Entity)) list.Add(MarkMini);