Gen7\Wild7Randomizer

-Added new randomization methods for SOS slots, Day/Night tables.  Gives a more even distribution rate for all species
-Added option to balance encounter rates.  Allows for easier hunting

Gen7\PersonalEditor7.cs
-Added GuaranteedItemChance flag.  Guarantees all wild species carry items when checked.
-Added Catch Rate, Call Rate, Friendship, Gender,  and Color to Log file Dump
-Resized, added, and moved controls on form respectively.

Gen7\SMWE.cs
-Redesigned Summary for Full and Simple options.  Full will show full stats for each encounter slot and each SOS under each one, including stats and held items.
-ExecuteRandomization: Added missing Shedinja flag and AlwaysShuffle flag to speciesRandomizer constructor

PK3DS.Core\Randomizers\GenericRandomizer.cs
-Added Debug.print

PK3DS.Core\Randomizers\PersonalRandomizer.cs
-Added GuaranteedItemChance flag logic
-RandomizeHeldItems: implemented randomization for all 3 hold chance slots

PK3DS.Core\Randomizers\SpeciesRandomizer.cs
-Added AlwaysShuffle flag and logic.  Flag gives option to allow repeats of randomized species

PK3DS.Core\Structures\Gen7\Area7.cs
-Added GetSummaryX.  I think all this does is change the sort order of tables from GetSummary.

PK3DS.Core\Structures\Gen7\Encounter7.cs
-Added spacing to string for formatting/readability purposes

PK3DS.Core\Structures\Gen7\EncounterTable.cs
-Maded GetSlotSetSummary public.  It's useful in  log dumps.
This commit is contained in:
mastersord
2022-05-25 22:03:53 -04:00
parent 94f23bb1c3
commit ebf7eb5f14
15 changed files with 456 additions and 63 deletions

View File

@@ -5,6 +5,8 @@
/// The shuffled list is iterated over, and reshuffled when exhausted.
/// The list does not repeat values until the list is exhausted.
/// </remarks>
///
using System.Diagnostics;
public class GenericRandomizer
{
public GenericRandomizer(int[] randomValues)
@@ -24,7 +26,10 @@ public void Reset()
public int Next()
{
if (ctr == 0)
{
Util.Shuffle(RandomValues);
Debug.Print("Shuffling list. Length = " + RandomValues.Length);
}
int value = RandomValues[ctr++];
ctr %= RandomValues.Length;

View File

@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -41,6 +42,7 @@ public class PersonalRandomizer : IRandomizer
public decimal SameTypeChance = 50;
public bool ModifyEggGroup = true;
public decimal SameEggGroupChance = 50;
public decimal GuaranteedItemChance = 50;
//public bool Advanced { get; set; } = false;
public bool TMInheritance { get; set; }
@@ -249,8 +251,12 @@ private void RandomizeEggGroups(PersonalInfo z)
private void RandomizeHeldItems(PersonalInfo z)
{
var item = z.Items;
for (int j = 0; j < item.Length; j++)
item[j] = GetRandomHeldItem();
//for (int j = 0; j < item.Length; j++)
// item[j] = GetRandomHeldItem();
item[0] = GetRandomHeldItem(); //Item 1 (50%)(common)
item[1] = rnd.Next(0, 100) < GuaranteedItemChance ? item[0] : GetRandomHeldItem(); //if Item 2 = Item 1 then Item 1 = 100% Else Item 2 (5%)(rare) according to https://github.com/Ajarmar/universal-pokemon-randomizer-zx
item[2] = GetRandomHeldItem(); //Item 3 (1%)(Dark Grass Only)
z.Items = item;
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using pk3DS.Core.Structures.PersonalInfo;
@@ -41,6 +42,7 @@ public void Initialize()
public bool rEXP = false;
public bool rBST = true;
public bool rType = false;
public bool AlwaysShuffle = false;
#endregion
#region Random Species Filtering Parameters
@@ -58,6 +60,8 @@ internal int GetRandomSpecies(int oldSpecies, int bannedSpecies)
loopctr = 0; // altering calculations to prevent infinite loops
int newSpecies;
while (!GetNewSpecies(bannedSpecies, oldpkm, out newSpecies))
if (AlwaysShuffle)
RandSpec.Reset();
loopctr++;
return newSpecies;
}
@@ -70,7 +74,9 @@ public int GetRandomSpeciesType(int oldSpecies, int type)
loopctr = 0; // altering calculations to prevent infinite loops
int newSpecies;
while (!GetNewSpecies(oldSpecies, oldpkm, out newSpecies) || !GetIsTypeMatch(newSpecies, type))
loopctr++;
if (AlwaysShuffle)
RandSpec.Reset();
loopctr++;
return newSpecies;
}
@@ -85,6 +91,8 @@ public int GetRandomSpecies(int oldSpecies)
int newSpecies;
while (!GetNewSpecies(oldSpecies, oldpkm, out newSpecies))
{
if (AlwaysShuffle)
Shuffle();
if (loopctr > 0x0001_0000)
{
PersonalInfo pkm = SpeciesStat[newSpecies];
@@ -97,6 +105,11 @@ public int GetRandomSpecies(int oldSpecies)
return newSpecies;
}
public void Shuffle()
{
RandSpec.Reset();
}
private bool IsSpeciesReplacementBad(int newSpecies, int currentSpecies)
{
return newSpecies == currentSpecies && loopctr < MaxSpeciesID * 10;
@@ -140,6 +153,11 @@ private int[] InitializeSpeciesList()
if (G6) AddGen6Species(list);
if (G7) AddGen7Species(list);
for (int x = 0; x< list.Count; x++)
{
Debug.Print("list = " + list[x]);
}
return list.Count == 0 ? RandomSpeciesList : list.ToArray();
}

View File

@@ -36,6 +36,30 @@ public string GetSummary(string[] speciesList)
return sb.ToString();
}
public string GetSummaryX(string[] speciesList)
{
var sb = new StringBuilder();
sb.AppendLine("==========");
sb.Append("Map: ").AppendLine(Name);
sb.Append("Tables: ").Append(Tables.Count).AppendLine();
for (int i = 0; i < Tables.Count; i++)
{
if (i % 2 == 0)
{
sb.Append("Table ").Append(i + 1).AppendLine(" (Day):");
sb.AppendLine(Tables[i].GetSummary(speciesList));
}
else
{
sb.Append("Table ").Append(i + 1).AppendLine(" (Night):");
sb.AppendLine(Tables[i].GetSummary(speciesList));
}
}
sb.AppendLine("==========");
return sb.ToString();
}
private const string PackIdentifier = "EA";
public static byte[] GetDayNightTableBinary(IList<EncounterTable> tables)

View File

@@ -20,7 +20,7 @@ public string GetSummary(string[] speciesList)
sb.Append(speciesList[Species]);
if (Forme != 0)
sb.Append(" (Forme ").Append(Forme).Append(')');
return sb.ToString();
return (sb.ToString() + " ").Substring(0,20) ;
}
public uint Dump(EncounterTable t) => RawValue | (uint)(t.MinLevel << 16) | (uint)(t.MaxLevel << 24);

View File

@@ -107,7 +107,7 @@ public string GetSummary(string[] speciesList)
return sb.ToString();
}
private string GetSlotSetSummary(string[] speciesList, int setNumber)
public string GetSlotSetSummary(string[] speciesList, int setNumber)
{
var specToRate = new Dictionary<uint, int>();
var distincts = new List<Encounter7>();

View File

@@ -132,7 +132,7 @@ private void SetEntry()
{
if (me.Method[i] > 1)
return; // Shouldn't hit this.
me.Method[i] = checkbox_spec[i].Checked ? (byte)1 : (byte)0;
me.Method[i] = checkbox_spec[i].Checked ? 1 : 0;
me.Argument[i] = (ushort)WinFormsUtil.GetIndex(item_spec[i]);
me.Form[i] = (ushort)forme_spec[i].SelectedIndex;
}

View File

@@ -139,11 +139,11 @@ private void InsertFile(string path)
{
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Overwrite image?"))
return;
byte[] data = File.ReadAllBytes(path);
byte[] bclim;
if (Path.GetExtension(path) == ".bclim") // bclim opened
{
byte[] data = File.ReadAllBytes(path);
var img = BCLIM.Analyze(data, path);
if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
{
@@ -155,7 +155,8 @@ private void InsertFile(string path)
}
else // image
{
Image img = Image.FromFile(path);
using Stream BitmapStream = new MemoryStream(data);
Image img = Image.FromStream(BitmapStream);
if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
{
WinFormsUtil.Alert("Image sizes do not match.",

View File

@@ -119,6 +119,7 @@ private void InitializeComponent()
this.CLB_TM = new System.Windows.Forms.CheckedListBox();
this.TP_Randomizer = new System.Windows.Forms.TabPage();
this.GB_Modifier = new System.Windows.Forms.GroupBox();
this.CHK_FullBeachTutorCompatibility = new System.Windows.Forms.CheckBox();
this.CHK_FullMoveTutorCompatibility = new System.Windows.Forms.CheckBox();
this.CHK_FullTMCompatibility = new System.Windows.Forms.CheckBox();
this.CHK_NoTutor = new System.Windows.Forms.CheckBox();
@@ -162,7 +163,8 @@ private void InitializeComponent()
this.B_Randomize = new System.Windows.Forms.Button();
this.PB_MonSprite = new System.Windows.Forms.PictureBox();
this.B_Dump = new System.Windows.Forms.Button();
this.CHK_FullBeachTutorCompatibility = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.NUD_Guaranteed = new System.Windows.Forms.NumericUpDown();
this.TC_Pokemon.SuspendLayout();
this.TP_General.SuspendLayout();
this.TP_MoveTutors.SuspendLayout();
@@ -176,6 +178,7 @@ private void InitializeComponent()
((System.ComponentModel.ISupportInitialize)(this.NUD_TypePercent)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_StatDev)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.PB_MonSprite)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_Guaranteed)).BeginInit();
this.SuspendLayout();
//
// CB_Species
@@ -208,7 +211,7 @@ private void InitializeComponent()
this.TC_Pokemon.Location = new System.Drawing.Point(12, 40);
this.TC_Pokemon.Name = "TC_Pokemon";
this.TC_Pokemon.SelectedIndex = 0;
this.TC_Pokemon.Size = new System.Drawing.Size(445, 375);
this.TC_Pokemon.Size = new System.Drawing.Size(445, 419);
this.TC_Pokemon.TabIndex = 416;
//
// TP_General
@@ -294,7 +297,7 @@ private void InitializeComponent()
this.TP_General.Location = new System.Drawing.Point(4, 22);
this.TP_General.Name = "TP_General";
this.TP_General.Padding = new System.Windows.Forms.Padding(3);
this.TP_General.Size = new System.Drawing.Size(437, 349);
this.TP_General.Size = new System.Drawing.Size(437, 393);
this.TP_General.TabIndex = 0;
this.TP_General.Text = "General Info";
this.TP_General.UseVisualStyleBackColor = true;
@@ -1073,7 +1076,7 @@ private void InitializeComponent()
this.TP_MoveTutors.Location = new System.Drawing.Point(4, 22);
this.TP_MoveTutors.Name = "TP_MoveTutors";
this.TP_MoveTutors.Padding = new System.Windows.Forms.Padding(3);
this.TP_MoveTutors.Size = new System.Drawing.Size(437, 349);
this.TP_MoveTutors.Size = new System.Drawing.Size(437, 393);
this.TP_MoveTutors.TabIndex = 1;
this.TP_MoveTutors.Text = "Move Tutors";
this.TP_MoveTutors.UseVisualStyleBackColor = true;
@@ -1096,7 +1099,7 @@ private void InitializeComponent()
this.CLB_BeachTutors.FormattingEnabled = true;
this.CLB_BeachTutors.Location = new System.Drawing.Point(301, 19);
this.CLB_BeachTutors.Name = "CLB_BeachTutors";
this.CLB_BeachTutors.Size = new System.Drawing.Size(133, 319);
this.CLB_BeachTutors.Size = new System.Drawing.Size(133, 364);
this.CLB_BeachTutors.TabIndex = 8;
this.CLB_BeachTutors.Visible = false;
//
@@ -1125,7 +1128,7 @@ private void InitializeComponent()
this.CLB_MoveTutors.FormattingEnabled = true;
this.CLB_MoveTutors.Location = new System.Drawing.Point(162, 19);
this.CLB_MoveTutors.Name = "CLB_MoveTutors";
this.CLB_MoveTutors.Size = new System.Drawing.Size(133, 319);
this.CLB_MoveTutors.Size = new System.Drawing.Size(133, 364);
this.CLB_MoveTutors.TabIndex = 3;
//
// CLB_TM
@@ -1135,7 +1138,7 @@ private void InitializeComponent()
this.CLB_TM.FormattingEnabled = true;
this.CLB_TM.Location = new System.Drawing.Point(9, 19);
this.CLB_TM.Name = "CLB_TM";
this.CLB_TM.Size = new System.Drawing.Size(147, 319);
this.CLB_TM.Size = new System.Drawing.Size(147, 364);
this.CLB_TM.TabIndex = 2;
//
// TP_Randomizer
@@ -1146,7 +1149,7 @@ private void InitializeComponent()
this.TP_Randomizer.Controls.Add(this.B_Randomize);
this.TP_Randomizer.Location = new System.Drawing.Point(4, 22);
this.TP_Randomizer.Name = "TP_Randomizer";
this.TP_Randomizer.Size = new System.Drawing.Size(437, 349);
this.TP_Randomizer.Size = new System.Drawing.Size(437, 393);
this.TP_Randomizer.TabIndex = 2;
this.TP_Randomizer.Text = "Enhancements";
this.TP_Randomizer.UseVisualStyleBackColor = true;
@@ -1169,13 +1172,23 @@ private void InitializeComponent()
this.GB_Modifier.Controls.Add(this.L_FinalXP);
this.GB_Modifier.Controls.Add(this.NUD_EXP);
this.GB_Modifier.Controls.Add(this.CHK_NoEV);
this.GB_Modifier.Location = new System.Drawing.Point(4, 147);
this.GB_Modifier.Location = new System.Drawing.Point(4, 199);
this.GB_Modifier.Name = "GB_Modifier";
this.GB_Modifier.Size = new System.Drawing.Size(345, 188);
this.GB_Modifier.TabIndex = 419;
this.GB_Modifier.TabStop = false;
this.GB_Modifier.Text = "Modifier Options";
//
// CHK_FullBeachTutorCompatibility
//
this.CHK_FullBeachTutorCompatibility.AutoSize = true;
this.CHK_FullBeachTutorCompatibility.Location = new System.Drawing.Point(204, 152);
this.CHK_FullBeachTutorCompatibility.Name = "CHK_FullBeachTutorCompatibility";
this.CHK_FullBeachTutorCompatibility.Size = new System.Drawing.Size(134, 30);
this.CHK_FullBeachTutorCompatibility.TabIndex = 24;
this.CHK_FullBeachTutorCompatibility.Text = "Full Beach Move Tutor\nCompatibility";
this.CHK_FullBeachTutorCompatibility.UseVisualStyleBackColor = true;
//
// CHK_FullMoveTutorCompatibility
//
this.CHK_FullMoveTutorCompatibility.AutoSize = true;
@@ -1363,6 +1376,8 @@ private void InitializeComponent()
//
// GB_Randomizer
//
this.GB_Randomizer.Controls.Add(this.label1);
this.GB_Randomizer.Controls.Add(this.NUD_Guaranteed);
this.GB_Randomizer.Controls.Add(this.CHK_Shuffle);
this.GB_Randomizer.Controls.Add(this.L_Same);
this.GB_Randomizer.Controls.Add(this.NUD_Egg);
@@ -1388,7 +1403,7 @@ private void InitializeComponent()
this.GB_Randomizer.Controls.Add(this.CHK_Item);
this.GB_Randomizer.Location = new System.Drawing.Point(4, 12);
this.GB_Randomizer.Name = "GB_Randomizer";
this.GB_Randomizer.Size = new System.Drawing.Size(345, 133);
this.GB_Randomizer.Size = new System.Drawing.Size(345, 181);
this.GB_Randomizer.TabIndex = 418;
this.GB_Randomizer.TabStop = false;
this.GB_Randomizer.Text = "Randomizer Options";
@@ -1688,28 +1703,39 @@ private void InitializeComponent()
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.B_Dump_Click);
//
// CHK_FullBeachTutorCompatibility
// label1
//
this.CHK_FullBeachTutorCompatibility.AutoSize = true;
this.CHK_FullBeachTutorCompatibility.Location = new System.Drawing.Point(204, 152);
this.CHK_FullBeachTutorCompatibility.Name = "CHK_FullBeachTutorCompatibility";
this.CHK_FullBeachTutorCompatibility.Size = new System.Drawing.Size(134, 30);
this.CHK_FullBeachTutorCompatibility.TabIndex = 24;
this.CHK_FullBeachTutorCompatibility.Text = "Full Beach Move Tutor\nCompatibility";
this.CHK_FullBeachTutorCompatibility.UseVisualStyleBackColor = true;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 134);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(102, 13);
this.label1.TabIndex = 28;
this.label1.Text = "Guaranteed item (%)";
//
// NUD_Guaranteed
//
this.NUD_Guaranteed.Location = new System.Drawing.Point(27, 150);
this.NUD_Guaranteed.Name = "NUD_Guaranteed";
this.NUD_Guaranteed.Size = new System.Drawing.Size(46, 20);
this.NUD_Guaranteed.TabIndex = 27;
this.NUD_Guaranteed.Value = new decimal(new int[] {
50,
0,
0,
0});
//
// PersonalEditor7
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(469, 426);
this.ClientSize = new System.Drawing.Size(469, 461);
this.Controls.Add(this.B_Dump);
this.Controls.Add(this.PB_MonSprite);
this.Controls.Add(this.TC_Pokemon);
this.Controls.Add(this.L_Species_Precursor);
this.Controls.Add(this.CB_Species);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(485, 465);
this.MaximumSize = new System.Drawing.Size(485, 500);
this.MinimumSize = new System.Drawing.Size(485, 465);
this.Name = "PersonalEditor7";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
@@ -1732,6 +1758,7 @@ private void InitializeComponent()
((System.ComponentModel.ISupportInitialize)(this.NUD_TypePercent)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_StatDev)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PB_MonSprite)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_Guaranteed)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -1874,5 +1901,7 @@ private void InitializeComponent()
private System.Windows.Forms.TextBox TB_RawColor;
private System.Windows.Forms.CheckBox CHK_FullMoveTutorCompatibility;
private System.Windows.Forms.CheckBox CHK_FullBeachTutorCompatibility;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown NUD_Guaranteed;
}
}

View File

@@ -361,7 +361,8 @@ private void B_Randomize_Click(object sender, EventArgs e)
SameTypeChance = NUD_TypePercent.Value,
SameEggGroupChance = NUD_Egg.Value,
StatDeviation = NUD_StatDev.Value,
AllowWonderGuard = CHK_WGuard.Checked
AllowWonderGuard = CHK_WGuard.Checked,
GuaranteedItemChance = NUD_Guaranteed.Value,
};
rnd.Execute();
@@ -463,12 +464,16 @@ private void B_Dump_Click(object sender, EventArgs e)
lines.Add(string.Format(CB_EggGroup1.SelectedIndex != CB_EggGroup2.SelectedIndex
? "Egg Group: {0} / {1}"
: "Egg Group: {0}", CB_EggGroup1.Text, CB_EggGroup2.Text));
lines.Add($"Friendship: {TB_Friendship.Text} | Gender: {TB_Gender.Text} | Color: {CB_Color.Text}");
lines.Add($"Hatch Cycles: {TB_HatchCycles.Text}");
lines.Add($"Catch Rate: {TB_CatchRate.Text}");
lines.Add($"Call Rate: {TB_CallRate.Text}");
lines.Add($"Height: {TB_Height.Text} m, Weight: {TB_Weight.Text} kg, Color: {CB_Color.Text}");
if (CB_ZBaseMove.SelectedIndex > 0)
lines.Add($"{CB_ZBaseMove.Text} + {CB_ZItem.Text} => {CB_ZMove.Text}");
lines.Add("");
}
string path = sfd.FileName;
File.WriteAllLines(path, lines, Encoding.Unicode);

View File

@@ -48,6 +48,10 @@ private void InitializeComponent()
this.B_Paste = new System.Windows.Forms.Button();
this.B_Copy = new System.Windows.Forms.Button();
this.GB_Tweak = new System.Windows.Forms.GroupBox();
this.chkRndBySlot = new System.Windows.Forms.CheckBox();
this.chkAlwaysShuffle = new System.Windows.Forms.CheckBox();
this.chkIngnorDayNight = new System.Windows.Forms.CheckBox();
this.chkBalanceRates = new System.Windows.Forms.CheckBox();
this.CB_SlotRand = new System.Windows.Forms.ComboBox();
this.L_SOS = new System.Windows.Forms.Label();
this.CHK_G7 = new System.Windows.Forms.CheckBox();
@@ -694,7 +698,7 @@ private void InitializeComponent()
this.GB_Encounters.Controls.Add(this.NUP_Rate1);
this.GB_Encounters.Location = new System.Drawing.Point(14, 39);
this.GB_Encounters.Name = "GB_Encounters";
this.GB_Encounters.Size = new System.Drawing.Size(1138, 561);
this.GB_Encounters.Size = new System.Drawing.Size(1138, 658);
this.GB_Encounters.TabIndex = 430;
this.GB_Encounters.TabStop = false;
this.GB_Encounters.Text = "Encounters (100%)";
@@ -778,6 +782,10 @@ private void InitializeComponent()
//
// GB_Tweak
//
this.GB_Tweak.Controls.Add(this.chkRndBySlot);
this.GB_Tweak.Controls.Add(this.chkAlwaysShuffle);
this.GB_Tweak.Controls.Add(this.chkIngnorDayNight);
this.GB_Tweak.Controls.Add(this.chkBalanceRates);
this.GB_Tweak.Controls.Add(this.CB_SlotRand);
this.GB_Tweak.Controls.Add(this.L_SOS);
this.GB_Tweak.Controls.Add(this.CHK_G7);
@@ -797,11 +805,52 @@ private void InitializeComponent()
this.GB_Tweak.Controls.Add(this.CHK_Level);
this.GB_Tweak.Location = new System.Drawing.Point(14, 405);
this.GB_Tweak.Name = "GB_Tweak";
this.GB_Tweak.Size = new System.Drawing.Size(282, 150);
this.GB_Tweak.Size = new System.Drawing.Size(282, 245);
this.GB_Tweak.TabIndex = 507;
this.GB_Tweak.TabStop = false;
this.GB_Tweak.Text = "Extra Randomization Tweaks";
//
// chkRndBySlot
//
this.chkRndBySlot.AutoSize = true;
this.chkRndBySlot.Location = new System.Drawing.Point(19, 191);
this.chkRndBySlot.Name = "chkRndBySlot";
this.chkRndBySlot.Size = new System.Drawing.Size(241, 43);
this.chkRndBySlot.TabIndex = 303;
this.chkRndBySlot.Text = "Randomize Each SOS Slot Separately\r\n(Each slot is randomized separately to ensure" +
" \r\neven distribution)\r\n";
this.chkRndBySlot.UseVisualStyleBackColor = true;
//
// chkAlwaysShuffle
//
this.chkAlwaysShuffle.AutoSize = true;
this.chkAlwaysShuffle.Location = new System.Drawing.Point(19, 177);
this.chkAlwaysShuffle.Name = "chkAlwaysShuffle";
this.chkAlwaysShuffle.Size = new System.Drawing.Size(218, 17);
this.chkAlwaysShuffle.TabIndex = 302;
this.chkAlwaysShuffle.Text = "Always reshuffle (Distribution is not even)";
this.chkAlwaysShuffle.UseVisualStyleBackColor = true;
//
// chkIngnorDayNight
//
this.chkIngnorDayNight.AutoSize = true;
this.chkIngnorDayNight.Location = new System.Drawing.Point(19, 162);
this.chkIngnorDayNight.Name = "chkIngnorDayNight";
this.chkIngnorDayNight.Size = new System.Drawing.Size(127, 17);
this.chkIngnorDayNight.TabIndex = 301;
this.chkIngnorDayNight.Text = "Ignore Day and Night";
this.chkIngnorDayNight.UseVisualStyleBackColor = true;
//
// chkBalanceRates
//
this.chkBalanceRates.AutoSize = true;
this.chkBalanceRates.Location = new System.Drawing.Point(19, 147);
this.chkBalanceRates.Name = "chkBalanceRates";
this.chkBalanceRates.Size = new System.Drawing.Size(96, 17);
this.chkBalanceRates.TabIndex = 300;
this.chkBalanceRates.Text = "Balance Rates";
this.chkBalanceRates.UseVisualStyleBackColor = true;
//
// CB_SlotRand
//
this.CB_SlotRand.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -811,7 +860,8 @@ private void InitializeComponent()
"Randomize All",
"Randomize Regular Only",
"Randomize SOS Only",
"Randomize Regular, Copy to SOS"});
"Randomize Regular, Copy to SOS",
"Randomize Regular Then SOS"});
this.CB_SlotRand.Location = new System.Drawing.Point(124, 120);
this.CB_SlotRand.Name = "CB_SlotRand";
this.CB_SlotRand.Size = new System.Drawing.Size(121, 21);
@@ -3144,7 +3194,7 @@ private void InitializeComponent()
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1161, 612);
this.ClientSize = new System.Drawing.Size(1161, 709);
this.Controls.Add(this.CopySOS);
this.Controls.Add(this.B_Export);
this.Controls.Add(this.CB_TableID);
@@ -3512,5 +3562,9 @@ private void InitializeComponent()
private System.Windows.Forms.Label L_Rain;
private System.Windows.Forms.Label L_Weather1;
private System.Windows.Forms.Label L_Weather0;
private System.Windows.Forms.CheckBox chkBalanceRates;
private System.Windows.Forms.CheckBox chkIngnorDayNight;
private System.Windows.Forms.CheckBox chkAlwaysShuffle;
private System.Windows.Forms.CheckBox chkRndBySlot;
}
}

View File

@@ -1,4 +1,9 @@
using System;
using pk3DS.Core;
using pk3DS.Core.CTR;
using pk3DS.Core.Randomizers;
using pk3DS.Core.Structures.PersonalInfo;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
@@ -6,10 +11,6 @@
using System.Text;
using System.Windows.Forms;
using pk3DS.Core;
using pk3DS.Core.CTR;
using pk3DS.Core.Randomizers;
namespace pk3DS
{
public partial class SMWE : Form
@@ -42,8 +43,8 @@ public SMWE(LazyGARCFile ed, LazyGARCFile zd, LazyGARCFile wd)
var weather = string.Format("If weather is active, create a random number.{0}If 0, use slot 0.{0}If <= 10, use slot 1.{0}Else, pick an SOS table and a slot.", Environment.NewLine);
new ToolTip().SetToolTip(L_AddSOS, weather);
var sos = new[] {L_SOS1, L_SOS2, L_SOS3, L_SOS4, L_SOS5, L_SOS6, L_SOS7};
var rates = new[] {1,1,1, 10,10,10, 67};
var sos = new[] { L_SOS1, L_SOS2, L_SOS3, L_SOS4, L_SOS5, L_SOS6, L_SOS7 };
var rates = new[] { 1, 1, 1, 10, 10, 10, 67 };
for (int i = 0; i < sos.Length; i++)
new ToolTip().SetToolTip(sos[i], $"Table Selection Rate: {rates[i]}%");
@@ -52,7 +53,7 @@ public SMWE(LazyGARCFile ed, LazyGARCFile zd, LazyGARCFile wd)
private NumericUpDown[] LoadRateNUD()
{
var list = new[] {NUP_Rate1, NUP_Rate2, NUP_Rate3, NUP_Rate4, NUP_Rate5, NUP_Rate6, NUP_Rate7, NUP_Rate8, NUP_Rate9, NUP_Rate10};
var list = new[] { NUP_Rate1, NUP_Rate2, NUP_Rate3, NUP_Rate4, NUP_Rate5, NUP_Rate6, NUP_Rate7, NUP_Rate8, NUP_Rate9, NUP_Rate10 };
foreach (var nup in list)
nup.ValueChanged += UpdateEncounterRate;
return list;
@@ -207,8 +208,8 @@ private void UpdateMinMax(object sender, EventArgs e)
if (loadingdata)
return;
loadingdata = true;
int min = (int) NUP_Min.Value;
int max = (int) NUP_Max.Value;
int min = (int)NUP_Min.Value;
int max = (int)NUP_Max.Value;
if (max < min)
{
max = min;
@@ -225,7 +226,7 @@ private void UpdateSpeciesForm(object sender, EventArgs e)
if (loadingdata)
return;
var cur_pb = CB_TableID.SelectedIndex%2 == 0 ? PB_DayTable : PB_NightTable;
var cur_pb = CB_TableID.SelectedIndex % 2 == 0 ? PB_DayTable : PB_NightTable;
var cur_img = cur_pb.Image;
object[][] source = sender is NumericUpDown ? (object[][])nup_spec : cb_spec;
@@ -234,8 +235,8 @@ private void UpdateSpeciesForm(object sender, EventArgs e)
var cb_l = cb_spec[table];
var nup_l = nup_spec[table];
var species = (uint) cb_l[slot].SelectedIndex;
var form = (uint) nup_l[slot].Value;
var species = (uint)cb_l[slot].SelectedIndex;
var form = (uint)nup_l[slot].Value;
if (table == 8)
{
CurrentTable.AdditionalSOS[slot].Species = species;
@@ -246,8 +247,8 @@ private void UpdateSpeciesForm(object sender, EventArgs e)
using (var g = Graphics.FromImage(cur_img))
{
int x = 40*slot;
int y = 30*(table + 1);
int x = 40 * slot;
int y = 30 * (table + 1);
if (table == 8)
{
x = (40 * slot) + 60;
@@ -269,17 +270,17 @@ private void UpdateEncounterRate(object sender, EventArgs e)
if (loadingdata)
return;
var cur_pb = CB_TableID.SelectedIndex%2 == 0 ? PB_DayTable : PB_NightTable;
var cur_pb = CB_TableID.SelectedIndex % 2 == 0 ? PB_DayTable : PB_NightTable;
var cur_img = cur_pb.Image;
int slot = Array.IndexOf(rate_spec, sender);
int rate = (int) ((NumericUpDown) sender).Value;
int rate = (int)((NumericUpDown)sender).Value;
CurrentTable.Rates[slot] = rate;
using (var g = Graphics.FromImage(cur_img))
{
var pnt = new PointF((40 * slot) + 10, 10);
g.SetClip(new Rectangle((int) pnt.X, (int) pnt.Y, 40, 14), CombineMode.Replace);
g.SetClip(new Rectangle((int)pnt.X, (int)pnt.Y, 40, 14), CombineMode.Replace);
g.Clear(Color.Transparent);
g.DrawString($"{rate}%", font, Brushes.Black, pnt);
}
@@ -371,15 +372,139 @@ private void B_Export_Click(object sender, EventArgs e)
private void DumpTables(object sender, EventArgs e)
{
using var sfd = new SaveFileDialog {FileName = "EncounterTables.txt"};
GetSummarySimple();
GetSummaryFull();
}
private void GetSummaryFull()
{
var sfd = new SaveFileDialog { FileName = "EncounterTablesFull.txt" };
if (sfd.ShowDialog() != DialogResult.OK)
return;
var sb = new StringBuilder();
sb.Append("================\nCompound Table\n================\n");
foreach (var Map in Areas)
sb.Append(Map.GetSummary(speciesList));
sb.Append(GetSummaryStatTable(Map, speciesList));
File.WriteAllText(sfd.FileName, sb.ToString());
}
private void GetSummarySimple()
{
using var sfd = new SaveFileDialog { FileName = "EncounterTablesSimple.txt" };
if (sfd.ShowDialog() != DialogResult.OK)
return;
var sb = new StringBuilder();
sb.Append("================\nSimplified Table\n================\n");
foreach (var Map in Areas)
sb.Append(Map.GetSummaryX(speciesList));
File.WriteAllText(sfd.FileName, sb.ToString());
}
public string GetSummaryStatTable(Area7 map, string[] speciesList)
{
var sb = new StringBuilder();
string AppendStr = "";
sb.AppendLine("==========");
sb.Append("Map: ").AppendLine(map.Name);
sb.Append("Tables: ").Append(map.Tables.Count).AppendLine();
for (int i = 0; i < map.Tables.Count; i++)
{
if (i % 2 == 0)
{
sb.Append("Table ").Append(i + 1).AppendLine(" (Day):");
AppendStr = "Map: " + map.Name + " " + "Table " + (i + 1) + " (Day): ";
sb.AppendLine(GetSummary(map.Tables[i], speciesList, AppendStr));
}
else
{
sb.Append("Table ").Append(i + 1).AppendLine(" (Night):");
AppendStr = "Map: " + map.Name + " " + "Table " + (i + 1) + " (Night): ";
sb.AppendLine(GetSummary(map.Tables[i], speciesList, AppendStr));
}
}
sb.AppendLine("==========");
return sb.ToString();
}
public string GetSummary(EncounterTable mapTable, string[] speciesList, string AppendStr)
{
var sb = new StringBuilder();
string BaseAppendStr = AppendStr;
for (int i = 0; i < mapTable.Encounter7s.Length - 1; i++)
{
var tn = "Encounters";
if (i != 0)
tn = "SOS Slot " + i;
AppendStr = BaseAppendStr + tn + " (Levels " + mapTable.MinLevel + "-" + mapTable.MaxLevel + "): ";
//sb.Append(tn).Append(" (Levels ").Append(mapTable.MinLevel).Append('-').Append(mapTable.MaxLevel).Append("): \n");
//sb.Append("\n");
sb.AppendLine(GetSlotSetSummary(mapTable, speciesList, i, AppendStr));
}
//sb.Append("Additional SOS encounters: \n");
//sb.Append("\n");
sb.AppendLine(string.Join("\n", mapTable.AdditionalSOS
.Select(e => e.RawValue).Distinct().Select(e => new Encounter7(e))
.Select(e => GetEncSummary(e, speciesList, AppendStr + "Additional SOS encounters: "))));
return sb.ToString();
}
public string GetEncSummary(Encounter7 enc, string[] speciesList, string AppendStr)
{
var sb = new StringBuilder();
string result = "";
if (enc.Species != 0)
{
sb.Append(speciesList[enc.Species]);
if (enc.Forme != 0)
sb.Append(" (Forme ").Append(enc.Forme).Append(')');
PersonalInfo per = Main.Config.Personal.GetFormEntry((int)enc.Species, (int)enc.Forme);
string[] items = Main.Config.GetText(TextName.ItemNames);
string[] types = Main.Config.GetText(TextName.Types);
result = AppendStr + " " + (sb.ToString() + " ").Substring(0, 25)
+ ("HP " + per.HP + " ").Substring(0, 8)
+ ("ATK " + per.ATK + " ").Substring(0, 8)
+ ("DEF " + per.DEF + " ").Substring(0, 8)
+ ("SPA " + per.SPA + " ").Substring(0, 8)
+ ("SPD " + per.SPD + " ").Substring(0, 8)
+ ("SPEED " + per.SPE + " ").Substring(0, 10)
+ ("Type1 " + types[per.Types[0]] + " ").Substring(0, 20)
+ ("Type2 " + types[per.Types[1]] + " ").Substring(0, 20)
+ ("Item1 " + items[per.Items[0]] + " ").Substring(0, 25)
+ ("Item2 " + items[per.Items[1]] + " ").Substring(0, 25)
+ ("Item3 " + items[per.Items[2]] + " ").Substring(0, 25)
+ "";
}
return result;
}
public string GetSlotSetSummary(EncounterTable mapTable, string[] speciesList, int setNumber, string AppendStr)
{
var specToRate = new Dictionary<uint, int>();
var distincts = new List<Encounter7>();
for (int j = 0; j < mapTable.Encounter7s[setNumber].Length; j++)
{
var encounter = mapTable.Encounter7s[setNumber][j];
if (!specToRate.ContainsKey(encounter.RawValue))
{
specToRate[encounter.RawValue] = 0;
distincts.Add(encounter);
}
specToRate[encounter.RawValue] += mapTable.Rates[j];
}
var list = distincts.OrderByDescending(e => specToRate[e.RawValue]);
var summaries = list.Select(e => $"{GetEncSummary(e, speciesList, AppendStr)} ({specToRate[e.RawValue]}%)\n");
return string.Join("", summaries);
}
// Randomization & Bulk Modification
private void B_Randomize_Click(object sender, EventArgs e)
{
@@ -405,10 +530,11 @@ private void ExecuteRandomization()
G5 = CHK_G5.Checked,
G6 = CHK_G6.Checked,
G7 = CHK_G7.Checked,
Shedinja = true,
E = CHK_E.Checked,
L = CHK_L.Checked,
rBST = CHK_BST.Checked,
AlwaysShuffle = chkAlwaysShuffle.Checked,
};
rnd.Initialize();
var form = new FormRandomizer(Main.Config)
@@ -423,6 +549,9 @@ private void ExecuteRandomization()
TableRandomizationOption = CB_SlotRand.SelectedIndex,
LevelAmplifier = NUD_LevelAmp.Value,
ModifyLevel = CHK_Level.Checked,
BalanceRates = chkBalanceRates.Checked,
IgnoreDayNight = chkIngnorDayNight.Checked,
RndBySlot = chkRndBySlot.Checked,
};
wild7.Execute(Areas, encdata);
}

View File

@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using pk3DS.Core;
using pk3DS.Core;
using pk3DS.Core.Randomizers;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
namespace pk3DS
{
@@ -14,10 +14,16 @@ public class Wild7Randomizer
public int TableRandomizationOption { private get; set; }
public decimal LevelAmplifier { private get; set; }
public bool ModifyLevel { private get; set; }
public bool BalanceRates { private get; set; }
public bool IgnoreDayNight { private get; set; }
public bool RndBySlot { private get; set; }
private void RandomizeTable7(EncounterTable Table, int slotStart, int slotStop)
{
int end = slotStop < 0 ? Table.Encounter7s.Length : slotStop;
int SlotCounter = 0;
int TotalRates = 0;
for (int s = slotStart; s < end; s++)
{
var EncounterSet = Table.Encounter7s[s];
@@ -25,6 +31,49 @@ private void RandomizeTable7(EncounterTable Table, int slotStart, int slotStop)
{
enc.Species = (uint)RandSpec.GetRandomSpecies((int)enc.Species);
enc.Forme = (uint)RandForm.GetRandomForme((int)enc.Species);
//Necessary because Weather SOS slots can be greater than initial SOS slots (see USUM Map set 181 for examples)
if(s < 1)
SlotCounter++;
}
//Get number of encounters, divide by 100, distribute remainder to reach 100 total
if (SlotCounter > 0)
TotalRates = 100 % SlotCounter;
if (BalanceRates == true)
{
for (int r = 0; r < SlotCounter; r++)
{
int NewRate = 100 / SlotCounter;
if (TotalRates > 0)
{
NewRate++;
TotalRates--;
}
Table.Rates[r] = NewRate;
}
}
TotalRates = 0;
SlotCounter = 0;
}
}
//Copy Species, Form, and rate from slot to slot. Day Table is randomized first so Copy it to Night table
public void CopyTableToTable(EncounterTable TableD, EncounterTable TableN)
{
for (int s = 0; s < TableD.Encounter7s.Length; s++)
{
var EncounterSetD = TableD.Encounter7s[s];
var EncounterSetN = TableN.Encounter7s[s];
for (int e = 0; e < EncounterSetD.Length; e++)
{
EncounterSetN[e].Species = EncounterSetD[e].Species;
EncounterSetN[e].Forme = EncounterSetD[e].Forme;
}
for (int r = 0; r < TableD.Rates.Length; r++)
{
TableN.Rates[r] = TableD.Rates[r];
}
}
}
@@ -33,21 +82,74 @@ public void Execute(IEnumerable<Area7> Areas, LazyGARCFile encdata)
{
GetTableRandSettings((RandOption)TableRandomizationOption, out int slotStart, out int slotStop, out bool copy);
if ((RandOption)TableRandomizationOption == RandOption.Regular_Then_SOS)
Randomize(Areas, encdata, 0, 1, copy);
if (RndBySlot)
{
for (int sl = 1; sl < 8; sl++)
{
Debug.Print("Randomizing slot" + sl);
Randomize(Areas, encdata, sl, sl + 1, copy);
}
Debug.Print("Randomizing other");
Randomize(Areas, encdata, 8, slotStop, copy);
}
else
{
Randomize(Areas, encdata, slotStart, slotStop, copy);
}
}
private void Randomize(IEnumerable<Area7> Areas, LazyGARCFile encdata, int slotStart, int slotStop, bool copy)
{
RandSpec.Shuffle();
foreach (var Map in Areas)
{
foreach (var Table in Map.Tables)
//foreach (var Table in Map.Tables) //Replaced so that tables can be skipped via IgnoreDayNight option
for (int t = 0; t < Map.Tables.Count; t++)
{
Debug.Print("Day table = " + t);
EncounterTable Table = Map.Tables[t];
if (ModifyLevel)
{
Table.MinLevel = Randomizer.GetModifiedLevel(Table.MinLevel, LevelAmplifier);
Table.MaxLevel = Randomizer.GetModifiedLevel(Table.MaxLevel, LevelAmplifier);
}
RandomizeTable7(Table, slotStart, slotStop);
if (copy) // copy row 0 to rest
Table.CopySlotsToSOS();
Table.Write();
t++;
}
encdata[Map.FileNumber] = Area7.GetDayNightTableBinary(Map.Tables);
}
RandSpec.Shuffle();
foreach (var Map in Areas)
{
for (int t = 1; t < Map.Tables.Count; t++)
{
Debug.Print("Night table = " + t);
EncounterTable Table = Map.Tables[t];
if (IgnoreDayNight) // Copy Table 1 to table 2 and skip to table 3. All encounter tables have a Day and Night version
{
CopyTableToTable(Map.Tables[t - 1], Table);
Map.Tables[t - 1].Write();
t++;
}
else
{
if (ModifyLevel)
{
Table.MinLevel = Randomizer.GetModifiedLevel(Table.MinLevel, LevelAmplifier);
Table.MaxLevel = Randomizer.GetModifiedLevel(Table.MaxLevel, LevelAmplifier);
}
RandomizeTable7(Table, slotStart, slotStop);
if (copy) // copy row 0 to rest
Table.CopySlotsToSOS();
Table.Write();
t++;
}
}
encdata[Map.FileNumber] = Area7.GetDayNightTableBinary(Map.Tables);
}
@@ -62,14 +164,22 @@ private static void GetTableRandSettings(RandOption option, out int slotStart, o
slotStart = 0;
slotStop = -1;
break;
case RandOption.Regular_Then_SOS: //Guarantees all species have an encounter before randomizing SOS slots
slotStart = 1;
slotStop = -1;
break;
case RandOption.Regular_Only:
slotStart = 0;
slotStop = 1;
break;
case RandOption.SOS_Only:
slotStart = 1;
slotStop = -1;
break;
case RandOption.Regular_CopySOS:
slotStart = 0;
slotStop = 1;
@@ -84,6 +194,7 @@ private enum RandOption
Regular_Only = 1,
SOS_Only = 2,
Regular_CopySOS = 3,
Regular_Then_SOS = 4,
}
}
}
}

View File

@@ -117,7 +117,7 @@ private void B_Save_Click(object sender, EventArgs e)
{
WriteCodePatch();
if (CHK_EverythingShiny.Enabled)
exefsData[alwaysIndex] = CHK_EverythingShiny.Checked ? (byte)0xEA : (byte)0x0A;
exefsData[alwaysIndex] = CHK_EverythingShiny.Checked ? 0xEA : 0x0A;
File.WriteAllBytes(codebin, exefsData);
Close();
}

View File

@@ -403,42 +403,53 @@
</EmbeddedResource>
<EmbeddedResource Include="Misc\About.resx">
<DependentUpon>About.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Misc\ErrorWindow.resx">
<DependentUpon>ErrorWindow.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\EnhancedRestore.resx">
<DependentUpon>EnhancedRestore.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\EggMoveEditor7.resx">
<DependentUpon>EggMoveEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\EvolutionEditor7.resx">
<DependentUpon>EvolutionEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\Experimental\OWSE7.resx">
<DependentUpon>OWSE7.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\ItemEditor7.resx">
<DependentUpon>ItemEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\LevelUpEditor7.resx">
<DependentUpon>LevelUpEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\MaisonEditor7.resx">
<DependentUpon>MaisonEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\MartEditor7UU.resx">
<DependentUpon>MartEditor7UU.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\MartEditor7.resx">
<DependentUpon>MartEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\MegaEvoEditor7.resx">
<DependentUpon>MegaEvoEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\MoveEditor7.resx">
<DependentUpon>MoveEditor7.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Subforms\Gen7\PersonalEditor7.resx">
<DependentUpon>PersonalEditor7.cs</DependentUpon>