From 84c4e658a65c9ac202e5a80cd29c144842952a35 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 24 May 2016 21:12:48 -0700 Subject: [PATCH] Add mart/pickup randomization Resolves #21 --- pk3DS/Randomizer.cs | 43 ++++++++++++++++++++++++++++ pk3DS/Subforms/Mart.Designer.cs | 44 +++++++++++++++++++++++++++-- pk3DS/Subforms/Mart.cs | 27 +++++++++++++++++- pk3DS/Subforms/Pickup.Designer.cs | 47 +++++++++++++++++++++++++++++-- pk3DS/Subforms/Pickup.cs | 28 +++++++++++++++++- 5 files changed, 181 insertions(+), 8 deletions(-) diff --git a/pk3DS/Randomizer.cs b/pk3DS/Randomizer.cs index e42f61e..e03ed37 100644 --- a/pk3DS/Randomizer.cs +++ b/pk3DS/Randomizer.cs @@ -44,5 +44,48 @@ internal static int[] getSpeciesList(bool G1, bool G2, bool G3, bool G4, bool G5 return sL.Length == 0 ? RandomSpeciesList : sL; } + + internal static int[] getRandomItemList(bool oras) + { + return (Main.oras ? Items_HeldAO : Items_HeldXY).Concat(Items_Ball).ToArray(); + } + #region Random Item List + private static readonly int[] Items_HeldXY = + { + /* 000, */ 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, 013, 014, 015, 017, 018, 019, 020, 021, 022, + 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, + 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 047, 048, 049, 050, 051, 052, 053, 054, 055, 056, 057, + 058, 059, 060, 061, 062, 063, 064, 065, 066, 067, 068, 069, 070, + 071, 072, 073, 074, 075, 076, 077, 078, 079, 080, 081, 082, 083, 084, 085, 086, 087, 088, 089, 090, 091, 092, + 093, 094, 099, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 112, 116, 117, 118, 119, 134, 135, 136, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, + 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, + 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, + 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + 210, 211, 212, 213, 214, 215, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, + 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 504, 537, 538, 539, 540, 541, 542, 543, 544, + 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, + 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 577, 580, 581, 582, 583, 584, + 585, 586, 587, 588, 589, 590, 591, 639, 640, 644, 645, 646, 647, + 648, 649, 650, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, + 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, + 684, 685, 686, 687, 688, 699, 704, 708, 709, 710, 711, 715, + }; + private static readonly int[] Items_HeldAO = Items_HeldXY.Concat(new[] + { + 534, 535, + 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 767, 768, 769, 770, + }).ToArray(); + private static readonly int[] Items_Ball = + { + 000, 001, 002, 003, 004, 005, 006, 007, 008, 009, 010, 011, 012, + 013, 014, 015, 016, 492, 493, 494, 495, 496, 497, 498, 499, 576, + }; + #endregion } } diff --git a/pk3DS/Subforms/Mart.Designer.cs b/pk3DS/Subforms/Mart.Designer.cs index 797a8d5..df4fafc 100644 --- a/pk3DS/Subforms/Mart.Designer.cs +++ b/pk3DS/Subforms/Mart.Designer.cs @@ -31,6 +31,9 @@ private void InitializeComponent() this.CB_Location = new System.Windows.Forms.ComboBox(); this.dgv = new System.Windows.Forms.DataGridView(); this.L_Mart = new System.Windows.Forms.Label(); + this.B_Randomize = new System.Windows.Forms.Button(); + this.B_Save = new System.Windows.Forms.Button(); + this.B_Cancel = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit(); this.SuspendLayout(); // @@ -58,7 +61,7 @@ private void InitializeComponent() this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgv.Location = new System.Drawing.Point(12, 33); this.dgv.Name = "dgv"; - this.dgv.Size = new System.Drawing.Size(300, 317); + this.dgv.Size = new System.Drawing.Size(300, 284); this.dgv.TabIndex = 1; // // L_Mart @@ -70,11 +73,44 @@ private void InitializeComponent() this.L_Mart.TabIndex = 2; this.L_Mart.Text = "Location:"; // + // B_Randomize + // + this.B_Randomize.Location = new System.Drawing.Point(12, 326); + this.B_Randomize.Name = "B_Randomize"; + this.B_Randomize.Size = new System.Drawing.Size(87, 23); + this.B_Randomize.TabIndex = 3; + this.B_Randomize.Text = "Randomize"; + this.B_Randomize.UseVisualStyleBackColor = true; + this.B_Randomize.Click += new System.EventHandler(this.B_Randomize_Click); + // + // B_Save + // + this.B_Save.Location = new System.Drawing.Point(244, 326); + this.B_Save.Name = "B_Save"; + this.B_Save.Size = new System.Drawing.Size(68, 23); + this.B_Save.TabIndex = 4; + this.B_Save.Text = "Save"; + this.B_Save.UseVisualStyleBackColor = true; + this.B_Save.Click += new System.EventHandler(this.B_Save_Click); + // + // B_Cancel + // + this.B_Cancel.Location = new System.Drawing.Point(170, 326); + this.B_Cancel.Name = "B_Cancel"; + this.B_Cancel.Size = new System.Drawing.Size(68, 23); + this.B_Cancel.TabIndex = 5; + this.B_Cancel.Text = "Cancel"; + this.B_Cancel.UseVisualStyleBackColor = true; + this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); + // // Mart // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(324, 362); + this.ClientSize = new System.Drawing.Size(324, 361); + this.Controls.Add(this.B_Cancel); + this.Controls.Add(this.B_Save); + this.Controls.Add(this.B_Randomize); this.Controls.Add(this.L_Mart); this.Controls.Add(this.dgv); this.Controls.Add(this.CB_Location); @@ -84,7 +120,6 @@ private void InitializeComponent() this.Name = "Mart"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Mart Editor"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing); ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -96,5 +131,8 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox CB_Location; private System.Windows.Forms.DataGridView dgv; private System.Windows.Forms.Label L_Mart; + private System.Windows.Forms.Button B_Randomize; + private System.Windows.Forms.Button B_Save; + private System.Windows.Forms.Button B_Cancel; } } \ No newline at end of file diff --git a/pk3DS/Subforms/Mart.cs b/pk3DS/Subforms/Mart.cs index 511408d..3640e3b 100644 --- a/pk3DS/Subforms/Mart.cs +++ b/pk3DS/Subforms/Mart.cs @@ -134,10 +134,35 @@ private void setList() Array.Copy(BitConverter.GetBytes((ushort)Array.IndexOf(itemlist, dgv.Rows[i].Cells[1].Value)), 0, data, dataoffset + 2 * i, 2); } - private void formClosing(object sender, FormClosingEventArgs e) + private void B_Save_Click(object sender, EventArgs e) { if (entry > -1) setList(); File.WriteAllBytes(codebin, data); } + private void B_Cancel_Click(object sender, EventArgs e) + { + Close(); + } + private void B_Randomize_Click(object sender, EventArgs e) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNoCancel, "Randomize mart inventories?")) + return; + + int[] validItems = Randomizer.getRandomItemList(Main.oras); + + 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; + } + } + } } } \ No newline at end of file diff --git a/pk3DS/Subforms/Pickup.Designer.cs b/pk3DS/Subforms/Pickup.Designer.cs index 71be5cf..96a480d 100644 --- a/pk3DS/Subforms/Pickup.Designer.cs +++ b/pk3DS/Subforms/Pickup.Designer.cs @@ -34,6 +34,9 @@ private void InitializeComponent() this.L_HM = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); + this.B_Save = new System.Windows.Forms.Button(); + this.B_Cancel = new System.Windows.Forms.Button(); + this.B_Randomize = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dgvCommon)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvRare)).BeginInit(); this.SuspendLayout(); @@ -102,11 +105,47 @@ private void InitializeComponent() this.label2.TabIndex = 6; this.label2.Text = "(level-1)/10, take 2."; // + // B_Save + // + this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.B_Save.Location = new System.Drawing.Point(421, 331); + this.B_Save.Name = "B_Save"; + this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.TabIndex = 7; + this.B_Save.Text = "Save"; + this.B_Save.UseVisualStyleBackColor = true; + this.B_Save.Click += new System.EventHandler(this.B_Save_Click); + // + // B_Cancel + // + this.B_Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.B_Cancel.Location = new System.Drawing.Point(340, 331); + this.B_Cancel.Name = "B_Cancel"; + this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.TabIndex = 8; + this.B_Cancel.Text = "Cancel"; + this.B_Cancel.UseVisualStyleBackColor = true; + this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click); + // + // B_Randomize + // + this.B_Randomize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.B_Randomize.Location = new System.Drawing.Point(9, 331); + this.B_Randomize.Name = "B_Randomize"; + this.B_Randomize.Size = new System.Drawing.Size(75, 23); + this.B_Randomize.TabIndex = 9; + this.B_Randomize.Text = "Randomize"; + this.B_Randomize.UseVisualStyleBackColor = true; + this.B_Randomize.Click += new System.EventHandler(this.B_Randomize_Click); + // // Pickup // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(504, 332); + this.ClientSize = new System.Drawing.Size(504, 361); + this.Controls.Add(this.B_Randomize); + this.Controls.Add(this.B_Cancel); + this.Controls.Add(this.B_Save); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.L_HM); @@ -115,11 +154,10 @@ private void InitializeComponent() this.Controls.Add(this.dgvCommon); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(520, 670); - this.MinimumSize = new System.Drawing.Size(520, 370); + this.MinimumSize = new System.Drawing.Size(520, 400); this.Name = "Pickup"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Pickup Editor"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing); ((System.ComponentModel.ISupportInitialize)(this.dgvCommon)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvRare)).EndInit(); this.ResumeLayout(false); @@ -135,5 +173,8 @@ private void InitializeComponent() private System.Windows.Forms.Label L_HM; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button B_Save; + private System.Windows.Forms.Button B_Cancel; + private System.Windows.Forms.Button B_Randomize; } } \ No newline at end of file diff --git a/pk3DS/Subforms/Pickup.cs b/pk3DS/Subforms/Pickup.cs index 6037c76..79354bc 100644 --- a/pk3DS/Subforms/Pickup.cs +++ b/pk3DS/Subforms/Pickup.cs @@ -100,10 +100,36 @@ private void setList() Array.Copy(BitConverter.GetBytes(rlist[i - 0x12]), 0, data, offset + 2 * i, 2); } - private void formClosing(object sender, FormClosingEventArgs e) + private void B_Save_Click(object sender, EventArgs e) { setList(); File.WriteAllBytes(codebin, data); } + private void B_Cancel_Click(object sender, EventArgs e) + { + Close(); + } + private void B_Randomize_Click(object sender, EventArgs e) + { + if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNoCancel, "Randomize pickup lists?")) + return; + + int[] validItems = Randomizer.getRandomItemList(Main.oras); + + 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; + } + } } } \ No newline at end of file