Make trainer rand work

tfw no fairy moves -> causing STAB fetch loop to hang for Clefairy, lul
This commit is contained in:
Kurt
2018-11-23 22:08:41 -08:00
parent 5779523782
commit 15974cd8d8
5 changed files with 24 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ public GenericRandomizer(int[] randomValues)
private readonly int[] RandomValues;
private int ctr;
public int Count => RandomValues.Length;
public void Reset()
{

View File

@@ -78,8 +78,9 @@ private int[] GetRandomMoves(int[] Types, int movecount = 4)
private int GetRandomSTABMove(int[] types)
{
int move;
int ctr = 0;
do { move = RandMove.Next(); }
while (!types.Contains(MoveData[move].Type));
while (!types.Contains(MoveData[move].Type) && ctr++ < RandMove.Count);
return move;
}

View File

@@ -20,7 +20,7 @@ public class TrainerRandomizer : Randomizer
public MoveRandomizer RandMove { get; set; }
public int ClassCount { get; set; }
public IList<int> BannedMoves { get; set; }
public static Func<TrainerPoke> GetBlank { get; set; }
public Func<TrainerPoke> GetBlank { get; set; }
public IList<int> FinalEvo { get; set; } = Array.Empty<int>();
private TrainerRandSettings Settings;
@@ -65,6 +65,8 @@ public override void Execute()
// Team
foreach (var pk in tr.Team)
{
if (pk.Species == 0)
continue;
DetermineSpecies(pk);
UpdatePKMFromSettings(pk);
}
@@ -155,7 +157,8 @@ private void DetermineSpecies(IPokeData pk)
if (Settings.ForceFullyEvolved && pk.Level >= Settings.ForceFullyEvolvedAtLevel && !FinalEvo.Contains(pk.Species))
{
int randFinalEvo() => Util.Random.Next(FinalEvo.Count);
pk.Species = FinalEvo[randFinalEvo()];
if (FinalEvo.Count != 0)
pk.Species = FinalEvo[randFinalEvo()];
pk.Form = Legal.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, Personal.Table);
}
}

View File

@@ -537,6 +537,7 @@ private void B_Save_Click(object sender, EventArgs e)
private void B_Randomize_Click(object sender, EventArgs e)
{
SaveEntry();
var moves = Game.Data.MoveData.LoadAll();
var rmove = new MoveRandomizer(Game.Info, moves, Personal);
int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves);
@@ -549,8 +550,12 @@ private void B_Randomize_Click(object sender, EventArgs e)
Learn = learn,
RandMove = rmove,
RandSpec = rspec,
GetBlank = () => new TrainerPoke7b(), // this should probably be less specific
};
trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject);
trand.Execute();
LoadEntry();
System.Media.SystemSounds.Asterisk.Play();
}
}

View File

@@ -748,7 +748,7 @@ private void InitializeComponent()
this.Tab_Stats.Location = new System.Drawing.Point(4, 22);
this.Tab_Stats.Name = "Tab_Stats";
this.Tab_Stats.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Stats.Size = new System.Drawing.Size(224, 247);
this.Tab_Stats.Size = new System.Drawing.Size(224, 285);
this.Tab_Stats.TabIndex = 2;
this.Tab_Stats.Text = "Stats";
this.Tab_Stats.UseVisualStyleBackColor = true;
@@ -762,7 +762,7 @@ private void InitializeComponent()
this.Tab_Moves.Location = new System.Drawing.Point(4, 22);
this.Tab_Moves.Name = "Tab_Moves";
this.Tab_Moves.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Moves.Size = new System.Drawing.Size(224, 247);
this.Tab_Moves.Size = new System.Drawing.Size(224, 285);
this.Tab_Moves.TabIndex = 1;
this.Tab_Moves.Text = "Moves";
this.Tab_Moves.UseVisualStyleBackColor = true;
@@ -1063,7 +1063,7 @@ private void InitializeComponent()
this.Tab_Rand.Controls.Add(this.TC_RandSettings);
this.Tab_Rand.Location = new System.Drawing.Point(4, 22);
this.Tab_Rand.Name = "Tab_Rand";
this.Tab_Rand.Size = new System.Drawing.Size(314, 247);
this.Tab_Rand.Size = new System.Drawing.Size(314, 285);
this.Tab_Rand.TabIndex = 2;
this.Tab_Rand.Text = "Randomizer Options";
this.Tab_Rand.UseVisualStyleBackColor = true;
@@ -1088,7 +1088,7 @@ private void InitializeComponent()
this.TC_RandSettings.Location = new System.Drawing.Point(0, 0);
this.TC_RandSettings.Name = "TC_RandSettings";
this.TC_RandSettings.SelectedIndex = 0;
this.TC_RandSettings.Size = new System.Drawing.Size(314, 247);
this.TC_RandSettings.Size = new System.Drawing.Size(314, 285);
this.TC_RandSettings.TabIndex = 447;
//
// Tab_RSpecies
@@ -1096,7 +1096,7 @@ private void InitializeComponent()
this.Tab_RSpecies.Controls.Add(this.PG_Species);
this.Tab_RSpecies.Location = new System.Drawing.Point(4, 22);
this.Tab_RSpecies.Name = "Tab_RSpecies";
this.Tab_RSpecies.Size = new System.Drawing.Size(306, 221);
this.Tab_RSpecies.Size = new System.Drawing.Size(306, 259);
this.Tab_RSpecies.TabIndex = 0;
this.Tab_RSpecies.Text = "Species";
this.Tab_RSpecies.UseVisualStyleBackColor = true;
@@ -1106,7 +1106,7 @@ private void InitializeComponent()
this.Tab_RMoves.Controls.Add(this.PG_Moves);
this.Tab_RMoves.Location = new System.Drawing.Point(4, 22);
this.Tab_RMoves.Name = "Tab_RMoves";
this.Tab_RMoves.Size = new System.Drawing.Size(306, 221);
this.Tab_RMoves.Size = new System.Drawing.Size(306, 259);
this.Tab_RMoves.TabIndex = 1;
this.Tab_RMoves.Text = "Moves";
this.Tab_RMoves.UseVisualStyleBackColor = true;
@@ -1116,7 +1116,7 @@ private void InitializeComponent()
this.Tab_RTrainer.Controls.Add(this.PG_RTrainer);
this.Tab_RTrainer.Location = new System.Drawing.Point(4, 22);
this.Tab_RTrainer.Name = "Tab_RTrainer";
this.Tab_RTrainer.Size = new System.Drawing.Size(306, 221);
this.Tab_RTrainer.Size = new System.Drawing.Size(306, 259);
this.Tab_RTrainer.TabIndex = 3;
this.Tab_RTrainer.Text = "Trainer";
this.Tab_RTrainer.UseVisualStyleBackColor = true;
@@ -1136,7 +1136,7 @@ private void InitializeComponent()
this.PG_RTrainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.PG_RTrainer.Location = new System.Drawing.Point(0, 0);
this.PG_RTrainer.Name = "PG_RTrainer";
this.PG_RTrainer.Size = new System.Drawing.Size(306, 221);
this.PG_RTrainer.Size = new System.Drawing.Size(306, 259);
this.PG_RTrainer.TabIndex = 0;
this.PG_RTrainer.ToolbarVisible = false;
//
@@ -1145,7 +1145,7 @@ private void InitializeComponent()
this.PG_Species.Dock = System.Windows.Forms.DockStyle.Fill;
this.PG_Species.Location = new System.Drawing.Point(0, 0);
this.PG_Species.Name = "PG_Species";
this.PG_Species.Size = new System.Drawing.Size(306, 221);
this.PG_Species.Size = new System.Drawing.Size(306, 259);
this.PG_Species.TabIndex = 1;
this.PG_Species.ToolbarVisible = false;
//
@@ -1154,7 +1154,7 @@ private void InitializeComponent()
this.PG_Moves.Dock = System.Windows.Forms.DockStyle.Fill;
this.PG_Moves.Location = new System.Drawing.Point(0, 0);
this.PG_Moves.Name = "PG_Moves";
this.PG_Moves.Size = new System.Drawing.Size(306, 221);
this.PG_Moves.Size = new System.Drawing.Size(306, 259);
this.PG_Moves.TabIndex = 1;
this.PG_Moves.ToolbarVisible = false;
//
@@ -1166,6 +1166,7 @@ private void InitializeComponent()
this.B_Dump.TabIndex = 449;
this.B_Dump.Text = "Dump .TXT";
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.DumpTxt);
//
// Stats
//