Fix fill empty, add wild mega

untested wild megas obv
This commit is contained in:
Kurt
2018-11-24 11:16:19 -08:00
parent 5111130381
commit d4179b35c7
4 changed files with 75 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using pkNX.Structures;
namespace pkNX.Randomization
@@ -62,6 +63,8 @@ public int GetRandomSpeciesType(int oldSpecies, int type)
private bool GetIsTypeMatch(int newSpecies, int type) => type == -1 || SpeciesStat[newSpecies].Types.Any(z => z == type) || loopctr > 9000;
public int GetRandomSpecies() => RandSpec.Next();
public int GetRandomSpecies(int oldSpecies)
{
// Get a new random species

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json;
namespace pkNX.Structures
{
@@ -7,7 +8,23 @@ public class EncounterArchive
public EncounterTable[] EncounterTables { get; set; }
public static EncounterArchive ReadJson(string json) => JsonConvert.DeserializeObject<EncounterArchive>(json);
public string WriteJson() => JsonConvert.SerializeObject(this);
public string WriteJson()
{
var serializer = new JsonSerializer();
using (var stringWriter = new StringWriter())
{
using (var writer = new JsonTextWriter(stringWriter))
{
writer.QuoteName = false;
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
serializer.Serialize(writer, this);
}
return stringWriter.ToString();
}
}
}
public class EncounterTable

View File

@@ -46,6 +46,9 @@ private void InitializeComponent()
this.Tab_Sky = new System.Windows.Forms.TabPage();
this.EL_Sky = new pkNX.WinForms.EncounterList();
this.Tab_Rand = new System.Windows.Forms.TabPage();
this.L_SpawnDuration = new System.Windows.Forms.Label();
this.L_SpawnCount = new System.Windows.Forms.Label();
this.L_SpawnRate = new System.Windows.Forms.Label();
this.CHK_FillEmpty = new System.Windows.Forms.CheckBox();
this.B_RandAll = new System.Windows.Forms.Button();
this.PG_Species = new System.Windows.Forms.PropertyGrid();
@@ -57,9 +60,7 @@ private void InitializeComponent()
this.B_ModSpawn = new System.Windows.Forms.Button();
this.L_Hash = new System.Windows.Forms.Label();
this.B_Save = new System.Windows.Forms.Button();
this.L_SpawnRate = new System.Windows.Forms.Label();
this.L_SpawnCount = new System.Windows.Forms.Label();
this.L_SpawnDuration = new System.Windows.Forms.Label();
this.CHK_WildMega = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.NUD_RankMin)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUD_RankMax)).BeginInit();
this.TC_Tables.SuspendLayout();
@@ -237,6 +238,7 @@ private void InitializeComponent()
//
// Tab_Rand
//
this.Tab_Rand.Controls.Add(this.CHK_WildMega);
this.Tab_Rand.Controls.Add(this.L_SpawnDuration);
this.Tab_Rand.Controls.Add(this.L_SpawnCount);
this.Tab_Rand.Controls.Add(this.L_SpawnRate);
@@ -257,10 +259,37 @@ private void InitializeComponent()
this.Tab_Rand.Text = "Rand";
this.Tab_Rand.UseVisualStyleBackColor = true;
//
// L_SpawnDuration
//
this.L_SpawnDuration.AutoSize = true;
this.L_SpawnDuration.Location = new System.Drawing.Point(202, 77);
this.L_SpawnDuration.Name = "L_SpawnDuration";
this.L_SpawnDuration.Size = new System.Drawing.Size(47, 13);
this.L_SpawnDuration.TabIndex = 11;
this.L_SpawnDuration.Text = "seconds";
//
// L_SpawnCount
//
this.L_SpawnCount.AutoSize = true;
this.L_SpawnCount.Location = new System.Drawing.Point(202, 13);
this.L_SpawnCount.Name = "L_SpawnCount";
this.L_SpawnCount.Size = new System.Drawing.Size(112, 13);
this.L_SpawnCount.TabIndex = 10;
this.L_SpawnCount.Text = "Max overworld models";
//
// L_SpawnRate
//
this.L_SpawnRate.AutoSize = true;
this.L_SpawnRate.Location = new System.Drawing.Point(202, 45);
this.L_SpawnRate.Name = "L_SpawnRate";
this.L_SpawnRate.Size = new System.Drawing.Size(15, 13);
this.L_SpawnRate.TabIndex = 9;
this.L_SpawnRate.Text = "%";
//
// CHK_FillEmpty
//
this.CHK_FillEmpty.AutoSize = true;
this.CHK_FillEmpty.Location = new System.Drawing.Point(154, 116);
this.CHK_FillEmpty.Location = new System.Drawing.Point(154, 108);
this.CHK_FillEmpty.Name = "CHK_FillEmpty";
this.CHK_FillEmpty.Size = new System.Drawing.Size(96, 17);
this.CHK_FillEmpty.TabIndex = 8;
@@ -382,32 +411,15 @@ private void InitializeComponent()
this.B_Save.UseVisualStyleBackColor = true;
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
//
// L_SpawnRate
// CHK_WildMega
//
this.L_SpawnRate.AutoSize = true;
this.L_SpawnRate.Location = new System.Drawing.Point(202, 45);
this.L_SpawnRate.Name = "L_SpawnRate";
this.L_SpawnRate.Size = new System.Drawing.Size(15, 13);
this.L_SpawnRate.TabIndex = 9;
this.L_SpawnRate.Text = "%";
//
// L_SpawnCount
//
this.L_SpawnCount.AutoSize = true;
this.L_SpawnCount.Location = new System.Drawing.Point(202, 13);
this.L_SpawnCount.Name = "L_SpawnCount";
this.L_SpawnCount.Size = new System.Drawing.Size(112, 13);
this.L_SpawnCount.TabIndex = 10;
this.L_SpawnCount.Text = "Max overworld models";
//
// L_SpawnDuration
//
this.L_SpawnDuration.AutoSize = true;
this.L_SpawnDuration.Location = new System.Drawing.Point(202, 77);
this.L_SpawnDuration.Name = "L_SpawnDuration";
this.L_SpawnDuration.Size = new System.Drawing.Size(47, 13);
this.L_SpawnDuration.TabIndex = 11;
this.L_SpawnDuration.Text = "seconds";
this.CHK_WildMega.AutoSize = true;
this.CHK_WildMega.Location = new System.Drawing.Point(154, 122);
this.CHK_WildMega.Name = "CHK_WildMega";
this.CHK_WildMega.Size = new System.Drawing.Size(82, 17);
this.CHK_WildMega.TabIndex = 12;
this.CHK_WildMega.Text = "Wild Megas";
this.CHK_WildMega.UseVisualStyleBackColor = true;
//
// GGWE
//
@@ -476,5 +488,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label L_SpawnDuration;
private System.Windows.Forms.Label L_SpawnCount;
private System.Windows.Forms.Label L_SpawnRate;
private System.Windows.Forms.CheckBox CHK_WildMega;
}
}

View File

@@ -344,12 +344,12 @@ private void B_RandAll_Click(object sender, EventArgs e)
var settings = (SpeciesSettings)PG_Species.SelectedObject;
var rand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);
rand.Initialize(settings);
RandomizeWild(rand, CHK_FillEmpty.Checked);
RandomizeWild(rand, CHK_FillEmpty.Checked, CHK_WildMega.Checked);
LoadEntry(entry);
System.Media.SystemSounds.Asterisk.Play();
}
private void RandomizeWild(SpeciesRandomizer rand, bool fill)
private void RandomizeWild(SpeciesRandomizer rand, bool fill, bool wildMega)
{
foreach (var area in Tables.EncounterTables)
{
@@ -362,15 +362,19 @@ private void RandomizeWild(SpeciesRandomizer rand, bool fill)
//ApplyRand(area.SuperRodTable);
}
void ApplyRand(IEnumerable<EncounterSlot> slots)
void ApplyRand(IList<EncounterSlot> slots)
{
foreach (var s in slots)
{
if (s.Species == 0 && !fill)
continue;
if (s.Species == 0)
{
if (!fill)
continue;
s.Species = slots.FirstOrDefault(z => z.Species != 0)?.Species ?? rand.GetRandomSpecies();
}
s.Species = rand.GetRandomSpecies(s.Species);
// meh form
s.Form = Legal.GetRandomForme(s.Species, wildMega, true, ROM.Data.PersonalData);
}
}
}