mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-26 18:57:47 -05:00
Inline some Rand32 calls
No functional change
This commit is contained in:
@@ -38,7 +38,8 @@ public static int GetWurmpleEvoGroup(int species)
|
||||
public static uint GetWurmpleEncryptionConstant(int evoVal)
|
||||
{
|
||||
uint result;
|
||||
do result = Util.Rand32();
|
||||
var rnd = Util.Rand;
|
||||
do result = rnd.Rand32();
|
||||
while (evoVal != GetWurmpleEvoVal(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny
|
||||
var rnd = Util.Rand;
|
||||
do
|
||||
{
|
||||
var seed = Util.Rand32(rnd);
|
||||
var seed = rnd.Rand32();
|
||||
if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed))
|
||||
return;
|
||||
} while (++ctr != maxAttempts);
|
||||
TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, Util.Rand32(rnd));
|
||||
TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, rnd.Rand32());
|
||||
}
|
||||
|
||||
private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed)
|
||||
|
||||
@@ -219,9 +219,10 @@ public static void SetRandomChainShinyPID(PKM pk, uint seed)
|
||||
|
||||
public static void SetRandomPokeSpotPID(PKM pk, int nature, int gender, int ability, int slot)
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
while (true)
|
||||
{
|
||||
var seed = Util.Rand32();
|
||||
var seed = rnd.Rand32();
|
||||
if (!MethodFinder.IsPokeSpotActivation(slot, seed, out _))
|
||||
continue;
|
||||
|
||||
@@ -341,9 +342,10 @@ private static void SetRandomWildPID4(PKM pk, int nature, int ability, int gende
|
||||
var type = GetPIDType(pk, specific);
|
||||
var method = GetGeneratorMethod(type);
|
||||
|
||||
var rnd = Util.Rand;
|
||||
while (true)
|
||||
{
|
||||
method(pk, Util.Rand32());
|
||||
method(pk, rnd.Rand32());
|
||||
if (!IsValidCriteria4(pk, nature, ability, gender))
|
||||
continue;
|
||||
return;
|
||||
@@ -393,9 +395,10 @@ private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gende
|
||||
if (ability == 2)
|
||||
ability = 0;
|
||||
|
||||
var rnd = Util.Rand;
|
||||
while (true)
|
||||
{
|
||||
uint seed = Util.Rand32();
|
||||
uint seed = rnd.Rand32();
|
||||
if (specific == PIDType.G5MGShiny)
|
||||
{
|
||||
SetValuesFromSeedMG5Shiny(pk, seed);
|
||||
@@ -422,8 +425,7 @@ private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gende
|
||||
|
||||
private static void SetRandomWildPID(PKM pk, int nature, int ability, int gender)
|
||||
{
|
||||
uint seed = Util.Rand32();
|
||||
pk.PID = seed;
|
||||
pk.PID = Util.Rand32();
|
||||
pk.Nature = nature;
|
||||
pk.Gender = gender;
|
||||
pk.RefreshAbility(ability);
|
||||
|
||||
@@ -24,13 +24,13 @@ public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny
|
||||
var rnd = Util.Rand;
|
||||
do
|
||||
{
|
||||
var seed = Util.Rand32(rnd);
|
||||
var seed = rnd.Rand32();
|
||||
if (seed == int.MaxValue)
|
||||
continue; // Unity's Rand is [int.MinValue, int.MaxValue)
|
||||
if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed))
|
||||
return;
|
||||
} while (++ctr != maxAttempts);
|
||||
TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, Util.Rand32(rnd));
|
||||
TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, rnd.Rand32());
|
||||
}
|
||||
|
||||
private static bool TryApplyFromSeed(PKM pk, EncounterCriteria criteria, Shiny shiny, int flawless, uint seed)
|
||||
|
||||
@@ -24,16 +24,16 @@ public static class Wild8bRNG
|
||||
var rnd = Util.Rand;
|
||||
do
|
||||
{
|
||||
ulong s0 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
|
||||
ulong s1 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
|
||||
ulong s0 = rnd.Rand64();
|
||||
ulong s1 = rnd.Rand64();
|
||||
var xors = new XorShift128(s0, s1);
|
||||
if (TryApplyFromSeed(pk, criteria, shiny, flawless, xors, ability))
|
||||
return;
|
||||
} while (++ctr != maxAttempts);
|
||||
|
||||
{
|
||||
ulong s0 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
|
||||
ulong s1 = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
|
||||
ulong s0 = rnd.Rand64();
|
||||
ulong s1 = rnd.Rand64();
|
||||
var xors = new XorShift128(s0, s1);
|
||||
TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, xors, ability);
|
||||
}
|
||||
|
||||
@@ -318,9 +318,9 @@ private void SetPID(PKM pk, int av)
|
||||
return;
|
||||
}
|
||||
|
||||
pk.PID = Util.Rand32();
|
||||
// Force Gender
|
||||
var rnd = Util.Rand;
|
||||
pk.PID = rnd.Rand32();
|
||||
// Force Gender
|
||||
do { pk.PID = (pk.PID & 0xFFFFFF00) | (uint)rnd.Next(0x100); }
|
||||
while (!pk.IsGenderValid());
|
||||
|
||||
|
||||
@@ -157,16 +157,17 @@ public PK2 ConvertToPK2()
|
||||
|
||||
public PK7 ConvertToPK7()
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
var pk7 = new PK7
|
||||
{
|
||||
EncryptionConstant = Util.Rand32(),
|
||||
EncryptionConstant = rnd.Rand32(),
|
||||
Species = Species,
|
||||
TID = TID,
|
||||
CurrentLevel = CurrentLevel,
|
||||
EXP = EXP,
|
||||
Met_Level = CurrentLevel,
|
||||
Nature = Experience.GetNatureVC(EXP),
|
||||
PID = Util.Rand32(),
|
||||
PID = rnd.Rand32(),
|
||||
Ball = 4,
|
||||
MetDate = DateTime.Now,
|
||||
Version = (int)GameVersion.RD, // Default to red
|
||||
@@ -200,7 +201,6 @@ public PK7 ConvertToPK7()
|
||||
// IVs
|
||||
Span<int> finalIVs = stackalloc int[6];
|
||||
int flawless = Species == (int)Core.Species.Mew ? 5 : 3;
|
||||
var rnd = Util.Rand;
|
||||
for (var i = 0; i < finalIVs.Length; i++)
|
||||
finalIVs[i] = rnd.Next(32);
|
||||
for (var i = 0; i < flawless; i++)
|
||||
|
||||
@@ -131,16 +131,17 @@ public PK1 ConvertToPK1()
|
||||
|
||||
public PK7 ConvertToPK7()
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
var pk7 = new PK7
|
||||
{
|
||||
EncryptionConstant = Util.Rand32(),
|
||||
EncryptionConstant = rnd.Rand32(),
|
||||
Species = Species,
|
||||
TID = TID,
|
||||
CurrentLevel = CurrentLevel,
|
||||
EXP = EXP,
|
||||
Met_Level = CurrentLevel,
|
||||
Nature = Experience.GetNatureVC(EXP),
|
||||
PID = Util.Rand32(),
|
||||
PID = rnd.Rand32(),
|
||||
Ball = 4,
|
||||
MetDate = DateTime.Now,
|
||||
Version = HasOriginalMetLocation ? (int)GameVersion.C : (int)GameVersion.SI,
|
||||
@@ -172,7 +173,6 @@ public PK7 ConvertToPK7()
|
||||
var special = Species is 151 or 251;
|
||||
Span<int> finalIVs = stackalloc int[6];
|
||||
int flawless = special ? 5 : 3;
|
||||
var rnd = Util.Rand;
|
||||
for (var i = 0; i < finalIVs.Length; i++)
|
||||
finalIVs[i] = rnd.Next(32);
|
||||
for (var i = 0; i < flawless; i++)
|
||||
|
||||
@@ -944,7 +944,7 @@ public void SetPIDNature(int nature)
|
||||
public void SetPIDUnown3(int form)
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
do PID = Util.Rand32(rnd); while (PKX.GetUnownForm(PID) != form);
|
||||
do PID = rnd.Rand32(); while (PKX.GetUnownForm(PID) != form);
|
||||
if (Format >= 6 && (Gen3 || Gen4 || Gen5))
|
||||
EncryptionConstant = PID;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public sealed override int Form
|
||||
return;
|
||||
var rnd = Util.Rand;
|
||||
while (PKX.GetUnownForm(PID) != value)
|
||||
PID = Util.Rand32(rnd);
|
||||
PID = rnd.Rand32();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin,
|
||||
{
|
||||
// Gen6+ (and VC) PIDs do not tie PID to Nature/Gender/Ability
|
||||
if (origin >= 24)
|
||||
return Util.Rand32(rnd);
|
||||
return rnd.Rand32();
|
||||
|
||||
// Below logic handles Gen3-5.
|
||||
|
||||
@@ -136,7 +136,7 @@ public static uint GetRandomPID(Random rnd, int species, int gender, int origin,
|
||||
bool singleGender = PersonalInfo.IsSingleGender(gt); // single gender, skip gender check
|
||||
while (true) // Loop until we find a suitable PID
|
||||
{
|
||||
uint pid = Util.Rand32(rnd);
|
||||
uint pid = rnd.Rand32();
|
||||
|
||||
// Gen 3/4: Nature derived from PID
|
||||
if (g34 && pid%25 != nature)
|
||||
|
||||
@@ -141,8 +141,11 @@ public string FileNameWithoutExtension
|
||||
|
||||
public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
var pk = new PB7
|
||||
{
|
||||
EncryptionConstant = rnd.Rand32(),
|
||||
PID = rnd.Rand32(),
|
||||
Version = (int) GameVersion.GO,
|
||||
Species = Species,
|
||||
Form = Form,
|
||||
@@ -157,7 +160,6 @@ public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
OT_Name = sav.OT,
|
||||
Ball = 4,
|
||||
Language = sav.Language,
|
||||
PID = Util.Rand32(),
|
||||
};
|
||||
|
||||
var nick = Nickname;
|
||||
@@ -198,7 +200,6 @@ public PB7 ConvertToPB7(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
pk.AwakeningSetAllTo(2);
|
||||
pk.ResetCalculatedValues();
|
||||
|
||||
pk.SetRandomEC();
|
||||
return pk;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user