diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot9.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot9.cs index 9be015153..86ad852d2 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot9.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot9.cs @@ -21,13 +21,16 @@ protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteri var pk9 = (PK9)pk; pk9.Obedience_Level = (byte)pk.Met_Level; - var type = Tera9RNG.GetTeraTypeFromPersonal(Species, Form, Util.Rand.Rand64()); + var rand = new Xoroshiro128Plus(Util.Rand.Rand64()); + var type = Tera9RNG.GetTeraTypeFromPersonal(Species, Form, rand.Next()); pk9.TeraTypeOriginal = (MoveType)type; if (criteria.TeraType != -1 && type != criteria.TeraType) pk9.SetTeraType(type); // sets the override type if (Gender != -1) pk.Gender = (byte)Gender; pk9.Scale = PokeSizeUtil.GetRandomScalar(); + if (Species == (int)Core.Species.Toxtricity) + pk.Nature = ToxtricityUtil.GetRandomNature(ref rand, Form); pk9.EncryptionConstant = Util.Rand32(); } } diff --git a/PKHeX.Core/Legality/RNG/Methods/Encounter9RNG.cs b/PKHeX.Core/Legality/RNG/Methods/Encounter9RNG.cs index 963878440..4f0b3108c 100644 --- a/PKHeX.Core/Legality/RNG/Methods/Encounter9RNG.cs +++ b/PKHeX.Core/Legality/RNG/Methods/Encounter9RNG.cs @@ -122,7 +122,9 @@ public static bool GenerateData(PK9 pk, in GenerateParam9 enc, EncounterCriteria return false; pk.Gender = gender; - var nature = (int)rand.NextInt(25); + byte nature = pk.Species == (int)Species.Toxtricity + ? ToxtricityUtil.GetRandomNature(ref rand, pk.Form) + : (byte)rand.NextInt(25); if (criteria.Nature != Nature.Random && nature != (int)criteria.Nature) return false; pk.Nature = pk.StatNature = nature; @@ -223,7 +225,9 @@ public static bool IsMatch(PKM pk, in GenerateParam9 enc, in ulong seed) if (pk.Gender != gender) return false; - var nature = (int)rand.NextInt(25); + int nature = pk.Species == (int)Species.Toxtricity + ? ToxtricityUtil.GetRandomNature(ref rand, pk.Form) + : (byte)rand.NextInt(25); if (pk.Nature != nature) return false; diff --git a/PKHeX.Core/Legality/RNG/Methods/ToxtricityUtil.cs b/PKHeX.Core/Legality/RNG/Methods/ToxtricityUtil.cs new file mode 100644 index 000000000..29a33e09a --- /dev/null +++ b/PKHeX.Core/Legality/RNG/Methods/ToxtricityUtil.cs @@ -0,0 +1,13 @@ +namespace PKHeX.Core; + +public static class ToxtricityUtil +{ + private static readonly byte[] Nature0 = { 3, 4, 2, 8, 9, 19, 22, 11, 13, 14, 0, 6, 24 }; + private static readonly byte[] Nature1 = { 1, 5, 7, 10, 12, 15, 16, 17, 18, 20, 21, 23 }; + + public static byte GetRandomNature(ref Xoroshiro128Plus rand, byte form) + { + var table = form == 0 ? Nature0 : Nature1; + return table[rand.NextInt((uint)table.Length)]; + } +} diff --git a/PKHeX.Core/Legality/RNG/RaidRNG.cs b/PKHeX.Core/Legality/RNG/RaidRNG.cs index 95126b7a9..4973cbfc8 100644 --- a/PKHeX.Core/Legality/RNG/RaidRNG.cs +++ b/PKHeX.Core/Legality/RNG/RaidRNG.cs @@ -143,34 +143,12 @@ private static bool Verify(PKM pk, ulong seed, Span ivs, int iv_count, int break; } - if (nature_param == -1) - { - if (pk.Species == (int) Species.Toxtricity && pk.Form == 0) - { - var table = Nature0; - var choice = table[rng.NextInt((uint)table.Length)]; - if (pk.Nature != choice) - return false; - } - else if (pk.Species == (int) Species.Toxtricity && pk.Form == 1) - { - var table = Nature1; - var choice = table[rng.NextInt((uint)table.Length)]; - if (pk.Nature != choice) - return false; - } - else - { - var nature = (int)rng.NextInt(25); - if (pk.Nature != nature) - return false; - } - } - else - { - if (pk.Nature != nature_param) - return false; - } + int nature = nature_param != -1 ? nature_param + : pk.Species == (int)Species.Toxtricity + ? ToxtricityUtil.GetRandomNature(ref rng, pk.Form) + : (byte)rng.NextInt(25); + if (pk.Nature != nature) + return false; if (pk is IScaledSize s) { @@ -272,28 +250,10 @@ private static bool ApplyDetailsTo(PKM pk, ulong seed, Span ivs, int iv_cou _ => (int) rng.NextInt(252) + 1 < gender_ratio ? 1 : 0, }; - int nature; - if (nature_param == -1) - { - if (pk.Species == (int)Species.Toxtricity && pk.Form == 0) - { - var table = Nature0; - nature = table[rng.NextInt((uint)table.Length)]; - } - else if (pk.Species == (int)Species.Toxtricity && pk.Form == 1) - { - var table = Nature1; - nature = table[rng.NextInt((uint)table.Length)]; - } - else - { - nature = (int)rng.NextInt(25); - } - } - else - { - nature = nature_param; - } + int nature = nature_param != -1 ? nature_param + : pk.Species == (int)Species.Toxtricity + ? ToxtricityUtil.GetRandomNature(ref rng, pk.Form) + : (byte)rng.NextInt(25); pk.StatNature = pk.Nature = nature; @@ -323,7 +283,4 @@ private static uint GetShinyXor(uint pid, uint oid) var xor = pid ^ oid; return (xor ^ (xor >> 16)) & 0xFFFF; } - - private static readonly byte[] Nature0 = {3, 4, 2, 8, 9, 19, 22, 11, 13, 14, 0, 6, 24}; - private static readonly byte[] Nature1 = {1, 5, 7, 10, 12, 15, 16, 17, 18, 20, 21, 23}; }