mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-24 02:24:43 -05:00
Skip random level check if criteria not in range
This commit is contained in:
@@ -7,6 +7,7 @@ namespace PKHeX.Core;
|
||||
/// Generation 2-3 specific met location name holder.
|
||||
/// </summary>
|
||||
/// <remarks>Single segment, no shift bias.</remarks>
|
||||
/// <param name="Met0">List of location names for bank 0.</param>
|
||||
public sealed record LocationSet0(string[] Met0) : ILocationSet
|
||||
{
|
||||
public ReadOnlySpan<string> GetLocationNames(int bankID) => bankID switch
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace PKHeX.Core;
|
||||
/// Generation 4 specific met location name holder.
|
||||
/// </summary>
|
||||
/// <remarks>Multi-segment, small gaps.</remarks>
|
||||
/// <param name="Met0">List of location names for bank 0.</param>
|
||||
/// <param name="Met2">List of location names for bank 2 (2000).</param>
|
||||
/// <param name="Met3">List of location names for bank 3 (3000).</param>
|
||||
public sealed record LocationSet4(string[] Met0, string[] Met2, string[] Met3) : ILocationSet
|
||||
{
|
||||
public ReadOnlySpan<string> GetLocationNames(int bankID) => bankID switch
|
||||
|
||||
@@ -7,6 +7,10 @@ namespace PKHeX.Core;
|
||||
/// Generation 5+ specific met location name holder.
|
||||
/// </summary>
|
||||
/// <remarks>Multi-segment, large gaps.</remarks>
|
||||
/// <param name="Met0">List of location names for bank 0.</param>
|
||||
/// <param name="Met3">List of location names for bank 3 (30000).</param>
|
||||
/// <param name="Met4">List of location names for bank 4 (40000).</param>
|
||||
/// <param name="Met6">List of location names for bank 6 (60000).</param>
|
||||
public sealed record LocationSet6(string[] Met0, string[] Met3, string[] Met4, string[] Met6) : ILocationSet
|
||||
{
|
||||
public ReadOnlySpan<string> GetLocationNames(int bankID) => bankID switch
|
||||
|
||||
@@ -69,16 +69,17 @@ public PA8 ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
|
||||
private void SetPINGA(PA8 pk, EncounterCriteria criteria, PersonalInfo8LA pi)
|
||||
{
|
||||
var para = GetParams(pi);
|
||||
bool checkLevel = criteria.IsSpecifiedLevelRange() && this.IsLevelWithinRange(criteria);
|
||||
while (true)
|
||||
{
|
||||
var (_, slotSeed) = Overworld8aRNG.ApplyDetails(pk, criteria, para, HasAlphaMove);
|
||||
if (this.IsRandomLevel())
|
||||
{
|
||||
// Give a random level according to the RNG correlation.
|
||||
var lvl = Overworld8aRNG.GetRandomLevel(slotSeed, LevelMin, LevelMax);
|
||||
if (criteria.IsSpecifiedLevelRange() && !criteria.IsSatisfiedLevelRange(lvl))
|
||||
var level = Overworld8aRNG.GetRandomLevel(slotSeed, LevelMin, LevelMax);
|
||||
if (checkLevel && !criteria.IsSatisfiedLevelRange(level))
|
||||
continue;
|
||||
pk.MetLevel = pk.CurrentLevel = lvl;
|
||||
pk.MetLevel = pk.CurrentLevel = level;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ public static class LevelRangeExtensions
|
||||
/// <inheritdoc cref="IsLevelWithinRange(ILevelRange,int)"/>
|
||||
public static bool IsLevelWithinRange(int level, int min, int max) => min <= level && level <= max;
|
||||
|
||||
/// <inheritdoc cref="IsLevelWithinRange(ILevelRange,int)"/>
|
||||
public static bool IsLevelWithinRange<T>(this ILevelRange r, T other) where T : ILevelRange => IsLevelWithinRange(r, other.LevelMin, other.LevelMax);
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the specified level inputs are within range of the <see cref="ILevelRange.LevelMin"/> and <see cref="ILevelRange.LevelMax"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,7 @@ public static void SetRandom<T>(this T enc, PK3 pk, PersonalInfo3 pi, EncounterC
|
||||
var gr = pi.Gender;
|
||||
var (min, max) = SlotMethodH.GetRange(enc.Type, enc.SlotNumber);
|
||||
bool checkProc = MethodH.IsEncounterCheckApplicable(enc.Type);
|
||||
bool checkLevel = criteria.IsSpecifiedLevelRange() && enc.IsLevelWithinRange(criteria);
|
||||
|
||||
// Generate Method H correlated PID and IVs, no lead (keep things simple).
|
||||
while (true)
|
||||
@@ -57,7 +58,7 @@ public static void SetRandom<T>(this T enc, PK3 pk, PersonalInfo3 pi, EncounterC
|
||||
|
||||
{
|
||||
var level = (byte)MethodH.GetRandomLevel(enc, lv, LeadRequired.None);
|
||||
if (criteria.IsSpecifiedLevelRange() && !criteria.IsSatisfiedLevelRange(level))
|
||||
if (checkLevel && !criteria.IsSatisfiedLevelRange(level))
|
||||
break; // try again
|
||||
pk.MetLevel = pk.CurrentLevel = level;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public static uint SetRandomJ<T>(this T enc, PK4 pk, PersonalInfo4 pi, Encounter
|
||||
var (min, max) = SlotMethodJ.GetRange(enc.Type, enc.SlotNumber);
|
||||
bool randLevel = MethodJ.IsLevelRand(enc);
|
||||
bool checkProc = MethodJ.IsEncounterCheckApplicable(enc.Type);
|
||||
bool checkLevel = criteria.IsSpecifiedLevelRange() && enc.IsLevelWithinRange(criteria);
|
||||
|
||||
// Generate Method J correlated PID and IVs, no lead (keep things simple).
|
||||
while (true)
|
||||
@@ -82,7 +83,7 @@ public static uint SetRandomJ<T>(this T enc, PK4 pk, PersonalInfo4 pi, Encounter
|
||||
if (randLevel)
|
||||
{
|
||||
var level = (byte)MethodJ.GetRandomLevel(enc, lv, LeadRequired.None);
|
||||
if (criteria.IsSpecifiedLevelRange() && !criteria.IsSatisfiedLevelRange(level))
|
||||
if (checkLevel && !criteria.IsSatisfiedLevelRange(level))
|
||||
break; // try again
|
||||
pk.MetLevel = pk.CurrentLevel = level;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public static uint SetRandomK<T>(this T enc, PK4 pk, PersonalInfo4 pi, Encounter
|
||||
bool randLevel = MethodK.IsLevelRand(enc);
|
||||
var modulo = enc.Type.IsSafari() ? 10u : 100u;
|
||||
bool checkProc = MethodK.IsEncounterCheckApplicable(enc.Type);
|
||||
bool checkLevel = criteria.IsSpecifiedLevelRange() && enc.IsLevelWithinRange(criteria);
|
||||
|
||||
// Generate Method K correlated PID and IVs, no lead (keep things simple).
|
||||
while (true)
|
||||
@@ -79,7 +80,7 @@ public static uint SetRandomK<T>(this T enc, PK4 pk, PersonalInfo4 pi, Encounter
|
||||
if (randLevel)
|
||||
{
|
||||
var level = (byte)MethodK.GetRandomLevel(enc, lv, LeadRequired.None);
|
||||
if (criteria.IsSpecifiedLevelRange() && !criteria.IsSatisfiedLevelRange(level))
|
||||
if (checkLevel && !criteria.IsSatisfiedLevelRange(level))
|
||||
break; // try again
|
||||
pk.MetLevel = pk.CurrentLevel = level;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user