diff --git a/pk3DS.Core/Randomizers/PersonalRandomizer.cs b/pk3DS.Core/Randomizers/PersonalRandomizer.cs index b59be51..4898534 100644 --- a/pk3DS.Core/Randomizers/PersonalRandomizer.cs +++ b/pk3DS.Core/Randomizers/PersonalRandomizer.cs @@ -8,7 +8,7 @@ namespace pk3DS.Core.Randomizers { public class PersonalRandomizer : IRandomizer { - private static readonly Random rnd = new Random(); + private readonly Random rnd = Util.rand; private const decimal LearnTMPercent = 35; // Average Learnable TMs is 35.260. private const decimal LearnTypeTutorPercent = 2; //136 special tutor moves learnable by species in Untouched ORAS. diff --git a/pk3DS.Core/Structures/Gen6/EncounterStatic6.cs b/pk3DS.Core/Structures/Gen6/EncounterStatic6.cs index cad65d2..03a19b8 100644 --- a/pk3DS.Core/Structures/Gen6/EncounterStatic6.cs +++ b/pk3DS.Core/Structures/Gen6/EncounterStatic6.cs @@ -9,11 +9,20 @@ public class EncounterStatic6 public ushort Species { - get { return BitConverter.ToUInt16(Data, 0x0); } - set { BitConverter.GetBytes(value).CopyTo(Data, 0x0); } + get => BitConverter.ToUInt16(Data, 0x0); + set => BitConverter.GetBytes(value).CopyTo(Data, 0x0); + } + + public byte Form + { + get => Data[0x2]; + set => Data[0x2] = value; + } + public byte Level + { + get => Data[0x3]; + set => Data[0x3] = value; } - public byte Form { get { return Data[0x2]; } set { Data[0x2] = value; } } - public byte Level { get { return Data[0x3]; } set { Data[0x3] = value; } } public int HeldItem { get @@ -29,20 +38,34 @@ public int HeldItem } } - public bool ShinyLock { get { return (Data[0x6] & 2) >> 1 == 1; } set { Data[0x6] = (byte)(Data[0x6] & ~2 | (value ? 2 : 0)); } } - public int Gender { get { return (Data[0x6] & 0xC) >> 2; } set { Data[0x6] = (byte)(Data[0x6] & ~0xC | ((value & 3) << 2)); } } - public int Ability { get { return (Data[0x6] & 0x70) >> 4; } set { Data[0x6] = (byte)(Data[0x6] & ~0x70 | ((value & 7) << 4)); } } - - public bool IV3 { get { return (Data[0x7] & 1) >> 0 == 1; } set { Data[0x7] = (byte)(Data[0x7] & ~1 | (value ? 1 : 0)); } } - public bool IV3_1 { get { return (Data[0x7] & 2) >> 1 == 1; } set { Data[0x7] = (byte)(Data[0x7] & ~2 | (value ? 2 : 0)); } } - - public EncounterStatic6(byte[] data) + public bool ShinyLock { - Data = (byte[])data.Clone(); + get => (Data[0x6] & 2) >> 1 == 1; + set => Data[0x6] = (byte)(Data[0x6] & ~2 | (value ? 2 : 0)); } - public byte[] Write() + public int Gender { - return (byte[])Data.Clone(); + get => (Data[0x6] & 0xC) >> 2; + set => Data[0x6] = (byte)(Data[0x6] & ~0xC | ((value & 3) << 2)); } + + public int Ability + { + get => (Data[0x6] & 0x70) >> 4; + set => Data[0x6] = (byte)(Data[0x6] & ~0x70 | ((value & 7) << 4)); + } + public bool IV3 + { + get => (Data[0x7] & 1) >> 0 == 1; + set => Data[0x7] = (byte)(Data[0x7] & ~1 | (value ? 1 : 0)); + } + public bool IV3_1 + { + get => (Data[0x7] & 2) >> 1 == 1; + set => Data[0x7] = (byte)(Data[0x7] & ~2 | (value ? 2 : 0)); + } + + public EncounterStatic6(byte[] data) => Data = (byte[])data.Clone(); + public byte[] Write() => (byte[])Data.Clone(); } } diff --git a/pk3DS.Core/Structures/Gen7/EncounterStatic7.cs b/pk3DS.Core/Structures/Gen7/EncounterStatic7.cs index c00b911..25cb686 100644 --- a/pk3DS.Core/Structures/Gen7/EncounterStatic7.cs +++ b/pk3DS.Core/Structures/Gen7/EncounterStatic7.cs @@ -52,12 +52,14 @@ public int Gender set => Data[0x6] = (byte)(Data[0x6] & ~0xC | ((value & 3) << 2)); } public int Ability - { get => (Data[0x6] & 0x70) >> 4; + { + get => (Data[0x6] & 0x70) >> 4; set => Data[0x6] = (byte)(Data[0x6] & ~0x70 | ((value & 7) << 4)); } public bool _7 - { get => (Data[0x7] & 1) >> 0 == 1; + { + get => (Data[0x7] & 1) >> 0 == 1; set => Data[0x7] = (byte)(Data[0x7] & ~1 | (value ? 1 : 0)); } public bool _7_1 @@ -96,10 +98,7 @@ public int Nature public int[] IVs { - get => new int[] - { - (sbyte) Data[0x15], (sbyte) Data[0x16], (sbyte) Data[0x17], (sbyte) Data[0x18], (sbyte) Data[0x19], (sbyte) Data[0x1A] - }; + get => new int[] { (sbyte) Data[0x15], (sbyte) Data[0x16], (sbyte) Data[0x17], (sbyte) Data[0x18], (sbyte) Data[0x19], (sbyte) Data[0x1A] }; set { if (value.Length != 6) @@ -110,10 +109,7 @@ public int[] IVs } public int[] EVs { - get => new int[] - { - (byte) Data[0x1B], (byte) Data[0x1C], (byte) Data[0x1D], (byte) Data[0x1E], (byte) Data[0x1F], (byte) Data[0x20] - }; + get => new int[] { Data[0x1B], Data[0x1C], Data[0x1D], Data[0x1E], Data[0x1F], Data[0x20] }; set { if (value.Length != 6) diff --git a/pk3DS.Core/Util.cs b/pk3DS.Core/Util.cs index f016904..d5bcd92 100644 --- a/pk3DS.Core/Util.cs +++ b/pk3DS.Core/Util.cs @@ -33,11 +33,9 @@ public static string TrimFromZero(string input) } // Randomization - public static Random rand = new Random(); - public static uint rnd32() - { - return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); - } + public static Random rand { get; private set; } = new Random(); + public static void ReseedRand(int seed) => rand = new Random(seed); + public static uint rnd32() => (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); // Data Retrieval public static int ToInt32(string value) diff --git a/pk3DS/ARCUtil.cs b/pk3DS/ARCUtil.cs index c1b53be..045cab3 100644 --- a/pk3DS/ARCUtil.cs +++ b/pk3DS/ARCUtil.cs @@ -6,7 +6,7 @@ namespace pk3DS.ARCUtil { - public class ARC + public static class ARC { // Multi Type Archive Handling internal static bool onefile = true; diff --git a/pk3DS/Subforms/Gen6/MoveEditor6.cs b/pk3DS/Subforms/Gen6/MoveEditor6.cs index a200a52..49738b5 100644 --- a/pk3DS/Subforms/Gen6/MoveEditor6.cs +++ b/pk3DS/Subforms/Gen6/MoveEditor6.cs @@ -174,7 +174,7 @@ private void B_RandAll_Click(object sender, EventArgs e) } if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Moves? Cannot undo.", "Double check options on the right before continuing.") != DialogResult.Yes) return; - Random rnd = new Random(); + Random rnd = Util.rand; for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; // Get new Move diff --git a/pk3DS/Subforms/Gen6/RSTE.cs b/pk3DS/Subforms/Gen6/RSTE.cs index db32d6f..ea82437 100644 --- a/pk3DS/Subforms/Gen6/RSTE.cs +++ b/pk3DS/Subforms/Gen6/RSTE.cs @@ -131,11 +131,7 @@ public RSTE(byte[][] trc, byte[][] trd, byte[][] trp) Setup(); } private string[][] AltForms; - internal static readonly Random rand = new Random(); - internal static uint rnd32() - { - return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); - } + internal static uint rnd32() => Util.rnd32(); private bool start = true; private bool loading = true; private int index = -1; diff --git a/pk3DS/Subforms/Gen6/RSWE.cs b/pk3DS/Subforms/Gen6/RSWE.cs index 93fca68..e21bd2f 100644 --- a/pk3DS/Subforms/Gen6/RSWE.cs +++ b/pk3DS/Subforms/Gen6/RSWE.cs @@ -304,11 +304,7 @@ private void RSWE_Load() //Preload Tabs PreloadTabs(); } - internal static Random rand = new Random(); - internal static uint rnd32() - { - return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); - } + internal static uint rnd32() => Util.rnd32(); private void openQuick(string[] encdata) { diff --git a/pk3DS/Subforms/Gen6/StaticEncounterEditor6.cs b/pk3DS/Subforms/Gen6/StaticEncounterEditor6.cs index 3fdde0b..07db88a 100644 --- a/pk3DS/Subforms/Gen6/StaticEncounterEditor6.cs +++ b/pk3DS/Subforms/Gen6/StaticEncounterEditor6.cs @@ -59,7 +59,7 @@ private void loadData() for (int i = 0; i < EncounterData.Length; i++) { EncounterData[i] = new EncounterStatic6(FieldData.Skip(fieldOffset + i * fieldSize).Take(fieldSize).ToArray()); - LB_Encounters.Items.Add($"{i.ToString("00")} - {specieslist[EncounterData[i].Species]}"); + LB_Encounters.Items.Add($"{i:00} - {specieslist[EncounterData[i].Species]}"); } loaded = true; LB_Encounters.SelectedIndex = 0; diff --git a/pk3DS/Subforms/Gen6/XYWE.cs b/pk3DS/Subforms/Gen6/XYWE.cs index 8ab384a..a55c58c 100644 --- a/pk3DS/Subforms/Gen6/XYWE.cs +++ b/pk3DS/Subforms/Gen6/XYWE.cs @@ -495,11 +495,8 @@ private void PreloadTabs(object sender, EventArgs e) } TabControl_EncounterData.TabPages[0].Show(); } - internal static Random rand = new Random(); - internal static uint rnd32() - { - return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); - } + + internal static uint rnd32() => Util.rnd32(); private void B_Randomize_Click(object sender, EventArgs e) { diff --git a/pk3DS/Subforms/Gen7/MoveEditor7.cs b/pk3DS/Subforms/Gen7/MoveEditor7.cs index 289f72c..761c0c1 100644 --- a/pk3DS/Subforms/Gen7/MoveEditor7.cs +++ b/pk3DS/Subforms/Gen7/MoveEditor7.cs @@ -175,7 +175,7 @@ private void B_RandAll_Click(object sender, EventArgs e) } if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Moves? Cannot undo.", "Double check options on the right before continuing.") != DialogResult.Yes) return; - Random rnd = new Random(); + Random rnd = Util.rand; for (int i = 0; i < CB_Move.Items.Count; i++) { CB_Move.SelectedIndex = i; // Get new Move diff --git a/pk3DS/Subforms/Gen7/StaticEncounterEditor7.cs b/pk3DS/Subforms/Gen7/StaticEncounterEditor7.cs index 33c7e2e..020c7a0 100644 --- a/pk3DS/Subforms/Gen7/StaticEncounterEditor7.cs +++ b/pk3DS/Subforms/Gen7/StaticEncounterEditor7.cs @@ -176,7 +176,7 @@ private void saveData() private string getEntryText(int species, int entry) { - return $"{entry.ToString("00")} - {specieslist[species]}"; + return $"{entry:00} - {specieslist[species]}"; } private string getEntryText(EncounterStatic enc, int entry) {