mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-30 07:56:39 -05:00
Enhance fail-retry PID generation for raids
try with criteria -> try with critera-w/o-IVs, try without any criteria
This commit is contained in:
@@ -55,6 +55,16 @@ public EncounterCriteria()
|
||||
HiddenPowerType = -1;
|
||||
}
|
||||
|
||||
public EncounterCriteria WithoutIVs() => this with
|
||||
{
|
||||
IV_HP = RandomIV,
|
||||
IV_ATK = RandomIV,
|
||||
IV_DEF = RandomIV,
|
||||
IV_SPA = RandomIV,
|
||||
IV_SPD = RandomIV,
|
||||
IV_SPE = RandomIV,
|
||||
};
|
||||
|
||||
public bool IsSatisfiedHiddenPower(uint iv32) => HiddenPower.GetType(iv32) == HiddenPowerType;
|
||||
|
||||
private const sbyte RandomIV = -1;
|
||||
|
||||
@@ -113,7 +113,10 @@ private void SetPINGA(PK8 pk, EncounterCriteria criteria, PersonalInfo8SWSH pi)
|
||||
} while (++ctr < max);
|
||||
|
||||
if (ctr == max) // fail
|
||||
while (!TryApply(pk, seed = rand.Next(), iv, param, EncounterCriteria.Unrestricted)) { }
|
||||
{
|
||||
if (!TryApply(pk, seed = rand.Next(), iv, param, criteria.WithoutIVs()))
|
||||
while (!TryApply(pk, seed = rand.Next(), iv, param, EncounterCriteria.Unrestricted)) { }
|
||||
}
|
||||
|
||||
FinishCorrelation(pk, seed);
|
||||
if (criteria.IsSpecifiedNature() && criteria.Nature != pk.Nature && criteria.Nature.IsMint())
|
||||
|
||||
@@ -279,7 +279,7 @@ private void SetPINGA(PK9 pk, EncounterCriteria criteria, PersonalInfo9SV pi)
|
||||
|
||||
var init = Util.Rand.Rand64();
|
||||
var success = this.TryApply32(pk, init, param, criteria);
|
||||
if (!success)
|
||||
if (!success && !this.TryApply32(pk, init, param, criteria.WithoutIVs()))
|
||||
this.TryApply32(pk, init, param, EncounterCriteria.Unrestricted);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -296,7 +296,7 @@ private void SetPINGA(PK9 pk, EncounterCriteria criteria, PersonalInfo9SV pi)
|
||||
|
||||
var init = Util.Rand.Rand64();
|
||||
var success = this.TryApply32(pk, init, param, criteria);
|
||||
if (!success)
|
||||
if (!success && !this.TryApply32(pk, init, param, criteria.WithoutIVs()))
|
||||
this.TryApply32(pk, init, param, EncounterCriteria.Unrestricted);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -146,9 +146,9 @@ private void SetPINGA(PK9 pk, EncounterCriteria criteria, PersonalInfo9SV pi)
|
||||
Ability, Shiny);
|
||||
|
||||
ulong init = Util.Rand.Rand64();
|
||||
var success = this.TryApply64(pk, init, param, criteria, IVs.IsSpecified);
|
||||
if (!success)
|
||||
this.TryApply64(pk, init, param, EncounterCriteria.Unrestricted, IVs.IsSpecified);
|
||||
var success = this.TryApply64(pk, init, param, criteria);
|
||||
if (!success && !this.TryApply64(pk, init, param, criteria.WithoutIVs()))
|
||||
this.TryApply64(pk, init, param, EncounterCriteria.Unrestricted);
|
||||
if (IVs.IsSpecified)
|
||||
{
|
||||
pk.IV_HP = IVs.HP;
|
||||
|
||||
@@ -217,7 +217,7 @@ private void SetPINGA(PK9 pk, EncounterCriteria criteria, PersonalInfo9SV pi)
|
||||
|
||||
var init = Util.Rand.Rand64();
|
||||
var success = this.TryApply32(pk, init, param, criteria);
|
||||
if (!success)
|
||||
if (!success && !this.TryApply32(pk, init, param, criteria.WithoutIVs()))
|
||||
this.TryApply32(pk, init, param, EncounterCriteria.Unrestricted);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -32,7 +32,7 @@ public static bool TryApply32<TEnc>(this TEnc enc, PK9 pk, in ulong init, in Gen
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryApply64<TEnc>(this TEnc enc, PK9 pk, in ulong init, in GenerateParam9 param, EncounterCriteria criteria, bool ignoreIVs)
|
||||
public static bool TryApply64<TEnc>(this TEnc enc, PK9 pk, in ulong init, in GenerateParam9 param, EncounterCriteria criteria)
|
||||
where TEnc : ISpeciesForm, IGemType
|
||||
{
|
||||
var rand = new Xoroshiro128Plus(init);
|
||||
@@ -40,7 +40,7 @@ public static bool TryApply64<TEnc>(this TEnc enc, PK9 pk, in ulong init, in Gen
|
||||
for (int ctr = 0; ctr < maxCtr; ctr++)
|
||||
{
|
||||
ulong seed = rand.Next(); // fake cryptosecure
|
||||
if (!GenerateData(pk, param, criteria, seed, ignoreIVs))
|
||||
if (!GenerateData(pk, param, criteria, seed))
|
||||
continue;
|
||||
|
||||
var type = Tera9RNG.GetTeraType(seed, enc.TeraType, enc.Species, enc.Form);
|
||||
|
||||
Reference in New Issue
Block a user