From 9930e8765aa5257c88b67e98c750c7d351f0691a Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 29 Nov 2017 23:20:49 -0800 Subject: [PATCH] Add frame level checking still WIP but should be working fairly well --- PKHeX.Core/Legality/RNG/Frame/Frame.cs | 4 +- PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs | 4 +- PKHeX.Core/Legality/RNG/Frame/SlotRange.cs | 63 +++++++++++++++---- .../Legality/Structures/EncounterArea.cs | 3 + PKHeX.Core/Legality/Structures/SlotType.cs | 4 ++ 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/PKHeX.Core/Legality/RNG/Frame/Frame.cs b/PKHeX.Core/Legality/RNG/Frame/Frame.cs index 697fbb709..130339852 100644 --- a/PKHeX.Core/Legality/RNG/Frame/Frame.cs +++ b/PKHeX.Core/Legality/RNG/Frame/Frame.cs @@ -35,7 +35,7 @@ return false; // Check Level Now - int lvl = SlotRange.GetLevel(slot, FrameType, Lead, RandLevel); + int lvl = SlotRange.GetLevel(slot, Lead, RandLevel); if (lvl < 0) { } // todo else if (pkm.HasOriginalMetLocation) { @@ -49,7 +49,7 @@ } // Check if the slot is actually encounterable (considering Sweet Scent) - bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType); + bool encounterable = SlotRange.GetIsEncounterable(slot, FrameType, 0, Lead); return encounterable; } diff --git a/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs b/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs index a4f96c898..3314fcfa3 100644 --- a/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs +++ b/PKHeX.Core/Legality/RNG/Frame/FrameFinder.cs @@ -57,6 +57,7 @@ namespace PKHeX.Core var prev = info.RNG.Prev(f.Seed); // ESV var rand = prev >> 16; f.ESV = rand; + f.RandLevel = f.Seed >> 16; yield return f; // Generate frames for other slots after the regular slots @@ -147,6 +148,7 @@ namespace PKHeX.Core var rand = f.Seed >> 16; { f.ESV = rand; + f.RandLevel = rand; yield return f; } @@ -171,7 +173,7 @@ namespace PKHeX.Core continue; var rand = f.Seed >> 16; - yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand, p16); + yield return info.GetFrame(prev, LeadRequired.StaticMagnet, rand, rand); } } diff --git a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs index 2d3742bf4..af95e0385 100644 --- a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs +++ b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs @@ -22,7 +22,7 @@ namespace PKHeX.Core case FrameType.MethodH: return HSlot(type, rand); case FrameType.MethodJ: - return JSlot(type, rand); + return JSlot(type, rand, seed); case FrameType.MethodK: return KSlot(type, rand, seed); } @@ -56,16 +56,18 @@ namespace PKHeX.Core private static int KSlot(SlotType type, uint rand, uint seed) { var ESV = rand % 100; + uint prev() => (RNG.LCRNG.Prev(seed) >> 16) % 100; switch (type) { + case SlotType.Rock_Smash: case SlotType.Surf: - return CalcSlot(ESV, H_Surf); + return CalcSlot(prev(), H_Surf); case SlotType.Super_Rod: case SlotType.Good_Rod: case SlotType.Old_Rod: - return CalcSlot(ESV, K_SuperRod); + return CalcSlot(prev(), K_SuperRod); case SlotType.BugContest: - return CalcSlot(ESV, K_BCC); + return CalcSlot(prev(), K_BCC); case SlotType.Grass_Safari: case SlotType.Surf_Safari: case SlotType.Old_Rod_Safari: @@ -75,22 +77,24 @@ namespace PKHeX.Core return 0; // (int)(rand % 10); /* Block Slot Priority not implemented */ case SlotType.Headbutt: case SlotType.Headbutt_Special: - return CalcSlot(ESV, K_Headbutt); + return CalcSlot(prev(), K_Headbutt); default: return CalcSlot(ESV, H_Regular); } } - private static int JSlot(SlotType type, uint rand) + private static int JSlot(SlotType type, uint rand, uint seed) { uint ESV = rand / 656; + uint prev() => (RNG.LCRNG.Prev(seed) >> 16) / 656; switch (type) { case SlotType.Old_Rod: + case SlotType.Rock_Smash: case SlotType.Surf: - return CalcSlot(ESV, H_Surf); + return CalcSlot(prev(), H_Surf); case SlotType.Good_Rod: case SlotType.Super_Rod: - return CalcSlot(ESV, J_SuperRod); + return CalcSlot(prev(), J_SuperRod); case SlotType.HoneyTree: return 0; default: @@ -129,21 +133,54 @@ namespace PKHeX.Core return -1; } - public static int GetLevel(EncounterSlot slot, FrameType frameType, LeadRequired seed, uint lvlrand) + public static int GetLevel(EncounterSlot slot, LeadRequired lead, uint lvlrand) { - if (seed == LeadRequired.PressureHustleSpirit) + if (lead == LeadRequired.PressureHustleSpirit) return slot.LevelMax; if (slot.LevelMin == slot.LevelMax) return slot.LevelMin; int delta = slot.LevelMax - slot.LevelMin + 1; var adjust = (int)(lvlrand % delta); - var lvl = slot.LevelMin + adjust; - return -1; // lvl; todo + return slot.LevelMin + adjust; } - public static bool GetIsEncounterable(EncounterSlot slot, FrameType frameType) + public static bool GetIsEncounterable(EncounterSlot slot, FrameType frameType, int rand, LeadRequired lead) { + if (slot.Type.IsSweetScentType()) + return true; return true; // todo + return GetCanEncounter(slot, frameType, rand, lead); + } + private static bool GetCanEncounter(EncounterSlot slot, FrameType frameType, int rand, LeadRequired lead) + { + int proc = frameType == FrameType.MethodJ ? rand / 656 : rand % 100; + if (slot.Type.HasFlag(SlotType.Rock_Smash)) + return proc < 60; + if (frameType == FrameType.MethodH) + return true; // fishing encounters are disjointed by the hooked message. + + // fishing + if (slot.Type.HasFlag(SlotType.Old_Rod)) + { + if (proc < 25) + return true; + if (proc < 50) + return lead == LeadRequired.None; + } + else if (slot.Type.HasFlag(SlotType.Good_Rod)) + { + if (proc < 50) + return true; + if (proc < 75 && lead == LeadRequired.None) + return lead == LeadRequired.None; + } + else if (slot.Type.HasFlag(SlotType.Super_Rod)) + { + if (proc < 75) + return true; + return lead == LeadRequired.None; // < 100 always true + } + return false; // shouldn't hit here } } } diff --git a/PKHeX.Core/Legality/Structures/EncounterArea.cs b/PKHeX.Core/Legality/Structures/EncounterArea.cs index 8c01c07f0..10c7e3e24 100644 --- a/PKHeX.Core/Legality/Structures/EncounterArea.cs +++ b/PKHeX.Core/Legality/Structures/EncounterArea.cs @@ -408,6 +408,7 @@ namespace PKHeX.Core var slot = baseSlot.Clone(); slot.Species = species; slot.Type = t; + slot.SlotNumber = i; slots.Add(slot); } return slots; @@ -428,6 +429,7 @@ namespace PKHeX.Core LevelMax = data[ofs + 0 + i * 8], LevelMin = data[ofs + 1 + i * 8], Species = Species, + SlotNumber = i, Type = t }); } @@ -450,6 +452,7 @@ namespace PKHeX.Core LevelMin = data[ofs + 0 + i * 4], LevelMax = data[ofs + 1 + i * 4], Species = Species, + SlotNumber = i, Type = t }); } diff --git a/PKHeX.Core/Legality/Structures/SlotType.cs b/PKHeX.Core/Legality/Structures/SlotType.cs index fc47c9df2..de402fe89 100644 --- a/PKHeX.Core/Legality/Structures/SlotType.cs +++ b/PKHeX.Core/Legality/Structures/SlotType.cs @@ -106,5 +106,9 @@ namespace PKHeX.Core { return t.HasFlag(SlotType.Old_Rod) || t.HasFlag(SlotType.Good_Rod) || t.HasFlag(SlotType.Super_Rod); } + internal static bool IsSweetScentType(this SlotType t) + { + return !(t.IsFishingRodType() || t.HasFlag(SlotType.Rock_Smash)); + } } }