From cf86cafdf767d07d9d64b399d07af59fd7157ece Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 2 Jul 2022 17:10:30 -0700 Subject: [PATCH] Add optional loop for generating min level --- .../Encounters/EncounterSlot/EncounterSlot8a.cs | 15 ++++++++++++--- .../Encounters/Generator/EncounterCriteria.cs | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8a.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8a.cs index 5f35ba85b..7579eef6b 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8a.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8a.cs @@ -43,9 +43,18 @@ public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMov pk.Gender = (int)Gender; var para = GetParams(); - var (_, slotSeed) = Overworld8aRNG.ApplyDetails(pk, criteria, para, HasAlphaMove); - if (LevelMin != LevelMax) - pk.CurrentLevel = pk.Met_Level = Overworld8aRNG.GetRandomLevel(slotSeed, LevelMin, LevelMax); + while (true) + { + var (_, slotSeed) = Overworld8aRNG.ApplyDetails(pk, criteria, para, HasAlphaMove); + if (LevelMin != LevelMax) + { + var lvl = Overworld8aRNG.GetRandomLevel(slotSeed, LevelMin, LevelMax); + if (criteria.ForceMinLevelRange && lvl != LevelMin) + continue; + pk.CurrentLevel = pk.Met_Level = lvl; + } + break; + } } protected override void SetEncounterMoves(PKM pk, GameVersion version, int level) diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs index d75ccf76f..ad20c666f 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterCriteria.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using static PKHeX.Core.AbilityPermission; @@ -37,6 +37,11 @@ public sealed record EncounterCriteria public int IV_SPD { get; init; } = RandomIV; public int IV_SPE { get; init; } = RandomIV; + /// + /// If the Encounter yields variable level ranges (e.g. RNG correlation), force the minimum level instead of yielding first match. + /// + public bool ForceMinLevelRange { get; set; } + // unused public int HPType { get; init; } = -1;