From cfb1593ca7146b464434c622a3fb27a2e5fce72e Mon Sep 17 00:00:00 2001 From: sora10pls Date: Wed, 10 Jun 2020 23:33:54 -0400 Subject: [PATCH] Add banlist and form randomization to evo randomizer Previously, no forms would be adjusted, so something like Milcery could evolve into Charmander-8 (invalid) --- .../Randomizers/EvolutionRandomizer.cs | 3 +++ pkNX.WinForms/Subforms/PokeDataUI.cs | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs b/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs index ca1dd6ba..691c3080 100644 --- a/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs +++ b/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs @@ -9,11 +9,13 @@ public class EvolutionRandomizer : Randomizer { private readonly EvolutionSet[] Evolutions; private readonly GameInfo Game; + private readonly PersonalTable Personal; public readonly SpeciesRandomizer Randomizer; public EvolutionRandomizer(GameInfo game, EvolutionSet[] evolutions, PersonalTable t) { Game = game; + Personal = t; Evolutions = evolutions; Randomizer = new SpeciesRandomizer(Game, t); } @@ -43,6 +45,7 @@ private void Randomize(EvolutionSet evos, int species) if (evo.Method != 0) { evo.Species = Randomizer.GetRandomSpecies(evo.Species, species); + evo.Form = Legal.GetRandomForme(evo.Species, false, true, Game.SWSH, Personal); } } } diff --git a/pkNX.WinForms/Subforms/PokeDataUI.cs b/pkNX.WinForms/Subforms/PokeDataUI.cs index 596ba432..ed24d036 100644 --- a/pkNX.WinForms/Subforms/PokeDataUI.cs +++ b/pkNX.WinForms/Subforms/PokeDataUI.cs @@ -467,9 +467,20 @@ private void B_RandEvo_Click(object sender, EventArgs e) { SaveCurrent(); var settings = (SpeciesSettings)PG_Evolution.SelectedObject; - settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = false; + if (ROM.Info.GG) + settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = settings.Gen8 = false; var rand = new EvolutionRandomizer(ROM.Info, Editor.Evolve.LoadAll(), Editor.Personal); - rand.Randomizer.Initialize(settings); + int[] ban = Array.Empty(); + + if (ROM.Info.SWSH) + { + var pt = ROM.Data.PersonalData; + ban = pt.Table.Take(ROM.Info.MaxSpeciesID + 1) + .Select((z, i) => new {Species = i, Present = ((PersonalInfoSWSH)z).IsPresentInGame}) + .Where(z => !z.Present).Select(z => z.Species).ToArray(); + } + + rand.Randomizer.Initialize(settings, ban); rand.Execute(); LoadIndex(CB_Species.SelectedIndex); System.Media.SystemSounds.Asterisk.Play(); @@ -479,7 +490,8 @@ private void B_TradeEvo_Click(object sender, EventArgs e) { SaveCurrent(); var settings = (SpeciesSettings)PG_Evolution.SelectedObject; - settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = false; + if (ROM.Info.GG) + settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = settings.Gen8 = false; var rand = new EvolutionRandomizer(ROM.Info, Editor.Evolve.LoadAll(), Editor.Personal); rand.Randomizer.Initialize(settings); rand.ExecuteTrade();