private void B_Randomize_Click(object sender, EventArgs e) { if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, "Randomize mart inventories?")) { return; } int[] validItems = Randomizer.getRandomItemList(); int ctr = 0; Util.Shuffle(validItems); bool specialOnly = DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize only special marts?", "Will leave regular necessities intact."); int start = specialOnly ? 8 : 0; for (int i = start; i < CB_Location.Items.Count; i++) { CB_Location.SelectedIndex = i; for (int r = 0; r < dgv.Rows.Count; r++) { dgv.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } } WinFormsUtil.Alert("Randomized!"); }
private void B_RandomTM_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize TMs?", "Move compatibility will be the same as the base TMs.") != DialogResult.Yes) { return; } int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int[] banned = Legal.Z_Moves.Concat(new int[] { 165, 464, 621 }).ToArray(); int ctr = 0; for (int i = 0; i < dgvTM.Rows.Count; i++) { int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); if (banned.Contains(val)) { continue; } while (banned.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } WinFormsUtil.Alert("Randomized!"); }
private void B_Randomize_Click(object sender, EventArgs e) { if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNoCancel, "Randomize mart inventories?")) { return; } int[] validItems = Randomizer.getRandomItemList(); int ctr = 0; Util.Shuffle(validItems); for (int i = 0; i < CB_Location.Items.Count; i++) { CB_Location.SelectedIndex = i; for (int r = 0; r < dgv.Rows.Count; r++) { dgv.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } } }
private void RandomizeBPItems() { if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, "Randomize BP inventories?")) { return; } int[] validItems = Randomizer.GetRandomItemList(); int ctr = 0; Util.Shuffle(validItems); for (int i = 0; i < CB_LocationBPItem.Items.Count; i++) { CB_LocationBPItem.SelectedIndex = i; for (int r = 0; r < dgvbp.Rows.Count; r++) { dgvbp.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } } WinFormsUtil.Alert("Randomized!"); }
private void B_Randomize_Click(object sender, EventArgs e) { if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNoCancel, "Randomize pickup lists?")) { return; } int[] validItems = Randomizer.getRandomItemList(); int ctr = 0; Util.Shuffle(validItems); for (int r = 0; r < dgvCommon.Rows.Count; r++) { dgvCommon.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } for (int r = 0; r < dgvRare.Rows.Count; r++) { dgvRare.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } }
private void B_RandomTM_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize TMs?", "Move compatibility will be the same as the base TMs.") != DialogResult.Yes) { return; } if (CHK_RandomizeHM.Checked) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomizing HMs can halt story progression!", "Continue anyway?") != DialogResult.Yes) { return; } } int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int[] hm_xy = { 015, 019, 057, 070, 127 }; // Cut, Fly, Surf, Strength, Waterfall int[] hm_oras = { 015, 019, 057, 070, 127, 249, 291 }; // + Rock Smash, Dive int[] field = { 148, 249, 290 }; // Flash (TM70), Rock Smash (XY TM94), Secret Power (ORAS TM94) int[] banned = { 165, 464 }; // Struggle and Hyperspace Fury int ctr = 0; for (int i = 0; i < dgvTM.Rows.Count; i++) { int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); if (banned.Contains(val)) { continue; } if (CHK_RandomizeField.Checked) { dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; // randomize everything } else { if (hm_xy.Contains(val) || hm_oras.Contains(val) || field.Contains(val)) { continue; // skip HMs and Field Moves } while (hm_xy.Contains(randomMoves[ctr]) || hm_oras.Contains(randomMoves[ctr]) || field.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } } if (CHK_RandomizeHM.Checked) { for (int i = 0; i < dgvHM.Rows.Count; i++) { dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; dgvHM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } } WinFormsUtil.Alert("Randomized!"); }
internal static int getRandomSpecies(ref int[] list, ref int ctr) { if (ctr == 0) { Util.Shuffle(list); } int species = list[ctr++]; ctr %= list.Length; return(species); }
private void B_RandAll_Click(object sender, EventArgs e) { /* * 3111 Egg Moves Learned by 290 Species (10.73 avg) * 18 is the most * 1000 moves learned were STAB (32.1%) */ Random rnd = new Random(); int[] banned = new[] { 165, 621, 464 }.Concat(Legal.Z_Moves).ToArray(); // Struggle, Hyperspace Fury, Dark Void // Move Stats Move[] moveTypes = Main.Config.Moves; // Set up Randomized Moves int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int ctr = 0; for (int i = 0; i < CB_Species.Items.Count; i++) { CB_Species.SelectedIndex = i; // Get new Species int count = dgv.Rows.Count - 1; int species = Util.getIndex(CB_Species); if (CHK_Expand.Checked && (int)NUD_Moves.Value > count) { dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count); } for (int j = 1; j < dgv.Rows.Count - 1; j++) { // Assign New Moves bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value; int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); while (banned.Contains(move) || /* Invalid */ (forceSTAB && !Main.SpeciesStat[species].Types.Contains(moveTypes[move].Type))) // STAB is required { move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); } // Assign Move dgv.Rows[j].Cells[0].Value = movelist[move]; } } CB_Species.SelectedIndex = 0; Util.Alert("All Pokemon's Egg Up Moves have been randomized!"); }
private void B_RandomTM_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize TMs?", "Move compatibility will be the same as the base TMs.") != DialogResult.Yes) { return; } if (CHK_RandomizeHM.Checked) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomizing HMs can halt story progression!", "Continue anyway?") != DialogResult.Yes) { return; } } int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int[] banned = { 15, 19, 57, 70, 127, 249, 291, 148, 290 }; // Moves with overworld effects int ctr = 0; for (int i = 0; i < dgvTM.Rows.Count; i++) { int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); if (banned.Contains(val)) { continue; } while (banned.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } if (CHK_RandomizeHM.Checked) { for (int i = 0; i < dgvHM.Rows.Count; i++) { dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; dgvHM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } } WinFormsUtil.Alert("Randomized!"); }
private void RandomizeItems() { if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, "Randomize mart inventories?")) { return; } int[] validItems = Randomizer.GetRandomItemList(); int ctr = 0; Util.Shuffle(validItems); bool specialOnly = DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize only special marts?", "Will leave regular necessities intact."); int start = specialOnly ? 8 : 0; for (int i = start; i < CB_Location.Items.Count; i++) { CB_Location.SelectedIndex = i; for (int r = 0; r < dgv.Rows.Count; r++) { int currentItem = Array.IndexOf(itemlist, dgv.Rows[r].Cells[1].Value); if (CHK_XItems.Checked && XItems.Contains(currentItem)) { continue; } if (BannedItems.Contains(currentItem)) { continue; } dgv.Rows[r].Cells[1].Value = itemlist[validItems[ctr++]]; if (ctr <= validItems.Length) { continue; } Util.Shuffle(validItems); ctr = 0; } } WinFormsUtil.Alert("Randomized!"); }
private void B_RandomTM_Click(object sender, EventArgs e) { int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int[] banned = { 15, 19, 57, 70, 127, 249, 291, 148 }; int ctr = 0; for (int i = 0; i < dgvTM.Rows.Count; i++) { int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); if (banned.Contains(val)) { continue; } while (banned.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } }
// Randomization private void B_Randomize_Click(object sender, EventArgs e) { if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings @ Horde Tab.") != DialogResult.Yes) { return; } Enabled = false; // Calculate % diff we will apply to each level decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100; // Nonrepeating List Start int[] sL = Randomizer.getSpeciesList(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked, CHK_G4.Checked, CHK_G5.Checked, CHK_G6.Checked, CHK_L.Checked, CHK_E.Checked); int ctr = 0; int[] slotArray = Enumerable.Range(0, max.Length).Select(a => a).ToArray(); for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location { CB_LocationID.SelectedIndex = i; if (!hasData()) { continue; // Don't randomize if doesn't have data. } // Assign Levels if (CHK_Level.Checked) { for (int l = 0; l < max.Length; l++) { min[l].Value = max[l].Value = (max[l].Value <= 1) ? max[l].Value : Math.Max(1, Math.Min(100, (int)((leveldiff) * max[l].Value))); } } // Get a new list of Pokemon so that DexNav does not crash. int[] list = new int[max.Length]; int used = 19; // Count up how many slots are active. for (int s = 0; s < max.Length; s++) { if (spec[s].SelectedIndex > 0) { list[s] = spec[s].SelectedIndex; } } // At most 18, but don't chew if there's only a few slots. int cons = list.Count(a => a != 0); int[] RandomList = new int[(cons > 18) ? (18 - (cons / 8)) : cons]; // Fill Location List if (!CHK_BST.Checked) { for (int z = 0; z < RandomList.Length; z++) { RandomList[z] = Randomizer.getRandomSpecies(ref sL, ref ctr); } } else { int oldBST = 0; for (int s = 0; s < max.Length; s++) { if (spec[s].SelectedIndex > 0) { oldBST = personal[spec[s + 2].SelectedIndex].Take(6).Sum(b => (ushort)b); break; } } for (int z = 0; z < RandomList.Length; z++) { int species = Randomizer.getRandomSpecies(ref sL, ref ctr); int newBST = personal[species].Take(6).Sum(b => (ushort)b); while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST)) { species = sL[rand.Next(1, sL.Length)]; newBST = personal[species].Take(6).Sum(b => (ushort)b); } RandomList[z] = species; } } // Assign Slots while (used < RandomList.Distinct().Count() || used > 18) // Can just arbitrarily assign slots. { int ctrSingle = 0; Util.Shuffle(slotArray); for (int s = 0; s < max.Length; s++) { int slot = slotArray[s]; if (spec[slot].SelectedIndex != 0) // If the slot is in use { list[slot] = Randomizer.getRandomSpecies(ref RandomList, ref ctrSingle); } } used = countUnique(list); if (used != RandomList.Length) { ShuffleSlots(ref list, RandomList.Length); } used = countUnique(list); } // Fill Slots for (int slot = 0; slot < max.Length; slot++) { if (spec[slot].SelectedIndex != 0) { spec[slot].SelectedIndex = list[slot]; setRandomForm(slot, spec[slot].SelectedIndex); } } B_Save_Click(sender, e); } Enabled = true; Util.Alert("Randomized!"); }
private void B_Randomize_Click(object sender, EventArgs e) { Util.Alert("Randomization currently disabled"); return; if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all?", "Cannot undo.") == DialogResult.Yes) { bool smart = Util.Prompt(MessageBoxButtons.YesNo, "Smart Randomize by Base Stat Total?", "Pokemon strength variance will attempt to match ingame.") == DialogResult.Yes; this.Enabled = false; // Nonrepeating List Start int[] sL = Randomizer.RandomSpeciesList; int ctr = 0; int[] slotArray = Enumerable.Range(0, max.Length).Select(a => (int)a).ToArray(); for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location { CB_LocationID.SelectedIndex = i; if (!hasData()) { continue; // Don't randomize if doesn't have data. } // Get a new list of Pokemon so that DexNav does not crash. int[] list = new int[max.Length]; int used = 19; // Count up how many slots are active. for (int s = 0; s < max.Length; s++) { if (spec[s].SelectedIndex > 0) { list[s] = spec[s].SelectedIndex; } } // At most 18, but don't chew if there's only a few slots. int cons = list.Count(a => a != 0); int[] RandomList = new int[(cons > 18) ? (18 - (cons / 8)) : cons]; // Fill Location List if (!smart) { for (int z = 0; z < RandomList.Length; z++) { RandomList[z] = Randomizer.getRandomSpecies(ref sL, ref ctr); } } else { int oldBST = 0; for (int s = 0; s < max.Length; s++) { if (spec[s].SelectedIndex > 0) { oldBST = personal[spec[s + 2].SelectedIndex].Take(6).Sum(b => (ushort)b); break; } } for (int z = 0; z < RandomList.Length; z++) { int species = Randomizer.getRandomSpecies(ref sL, ref ctr); int newBST = personal[species].Take(6).Sum(b => (ushort)b); while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST)) { species = rand.Next(1, 722); newBST = personal[species].Take(6).Sum(b => (ushort)b); } RandomList[z] = species; } } // Assign Slots while (used < RandomList.Length || used > 18) // Can just arbitrarily assign slots. { int ctrSingle = 0; Util.Shuffle(slotArray); for (int s = 0; s < max.Length; s++) { int slot = slotArray[s]; if (spec[slot].SelectedIndex != 0) // If the slot is in use { list[slot] = Randomizer.getRandomSpecies(ref RandomList, ref ctrSingle); } } ShuffleSlots(ref list, RandomList.Length); used = countUnique(list); } // Fill Slots for (int slot = 0; slot < max.Length; slot++) { if (spec[slot].SelectedIndex != 0) { spec[slot].SelectedIndex = list[slot]; setRandomForm(slot, spec[slot].SelectedIndex); } } B_Save_Click(sender, e); } this.Enabled = true; Util.Alert("Randomized!"); } }
private void B_RandAll_Click(object sender, EventArgs e) { /* * 3111 Egg Moves Learned by 290 Species (10.73 avg) * 18 is the most * 1000 moves learned were STAB (32.1%) */ Random rnd = new Random(); ushort[] HMs = { 15, 19, 57, 70, 127, 249, 291 }; ushort[] TMs = { }; if (CHK_HMs.Checked && Main.ExeFSPath != null) { TMHM.getTMHMList(Main.oras, ref TMs, ref HMs); } int[] banned = new int[HMs.Length]; for (int i = 0; i < banned.Length; i++) { banned[i] = HMs[i]; } banned = banned.Concat(new[] { 165, 621 }).ToArray(); // Struggle, Hyperspace Fury // Move Stats Move[] moveTypes = Moves.getMoves(); // Personal Stats byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last()); // Set up Randomized Moves int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int ctr = 0; for (int i = 0; i < CB_Species.Items.Count; i++) { CB_Species.SelectedIndex = i; // Get new Species int count = dgv.Rows.Count - 1; int species = Util.getIndex(CB_Species); if (count == 0) { continue; } if (CHK_Expand.Checked && (int)NUD_Moves.Value > count) { dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count); } for (int j = 0; j < dgv.Rows.Count - 1; j++) { // Assign New Moves bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value; int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); while ( // Move is invalid (!CHK_HMs.Checked && banned.Contains(move)) || // HM Moves Not Allowed (forceSTAB && // STAB is required !( moveTypes[move].Type == personalData[6 + (Main.oras ? 0x50 : 0x40) * species] // Type 1 || moveTypes[move].Type == personalData[7 + (Main.oras ? 0x50 : 0x40) * species] // Type 2 ) ) ) { move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); } // Assign Move dgv.Rows[j].Cells[0].Value = movelist[move]; } } CB_Species.SelectedIndex = 0; Util.Alert("All Pokemon's Egg Moves have been randomized!"); }
private void B_Shuffle_Click(object sender, EventArgs e) { if (garc == null) { return; } string garcID = L_File.Text.Split(':')[1].Replace("\\", "").Replace(" ", ""); if (banlist.Contains(garcID)) { Util.Alert("GARC is prevented from being shuffled."); return; } var g = CTR.GARC.unpackGARC(garc); // Build a list of all the files we can relocate. int[] randFiles = new int[g.fatb.FileCount]; int ctr = 0; for (int i = 0; i < randFiles.Length; i++) { if (!g.fatb.Entries[i].IsFolder) { randFiles[ctr++] = i; } } Array.Resize(ref randFiles, ctr); if (ctr == 0) { Util.Alert("No files to shuffle...?"); return; } // Create backup string dest = "backup" + Path.DirectorySeparatorChar + $"PreShuffle {garcID}"; if (!File.Exists(dest)) { File.Copy(garc, dest); } var g2 = CTR.GARC.unpackGARC(garc); int[] newFileOffset = (int[])randFiles.Clone(); Util.Shuffle(newFileOffset); for (int i = 0; i < randFiles.Length; i++) { g.fatb.Entries[randFiles[i]] = g2.fatb.Entries[newFileOffset[i]]; } #region Re-write GARC Header information! using (var newGARC = File.OpenWrite(garc)) using (BinaryWriter gw = new BinaryWriter(newGARC)) { gw.Seek(7 * 4, SeekOrigin.Begin); // Skip GARC Header // Write GARC // gw.Write((uint)0x47415243); // GARC // gw.Write((uint)0x0000001C); // Header Length // gw.Write((ushort)0xFEFF); // Endianness BOM // gw.Write((ushort)0x0400); // Const (4) // gw.Write((uint)0x00000004); // Section Count (4) // gw.Write((uint)0x00000000); // Data Offset (temp) // gw.Write((uint)0x00000000); // File Length (temp) // gw.Write((uint)0x00000000); // Largest File Size (temp) // Write FATO gw.Write((uint)0x4641544F); // FATO gw.Write(g.fato.HeaderSize); // Header Size gw.Write(g.fato.EntryCount); // Entry Count gw.Write(g.fato.Padding); // Padding for (int i = 0; i < g.fato.Entries.Length; i++) { gw.Write((uint)g.fato.Entries[i].Offset); } // Write FATB gw.Write((uint)0x46415442); // FATB gw.Write(g.fatb.HeaderSize); // Header Size gw.Write(g.fatb.FileCount); // File Count foreach (var fe in g.fatb.Entries) { gw.Write(fe.Vector); foreach (var s in fe.SubEntries.Where(s => s.Exists)) { gw.Write((uint)s.Start); gw.Write((uint)s.End); gw.Write((uint)s.Length); } } } #endregion Util.Alert("GARC Shuffled!"); }
// Randomization private void B_Randomize_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Horde tab.") != DialogResult.Yes) { return; } Enabled = false; // Calculate % diff we will apply to each level decimal leveldiff = NUD_LevelAmp.Value; // Nonrepeating List Start var rand = new SpeciesRandomizer(Main.Config) { G1 = CHK_G1.Checked, G2 = CHK_G2.Checked, G3 = CHK_G3.Checked, G4 = CHK_G4.Checked, G5 = CHK_G5.Checked, G6 = CHK_G6.Checked, L = CHK_L.Checked, E = CHK_E.Checked, Shedinja = false, rBST = CHK_BST.Checked, }; rand.Initialize(); int[] slotArray = Enumerable.Range(0, max.Length).Select(a => a).ToArray(); for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location { CB_LocationID.SelectedIndex = i; if (!hasData()) { continue; // Don't randomize if doesn't have data. } // Assign Levels if (CHK_Level.Checked) { for (int l = 0; l < max.Length; l++) { min[l].Value = max[l].Value = max[l].Value <= 1 ? max[l].Value : Math.Max(1, Math.Min(100, (int)(leveldiff * max[l].Value))); } } // Get a new list of Pokemon so that DexNav does not crash. int[] list = new int[max.Length]; int used = 19; // Count up how many slots are active. for (int s = 0; s < max.Length; s++) { if (spec[s].SelectedIndex > 0) { list[s] = spec[s].SelectedIndex; } } // At most 18, but don't chew if there's only a few slots. int cons = list.Count(a => a != 0); int[] RandomList = new int[cons > 18 ? 18 - cons / 8 : cons]; // Fill Location List for (int s = 0; s < RandomList.Length; s++) { RandomList[s] = rand.GetRandomSpecies(spec[s].SelectedIndex); } // Assign Slots while (used < RandomList.Distinct().Count() || used > 18) // Can just arbitrarily assign slots. { Util.Shuffle(slotArray); for (int s = 0; s < max.Length; s++) { int slot = slotArray[s]; if (spec[slot].SelectedIndex != 0) // If the slot is in use { list[slot] = RandomList[Util.rand.Next(0, RandomList.Length)]; } } used = countUnique(list); if (used != RandomList.Length) { ShuffleSlots(ref list, RandomList.Length); } used = countUnique(list); } // If Distinct Hordes are selected, homogenize int hordeslot = 0; if (CHK_HomogeneousHordes.Checked) { for (int slot = max.Length - 15; slot < max.Length; slot++) { list[slot] = list[slot - hordeslot % 5]; hordeslot++; } } // Fill Slots for (int slot = 0; slot < max.Length; slot++) { if (spec[slot].SelectedIndex != 0) { spec[slot].SelectedIndex = list[slot]; setRandomForm(slot, spec[slot].SelectedIndex); } } B_Save_Click(sender, e); } Enabled = true; WinFormsUtil.Alert("Randomized all Wild Encounters according to specification!", "Press the Dump Tables button to view the new Wild Encounter information!"); }
private void B_Randomize_Click(object sender, EventArgs e) { // gametext can be horribly broken if randomized if (Mode == "gametext" && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomizing Game Text is dangerous!", "Continue?")) { return; } // get if the user wants to randomize current text file or all files var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, $"Yes: Randomize ALL{Environment.NewLine}No: Randomize current textfile{Environment.NewLine}Cancel: Abort"); if (dr == DialogResult.Cancel) { return; } // get if pure shuffle or smart shuffle (no shuffle if variable present) var drs = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Smart shuffle:{Environment.NewLine}Yes: Shuffle if no Variable present{Environment.NewLine}No: Pure random!"); if (drs == DialogResult.Cancel) { return; } bool all = dr == DialogResult.Yes; bool smart = drs == DialogResult.Yes; // save current if (entry > -1) { files[entry] = getCurrentDGLines(); } // single-entire looping int start = all ? 0 : entry; int end = all ? files.Length - 1 : entry; // Gather strings List <string> strings = new List <string>(); for (int i = start; i <= end; i++) { string[] data = files[i]; strings.AddRange(smart ? data.Where(line => !line.Contains("[")) : data); } // Shuffle up string[] pool = strings.ToArray(); Util.Shuffle(pool); // Apply Text int ctr = 0; for (int i = start; i <= end; i++) { string[] data = files[i]; for (int j = 0; j < data.Length; j++) // apply lines { if (!smart || !data[j].Contains("[")) { data[j] = pool[ctr++]; } } files[i] = data; } // Load current text file setStringsDataGridView(files[entry]); WinFormsUtil.Alert("Strings randomized!"); }
private void B_RandomTM_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize TMs? Cannot undo.", "Move compatibility will be the same as the base TMs.") != DialogResult.Yes) { return; } if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomizing HMs can halt story progression!", "Continue anyway?") != DialogResult.Yes) { return; } int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int[] hm_xy = { 015, 019, 057, 070, 127 }; int[] hm_ao = hm_xy.Concat(new int[] { 249, 291 }).ToArray(); int[] field = { 148, 249, 290 }; // TMs with field effects int[] banned = { 165, 621 }; // Struggle and Hyperspace Fury int ctr = 0; for (int i = 0; i < dgvTM.Rows.Count; i++) { // randomize all TMs if (CHK_RandomizeField.Checked) { while (banned.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } // randomize all TMs, no Field Moves else { int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value); if (hm_xy.Contains(val) || hm_ao.Contains(val) || field.Contains(val)) { continue; // skip banned moves } while (hm_xy.Contains(randomMoves[ctr]) || hm_ao.Contains(randomMoves[ctr]) || field.Contains(randomMoves[ctr]) || banned.Contains(randomMoves[ctr])) { ctr++; } dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]]; } } if (CHK_RandomizeHM.Checked) { for (int j = 0; j < dgvHM.Rows.Count; j++) { while (banned.Contains(randomMoves[ctr])) { ctr++; } dgvHM.Rows[j].Cells[1].Value = movelist[randomMoves[ctr++]]; } } WinFormsUtil.Alert("Randomized!"); }
private void B_RandAll_Click(object sender, EventArgs e) { // ORAS: 10682 moves learned on levelup/birth. // 5593 are STAB. 52.3% are STAB. // Steelix learns the most @ 25 (so many level 1)! // Move relearner ingame glitch fixed (52 tested), but keep below 75: // https://twitter.com/Drayano60/status/807297858244411397 Random rnd = new Random(); int[] firstMoves = { 1, 40, 52, 55, 64, 71, 84, 98, 122, 141 }; // Pound, Poison Sting, Ember, Water Gun, Peck, Absorb, Thunder Shock, Quick Attack, Lick, Leech Life int[] banned = new[] { 165, 621, 464 }.Concat(Legal.Z_Moves).ToArray(); // Struggle, Hyperspace Fury, Dark Void // Move Stats Move[] moveTypes = Main.Config.Moves; // Set up Randomized Moves int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int ctr = 0; for (int i = 0; i < CB_Species.Items.Count; i++) { CB_Species.SelectedIndex = i; // Get new Species int count = dgv.Rows.Count - 1; int species = WinFormsUtil.getIndex(CB_Species); if (CHK_Expand.Checked && (int)NUD_Moves.Value > count) { dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count); } // Default First Move dgv.Rows[0].Cells[0].Value = 1; dgv.Rows[0].Cells[1].Value = movelist[firstMoves[rnd.Next(0, firstMoves.Length)]]; for (int j = 1; j < dgv.Rows.Count - 1; j++) { // Assign New Moves bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value; int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); while (banned.Contains(move) || /* Invalid */ forceSTAB && !Main.SpeciesStat[species].Types.Contains(moveTypes[move].Type)) // STAB is required { move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); } // Assign Move dgv.Rows[j].Cells[1].Value = movelist[move]; // Assign Level if (j >= count) { string level = (dgv.Rows[count - 1].Cells[0].Value ?? 0).ToString(); ushort lv; UInt16.TryParse(level, out lv); if (lv > 100) { lv = 100; } dgv.Rows[j].Cells[0].Value = lv + (j - count) + 1; } if (CHK_Spread.Checked) { dgv.Rows[j].Cells[0].Value = ((int)(j * (NUD_Level.Value / (dgv.Rows.Count - 1)))).ToString(); } } } CB_Species.SelectedIndex = 0; WinFormsUtil.Alert("All Pokemon's Level Up Moves have been randomized!"); }
private void B_RandAll_Click(object sender, EventArgs e) { // ORAS: 10682 moves learned on levelup/birth. // 5593 are STAB. 52.3% are STAB. // Steelix learns the most @ 25 (so many level 1)! // Move relearner ingame does not behave properly if the count exceeds 25: // https://twitter.com/Drayano60/status/630044237883666433 Random rnd = new Random(); int[] firstMoves = { 1, 40, 52, 55, 64, 71, 84, 98, 122, 141 }; // Pound, Poison Sting, Ember, Water Gun, Peck, Absorb, Thunder Shock, Quick Attack, Lick, Leech Life ushort[] HMs = { 15, 19, 57, 70, 127, 249, 291 }; ushort[] TMs = {}; if (CHK_HMs.Checked && Main.ExeFSPath != null) { TMHMEditor6.getTMHMList(Main.Config.ORAS, ref TMs, ref HMs); } int[] banned = new int[HMs.Length]; for (int i = 0; i < banned.Length; i++) { banned[i] = HMs[i]; } banned = banned.Concat(new[] { 165, 621 }).ToArray(); // Struggle, Hyperspace Fury // Move Stats Move[] moveTypes = Main.Config.Moves; // Set up Randomized Moves int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int ctr = 0; for (int i = 0; i < CB_Species.Items.Count; i++) { CB_Species.SelectedIndex = i; // Get new Species int count = dgv.Rows.Count - 1; int species = WinFormsUtil.getIndex(CB_Species); if (CHK_Expand.Checked && (int)NUD_Moves.Value > count) { dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count); } // Default First Move dgv.Rows[0].Cells[0].Value = 1; dgv.Rows[0].Cells[1].Value = movelist[firstMoves[rnd.Next(0, firstMoves.Length)]]; for (int j = 1; j < dgv.Rows.Count - 1; j++) { // Assign New Moves bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value; int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); while ( // Move is invalid !CHK_HMs.Checked && banned.Contains(move) || // HM Moves Not Allowed forceSTAB && // STAB is required !Main.Config.Personal[species].Types.Contains(moveTypes[move].Type)) { move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); } // Assign Move dgv.Rows[j].Cells[1].Value = movelist[move]; // Assign Level if (j >= count) { string level = (dgv.Rows[count - 1].Cells[0].Value ?? 0).ToString(); ushort lv; ushort.TryParse(level, out lv); if (lv > 100) { lv = 100; } else if (lv == 0) { lv = 1; } dgv.Rows[j].Cells[0].Value = lv + (j - count) + 1; } if (CHK_Spread.Checked) { dgv.Rows[j].Cells[0].Value = ((int)(j * (NUD_Level.Value / (dgv.Rows.Count - 1)))).ToString(); } } } CB_Species.SelectedIndex = 0; WinFormsUtil.Alert("All Pokemon's Level Up Moves have been randomized!"); }
private void Randomize() { int[] banned = { 165, 621 }; // Struggle, Hyperspace Fury rImportant = new string[CB_TrainerID.Items.Count]; rTags = Main.oras ? GetTagsORAS() : GetTagsXY(); mEvoTypes = GetMegaEvolvableTypes(); List <int> GymE4Types = new List <int>(); // Fetch Move Stats for more difficult randomization var moveData = Moves.getMoves(); int[] moveList = Enumerable.Range(1, movelist.Count() - 1).ToArray(); int mctr = 0; Util.Shuffle(moveList); if (rEnsureMEvo.Length > 0) { if (mEvoTypes.Length < 13 && rTypeTheme) { Util.Alert("There are insufficient types with at least one mega evolution to Guarantee story Mega Evos while keeping Type theming.", "Re-Randomize Personal or don't choose both options."); return; } GymE4Types.AddRange(mEvoTypes); } else { GymE4Types.AddRange(Enumerable.Range(0, types.Length).ToArray()); } foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1] != "" && !TagTypes.Keys.Contains(rTags[t1]))) { int t; if (rTags[t1].Contains("GYM") || rTags[t1].Contains("ELITE") || rTags[t1].Contains("CHAMPION")) { t = GymE4Types[(int)(rnd32() % GymE4Types.Count)]; GymE4Types.Remove(t); } else { t = mEvoTypes[rnd32() % mEvoTypes.Length]; } TagTypes[rTags[t1]] = t; } foreach (string t1 in Tags) { if (!TagTypes.Keys.Contains(t1) && t1 != "") { int t; if (t1.Contains("GYM") || t1.Contains("ELITE") || t1.Contains("CHAMPION")) { t = GymE4Types[(int)(rnd32() % GymE4Types.Count)]; GymE4Types.Remove(t); } else { t = (int)(rnd32() % types.Length); } TagTypes[t1] = t; } Console.WriteLine(t1 + ": " + types[TagTypes[t1]]); } randomizing = true; for (int i = 1; i < CB_TrainerID.Items.Count; i++) { CB_TrainerID.SelectedIndex = i; // data is loaded // Setup checkBox_Moves.Checked = rMove || (!rNoMove && checkBox_Moves.Checked); checkBox_Item.Checked = rItem || checkBox_Item.Checked; if (r6PKM && rImportant[i] != null) // skip the first rival battles { // Copy the last slot to random pokemon int lastPKM = Math.Max(CB_numPokemon.SelectedIndex - 1, 0); // 0,1-6 => 0-5 (never is 0) CB_numPokemon.SelectedIndex = 6; for (int f = lastPKM + 1; f < 6; f++) { trpk_pkm[f].SelectedIndex = trpk_IV[lastPKM].SelectedIndex; trpk_lvl[f].SelectedIndex = Math.Min(trpk_lvl[f - 1].SelectedIndex + 1, 100); } } // Randomize Trainer Stats if (rDiffAI) { if (CB_Battle_Type.SelectedIndex == 0) { CB_AI.SelectedIndex = 7; // Max Single } else if (CB_Battle_Type.SelectedIndex == 1) { CB_AI.SelectedIndex = 135; // Max Double } } if ( rClass && // Classes selected to be randomized (!rOnlySingles || CB_Battle_Type.SelectedIndex == 0) && // Nonsingles only get changed if rOnlySingles !rIgnoreClass.Contains(CB_Trainer_Class.SelectedIndex) // Current class isn't a special class ) { int rv = (int)(rnd32() % CB_Trainer_Class.Items.Count); // Ensure the Random Class isn't an exclusive class while (rIgnoreClass.Contains(rv) && !trClass[rv].StartsWith("[~")) // don't allow disallowed classes { rv = (int)(rnd32() % CB_Trainer_Class.Items.Count); } CB_Trainer_Class.SelectedIndex = rv; } if (rGift && rnd32() % 100 < rGiftPercent) #region Random Prize Logic { ushort[] items; uint rnd = rnd32() % 10; if (rnd < 2) // held item { items = Main.oras ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY; } else if (rnd < 5) // medicine { items = Main.oras ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY; } else // berry { items = Legal.Pouch_Berry_XY; } CB_Prize.SelectedIndex = items[rnd32() % items.Length]; } #endregion else if (rGift) { CB_Prize.SelectedIndex = 0; } ushort[] itemvals = Main.oras ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY; itemvals = itemvals.Concat(Legal.Pouch_Berry_XY).ToArray(); int itemC = itemvals.Length; int ctr = 0; // Trainer Type/Mega Evo int type = GetRandomType(i); bool mevo = rEnsureMEvo.Contains(i); bool typerand = rTypeTheme && !rGymE4Only || (rTypeTheme && rImportant[i] != null && (rImportant[i].Contains("GYM") || rImportant[i].Contains("ELITE") || rImportant[i].Contains("CHAMPION"))); // Randomize Pokemon for (int p = 0; p < CB_numPokemon.SelectedIndex; p++) { PersonalInfo oldpkm = Main.SpeciesStat[trpk_pkm[p].SelectedIndex]; PersonalInfo pkm = null; if (rPKM) { // randomize pokemon int species; pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]; if (typerand) { int tries = 0; while (((pkm.Types[0] != type && pkm.Types[1] != type) || mevo && p == CB_numPokemon.SelectedIndex - 1 && !megaEvos.Contains(species)) && tries < 0x10000) { if (p == CB_numPokemon.SelectedIndex - 1 && mevo) { pkm = Main.SpeciesStat[species = GetRandomMegaEvolvablePokemon(type)]; } else if (rSmart) // Get a new Pokemon with a close BST { pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]; while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && pkm.BST * (6 + ++tries / 722) / 5 > oldpkm.BST)) { pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]; } } else { pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]; } } } else if (p == CB_numPokemon.SelectedIndex - 1 && mevo) { pkm = Main.SpeciesStat[species = megaEvos[rnd32() % megaEvos.Length]]; } else if (rSmart) // Get a new Pokemon with a close BST { int tries = 0; while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && pkm.BST * (6 + ++tries / 722) / 5 > oldpkm.BST)) { pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)]; } } trpk_pkm[p].SelectedIndex = species; // Set Gender to Random trpk_gender[p].SelectedIndex = 0; if (trpk_form[p].Items.Count > 0) { trpk_form[p].SelectedIndex = 0; } // Randomize form if (trpk_form[p].Items.Count > 0 && (!megaEvos.Contains(species) || rRandomMegas)) { trpk_form[p].SelectedIndex = (int)(rnd32() % trpk_form[p].Items.Count); } } if (rLevel) { trpk_lvl[p].SelectedIndex = Math.Max(1, Math.Min((int)(trpk_lvl[p].SelectedIndex * ((100 + rLevelPercent) / 100)), 100)); } if (rAbility) { trpk_abil[p].SelectedIndex = (int)(1 + rnd32() % 3); } if (rDiffIV) { trpk_IV[p].SelectedIndex = 255; } if (mevo && p == CB_numPokemon.SelectedIndex - 1) { int[] megastones = GetMegaStones(trpk_pkm[p].SelectedIndex); if (megastones.Length > 0) { trpk_item[p].SelectedIndex = megastones[rnd32() % megastones.Length]; } } else if (rItem) #region RandomItem { trpk_item[p].SelectedIndex = itemvals[rnd32() % itemC]; } #endregion if (rMove) { pkm = pkm ?? Main.SpeciesStat[trpk_pkm[p].SelectedIndex]; int[] pkMoves = new int[4]; var moves = new[] { trpk_m1[p], trpk_m2[p], trpk_m3[p], trpk_m4[p] }; int loopctr = 0; getMoves: // Get list of moves loopctr++; for (int m = 0; m < 4; m++) { int mv = Randomizer.getRandomSpecies(ref moveList, ref mctr); while (banned.Contains(mv) || pkMoves.Contains(mv)) { mv = Randomizer.getRandomSpecies(ref moveList, ref mctr); } pkMoves[m] = mv; } // If a certain amount of damaging moves is required, check. if (rDMG) { int damagingMoves = pkMoves.Count(move => moveData[move].Category != 0); if (damagingMoves < rDMGCount && loopctr < 666) { goto getMoves; } } if (rSTAB) { int STAB = pkMoves.Count(move => pkm.Types.Contains(moveData[move].Type)); if (STAB < rSTABCount && loopctr < 666) { goto getMoves; } } // Assign Moves for (int m = 0; m < 4; m++) { moves[m].SelectedIndex = pkMoves[m]; } } } } randomizing = false; CB_TrainerID.SelectedIndex = 1; Util.Alert("Randomized all trainers according to specification!", "Press the Dump to TXT to view the new trainer information!"); }
private void B_RandAll_Click(object sender, EventArgs e) { // ORAS: 10682 moves learned on levelup/birth. // 5593 are STAB. 52.3% are STAB. // Steelix learns the most @ 25 (so many level 1)! Random rnd = new Random(); int[] firstMoves = { 1, 40, 52, 55, 64, 71, 84, 98, 122, 141 }; // Pound, Poison Sting, Ember, Water Gun, Peck, Absorb, Thunder Shock, Quick Attack, Lick, Leech Life ushort[] HMs = { 15, 19, 57, 70, 127, 249, 291 }; ushort[] TMs = {}; if (CHK_HMs.Checked && Main.ExeFS != null) { TMHM.getTMHMList(Main.oras, ref TMs, ref HMs); } int[] banned = new int[HMs.Length]; for (int i = 0; i < banned.Length; i++) { banned[i] = HMs[i]; } // Move Stats int[] moveTypes = Moves.getTypes(); // Personal Stats byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last()); // Set up Randomized Moves int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray(); Util.Shuffle(randomMoves); int ctr = 0; for (int i = 0; i < CB_Species.Items.Count; i++) { CB_Species.SelectedIndex = i; // Get new Species int count = dgv.Rows.Count - 1; if (CHK_Expand.Checked && (int)NUD_Moves.Value > count) { dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count); } // Default First Move dgv.Rows[0].Cells[0].Value = 1; dgv.Rows[0].Cells[1].Value = movelist[firstMoves[rnd.Next(0, firstMoves.Length)]]; for (int j = 1; j < dgv.Rows.Count - 1; j++) { // Assign New Moves bool forceSTAB = (CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value); int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); while ( // Move is invalid (!CHK_HMs.Checked && banned.Contains(move)) || // HM Moves Not Allowed (forceSTAB && // STAB is required !( moveTypes[move] == personalData[6 + (Main.oras ? 0x50 : 0x40) * i] // Type 1 || moveTypes[move] == personalData[7 + (Main.oras ? 0x50 : 0x40) * i] // Type 2 ) ) ) { move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr); } // Assign Move dgv.Rows[j].Cells[1].Value = movelist[move]; // Assign Level if (j >= count) { string level = (dgv.Rows[count - 1].Cells[0].Value ?? 0).ToString(); ushort lv; UInt16.TryParse(level, out lv); if (lv > 100) { lv = 100; } else if (lv == 0) { lv = 1; } dgv.Rows[j].Cells[0].Value = lv + (j - count) + 1; } if (CHK_Spread.Checked) { dgv.Rows[j].Cells[0].Value = (j * (NUD_Level.Value / (dgv.Rows.Count - 1))).ToString(); } } } CB_Species.SelectedIndex = 0; Util.Alert("All Pokemon's Level Up Moves have been randomized!"); }