Example #1
0
        private TrainerRandomizer GetRandomizer()
        {
            var moves = Game.Data.MoveData.LoadAll();
            var rmove = new MoveRandomizer(Game.Info, moves, Personal);

            int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves.Length);
            rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned);
            int[] ban = Array.Empty <int>();

            if (Game.Info.SWSH)
            {
                var pt = Game.Data.PersonalData;
                ban = pt.Table.Take(Game.Info.MaxSpeciesID + 1)
                      .Select((z, i) => new { Species = i, Present = ((PersonalInfoSWSH)z).IsPresentInGame })
                      .Where(z => !z.Present).Select(z => z.Species).ToArray();
            }

            var rspec = new SpeciesRandomizer(Game.Info, Personal);
            var rform = new FormRandomizer(Personal);

            rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject, ban);
            learn.Moves = moves;
            var evos  = Game.Data.EvolutionData;
            var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll(), evos.LoadAll())
            {
                ClassCount = CB_Trainer_Class.Items.Count,
                Learn      = learn,
                RandMove   = rmove,
                RandSpec   = rspec,
                RandForm   = rform,
                GetBlank   = () => (Game.Info.SWSH ? (TrainerPoke) new TrainerPoke8() : new TrainerPoke7b()), // this should probably be less specific
            };

            trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject, (SpeciesSettings)PG_Species.SelectedObject);
            return(trand);
        }
Example #2
0
        private TrainerRandomizer GetRandomizer()
        {
            var moves = Game.Data.MoveData.LoadAll();
            var rmove = new MoveRandomizer(Game.Info, moves, Personal);

            int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves.Length);
            rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned);
            var rspec = new SpeciesRandomizer(Game.Info, Personal);

            rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject);
            learn.Moves = moves;
            var evos  = Game.Data.EvolutionData;
            var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll(), evos.LoadAll())
            {
                ClassCount = CB_Trainer_Class.Items.Count,
                Learn      = learn,
                RandMove   = rmove,
                RandSpec   = rspec,
                GetBlank   = () => (Game.Info.SWSH ? (TrainerPoke) new TrainerPoke8() : new TrainerPoke7b()), // this should probably be less specific
            };

            trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject);
            return(trand);
        }
Example #3
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Randomizer Options tab.") != DialogResult.Yes)
            {
                return;
            }

            CB_TrainerID.SelectedIndex = 0;
            var rnd = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = CHK_G7.Checked,

                E    = CHK_E.Checked,
                L    = CHK_L.Checked,
                rBST = CHK_BST.Checked,
            };

            rnd.Initialize();

            // add Legendary/Mythical to final evolutions if checked
            if (CHK_L.Checked)
            {
                FinalEvo = FinalEvo.Concat(Legendary).ToArray();
            }
            if (CHK_E.Checked)
            {
                FinalEvo = FinalEvo.Concat(Mythical).ToArray();
            }

            var banned = new List <int>(new[] { 165, 621, 464 }.Concat(Legal.Z_Moves)); // Struggle, Hyperspace Fury, Dark Void

            if (CHK_NoFixedDamage.Checked)
            {
                banned.AddRange(MoveRandomizer.FixedDamageMoves);
            }
            var move = new MoveRandomizer(Main.Config)
            {
                BannedMoves = banned,
                rSTABCount  = (int)NUD_STAB.Value,
                rDMG        = CHK_Damage.Checked,
                rDMGCount   = (int)NUD_Damage.Value,
                rSTAB       = CHK_STAB.Checked
            };

            var items = Randomizer.getRandomItemList();

            for (int i = 0; i < Trainers.Length; i++)
            {
                var tr = Trainers[i];
                if (tr.Pokemon.Count == 0)
                {
                    continue;
                }

                // Trainer Properties
                if (CHK_RandomClass.Checked)
                {
                    // ignore special classes
                    if (CHK_IgnoreSpecialClass.Checked && !SpecialClasses.Contains(tr.TrainerClass))
                    {
                        int randClass() => (int)(Util.rnd32() % CB_Trainer_Class.Items.Count);

                        int rv; do
                        {
                            rv = randClass();
                        }while (SpecialClasses.Contains(rv)); // don't allow disallowed classes
                        tr.TrainerClass = (byte)rv;
                    }

                    // all classes
                    else if (!CHK_IgnoreSpecialClass.Checked)
                    {
                        int randClass() => (int)(Util.rnd32() % CB_Trainer_Class.Items.Count);

                        int rv; do
                        {
                            rv = randClass();
                        }while (rv == 082); // Lusamine 2 can crash multi battles, skip
                        tr.TrainerClass = (byte)rv;
                    }
                }

                var   avgBST   = (int)tr.Pokemon.Average(pk => Main.SpeciesStat[pk.Species].BST);
                int   avgLevel = (int)tr.Pokemon.Average(pk => pk.Level);
                var   pinfo    = Main.SpeciesStat.OrderBy(pk => Math.Abs(avgBST - pk.BST)).First();
                int   avgSpec  = Array.IndexOf(Main.SpeciesStat, pinfo);
                int[] royal    = { 081, 082, 083, 084, 185 };

                if (tr.NumPokemon < NUD_RMin.Value)
                {
                    for (int p = tr.NumPokemon; p < NUD_RMin.Value; p++)
                    {
                        tr.Pokemon.Add(new trpoke7
                        {
                            Species = rnd.GetRandomSpecies(avgSpec),
                            Level   = avgLevel,
                        });
                    }

                    tr.NumPokemon = (int)NUD_RMin.Value;
                }
                if (tr.NumPokemon > NUD_RMax.Value)
                {
                    tr.Pokemon.RemoveRange((int)NUD_RMax.Value, (int)(tr.NumPokemon - NUD_RMax.Value));
                    tr.NumPokemon = (int)NUD_RMax.Value;
                }
                if (CHK_6PKM.Checked && ImportantTrainers.Contains(tr.ID))
                {
                    for (int g = tr.NumPokemon; g < 6; g++)
                    {
                        tr.Pokemon.Add(new trpoke7
                        {
                            Species = rnd.GetRandomSpecies(avgSpec),
                            Level   = avgLevel,
                        });
                    }

                    tr.NumPokemon = 6;
                }

                // force 1 pkm to keep forced Battle Royal fair
                if (royal.Contains(tr.ID))
                {
                    tr.NumPokemon = 1;
                }

                // PKM Properties
                foreach (var pk in tr.Pokemon)
                {
                    if (CHK_RandomPKM.Checked)
                    {
                        int Type = CHK_TypeTheme.Checked ? (int)Util.rnd32() % 17 : -1;

                        // replaces Megas with another Mega (Dexio and Lysandre in USUM)
                        if (MegaDictionary.Values.Any(z => z.Contains(pk.Item)))
                        {
                            int[] mega = GetRandomMega(out int species);
                            pk.Species = species;
                            pk.Item    = mega[Util.rand.Next(0, mega.Length)];
                            pk.Form    = 0; // allow it to Mega Evolve naturally
                        }

                        // every other pkm
                        else
                        {
                            pk.Species = rnd.GetRandomSpeciesType(pk.Species, Type);
                            pk.Item    = items[Util.rnd32() % items.Length];
                            pk.Form    = Randomizer.GetRandomForme(pk.Species, CHK_RandomMegaForm.Checked, true, Main.SpeciesStat);
                        }

                        pk.Gender = 0;                                           // random
                        pk.Nature = (int)(Util.rnd32() % CB_Nature.Items.Count); // random
                    }
                    if (CHK_Level.Checked)
                    {
                        pk.Level = Randomizer.getModifiedLevel(pk.Level, NUD_LevelBoost.Value);
                    }
                    if (CHK_RandomShiny.Checked)
                    {
                        pk.Shiny = Util.rand.Next(0, 100 + 1) < NUD_Shiny.Value;
                    }
                    if (CHK_RandomAbilities.Checked)
                    {
                        pk.Ability = (int)Util.rnd32() % 4;
                    }
                    if (CHK_MaxDiffPKM.Checked)
                    {
                        pk.IVs = new[] { 31, 31, 31, 31, 31, 31 }
                    }
                    ;
                    if (CHK_MaxAI.Checked)
                    {
                        tr.AI |= (int)(TrainerAI.Basic | TrainerAI.Strong | TrainerAI.Expert | TrainerAI.PokeChange);
                    }

                    if (CHK_ForceFullyEvolved.Checked && pk.Level >= NUD_ForceFullyEvolved.Value && !FinalEvo.Contains(pk.Species))
                    {
                        int randFinalEvo() => (int)(Util.rnd32() % FinalEvo.Length);

                        pk.Species = FinalEvo[randFinalEvo()];
                        pk.Form    = Randomizer.GetRandomForme(pk.Species, CHK_RandomMegaForm.Checked, true, Main.SpeciesStat);
                    }

                    switch (CB_Moves.SelectedIndex)
                    {
                    case 1:     // Random
                        pk.Moves = move.GetRandomMoveset(pk.Species, 4);
                        break;

                    case 2:     // Current LevelUp
                        pk.Moves = learn.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4);
                        break;

                    case 3:     // Metronome
                        pk.Moves = new[] { 118, 0, 0, 0 };
                        break;
                    }

                    // high-power attacks
                    if (CHK_ForceHighPower.Checked && pk.Level >= NUD_ForceHighPower.Value)
                    {
                        pk.Moves = learn.GetHighPoweredMoves(pk.Species, pk.Form, 4);
                    }

                    // sanitize moves
                    if (CB_Moves.SelectedIndex > 1) // learn source
                    {
                        var moves = pk.Moves;
                        if (move.SanitizeMovesetForBannedMoves(moves, pk.Species))
                        {
                            pk.Moves = moves;
                        }
                    }
                }
                SaveData(tr, i);
            }
            WinFormsUtil.Alert("Randomized all Trainers according to specification!", "Press the Dump to .TXT button to view the new Trainer information!");
        }
Example #4
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Horde tab.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            var rand = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,

                L        = CHK_L.Checked,
                E        = CHK_E.Checked,
                Shedinja = false,

                rBST = CHK_BST.Checked,
            };

            rand.Initialize();

            for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
            {
                CB_LocationID.SelectedIndex = i;
                if (!hasData())
                {
                    continue;             // Don't randomize if doesn't have data.
                }
                // Assign Levels
                if (CHK_Level.Checked)
                {
                    for (int l = 0; l < max.Length; l++)
                    {
                        min[l].Value = max[l].Value = max[l].Value <= 1 ? max[l].Value : Math.Max(1, Math.Min(100, (int)(leveldiff * max[l].Value)));
                    }
                }


                // If Distinct Hordes are selected, homogenize
                int hordeslot = 0;
                for (int slot = 0; slot < max.Length; slot++)
                {
                    if (spec[slot].SelectedIndex == 0)
                    {
                        continue;
                    }
                    if (CHK_HomogeneousHordes.Checked && slot >= max.Length - 15)
                    {
                        int shift = hordeslot % 5;
                        hordeslot++;
                        if (shift != 0)
                        {
                            spec[slot].SelectedIndex = spec[slot - shift].SelectedIndex;
                            form[slot].Value         = form[slot - shift].Value;
                            continue;
                        }
                    }

                    int species = rand.GetRandomSpecies(spec[slot].SelectedIndex);
                    spec[slot].SelectedIndex = species;
                    setRandomForm(slot, species);
                }
                B_Save_Click(sender, e);
            }
            Enabled = true;
            WinFormsUtil.Alert("Randomized all Wild Encounters according to specification!", "Press the Dump Tables button to view the new Wild Encounter information!");
        }
Example #5
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Misc/Rand tab.") != DialogResult.Yes)
            {
                return;
            }

            CB_TrainerID.SelectedIndex = 0;
            var rnd = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = CHK_G7.Checked,

                E    = CHK_E.Checked,
                L    = CHK_L.Checked,
                rBST = CHK_BST.Checked,
            };

            rnd.Initialize();

            var items = Randomizer.getRandomItemList();

            for (int i = 0; i < Trainers.Length; i++)
            {
                var tr = Trainers[i];
                if (tr.Pokemon.Count == 0)
                {
                    continue;
                }
                // Trainer Properties
                if (CHK_RandomClass.Checked)
                {
                    int rv;
                    do
                    {
                        rv = (int)(Util.rnd32() % CB_Trainer_Class.Items.Count);
                    } while (/*trClass[rv].StartsWith("[~") || */ Legal.SpecialClasses_SM.Contains(rv) && !CHK_IgnoreSpecialClass.Checked);
                    // don't allow disallowed classes
                    tr.TrainerClass = (byte)rv;
                }

                if (tr.NumPokemon < NUD_RMin.Value)
                {
                    var avgBST   = (int)tr.Pokemon.Average(pk => Main.SpeciesStat[pk.Species].BST);
                    int avgLevel = (int)tr.Pokemon.Average(pk => pk.Level);
                    var pinfo    = Main.SpeciesStat.OrderBy(pk => Math.Abs(avgBST - pk.BST)).First();
                    int avgSpec  = Array.IndexOf(Main.SpeciesStat, pinfo);
                    for (int p = tr.NumPokemon; p < NUD_RMin.Value; p++)
                    {
                        tr.Pokemon.Add(new trpoke7
                        {
                            Species = rnd.GetRandomSpecies(avgSpec),
                            Level   = avgLevel,
                        });
                    }
                    tr.NumPokemon = (int)NUD_RMin.Value;
                }
                if (tr.NumPokemon > NUD_RMax.Value)
                {
                    tr.Pokemon.RemoveRange((int)NUD_RMax.Value, (int)(tr.NumPokemon - NUD_RMax.Value));
                    tr.NumPokemon = (int)NUD_RMax.Value;
                }

                // PKM Properties
                foreach (var pk in tr.Pokemon)
                {
                    if (CHK_RandomPKM.Checked)
                    {
                        int Type = CHK_TypeTheme.Checked ? (int)Util.rnd32() % 17 : -1;
                        pk.Species = rnd.GetRandomSpeciesType(pk.Species, Type);
                        pk.Form    = Randomizer.GetRandomForme(pk.Species, CHK_RandomMegaForm.Checked, true, Main.SpeciesStat);
                        pk.Gender  = 0; // Random Gender
                    }
                    if (CHK_Level.Checked)
                    {
                        pk.Level = Randomizer.getModifiedLevel(pk.Level, NUD_LevelBoost.Value);
                    }
                    if (CHK_RandomShiny.Checked)
                    {
                        pk.Shiny = Util.rand.Next(0, 100 + 1) < NUD_Shiny.Value;
                    }
                    if (CHK_RandomItems.Checked)
                    {
                        pk.Item = items[Util.rnd32() % items.Length];
                    }
                    if (CHK_RandomAbilities.Checked)
                    {
                        pk.Ability = (int)Util.rnd32() % 4;
                    }
                    if (CHK_MaxDiffPKM.Checked)
                    {
                        pk.IVs = new[] { 31, 31, 31, 31, 31, 31 }
                    }
                    ;

                    switch (CB_Moves.SelectedIndex)
                    {
                    case 1:     // Random
                        pk.Moves = Randomizer.getRandomMoves(
                            Main.Config.Personal.getFormeEntry(pk.Species, pk.Form).Types,
                            Main.Config.Moves,
                            CHK_Damage.Checked, (int)NUD_Damage.Value,
                            CHK_STAB.Checked, (int)NUD_STAB.Value);
                        break;

                    case 2:     // Current LevelUp
                        pk.Moves = move.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4);
                        break;

                    case 3:     // High Attacks
                        pk.Moves = move.GetHighPoweredMoves(pk.Species, pk.Form, 4);
                        break;
                    }
                }
                saveData(tr, i);
            }
            WinFormsUtil.Alert("Randomized all Trainers according to specification!", "Press the Dump to .TXT button to view the new Trainer information!");
        }
Example #6
0
        // Randomization
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Horde tab.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;

            // Calculate % diff we will apply to each level
            decimal leveldiff = NUD_LevelAmp.Value;

            // Nonrepeating List Start
            var rand = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,

                L        = CHK_L.Checked,
                E        = CHK_E.Checked,
                Shedinja = false,

                rBST = CHK_BST.Checked,
            };

            rand.Initialize();

            int[] slotArray = Enumerable.Range(0, max.Length).Select(a => a).ToArray();

            for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
            {
                CB_LocationID.SelectedIndex = i;
                if (!hasData())
                {
                    continue;             // Don't randomize if doesn't have data.
                }
                // Assign Levels
                if (CHK_Level.Checked)
                {
                    for (int l = 0; l < max.Length; l++)
                    {
                        min[l].Value = max[l].Value = max[l].Value <= 1 ? max[l].Value : Math.Max(1, Math.Min(100, (int)(leveldiff * max[l].Value)));
                    }
                }

                // Get a new list of Pokemon so that DexNav does not crash.
                int[] list = new int[max.Length];
                int   used = 19;

                // Count up how many slots are active.
                for (int s = 0; s < max.Length; s++)
                {
                    if (spec[s].SelectedIndex > 0)
                    {
                        list[s] = spec[s].SelectedIndex;
                    }
                }

                // At most 18, but don't chew if there's only a few slots.
                int   cons       = list.Count(a => a != 0);
                int[] RandomList = new int[cons > 18 ? 18 - cons / 8 : cons];

                // Fill Location List
                for (int s = 0; s < RandomList.Length; s++)
                {
                    RandomList[s] = rand.GetRandomSpecies(spec[s].SelectedIndex);
                }

                // Assign Slots
                while (used < RandomList.Distinct().Count() || used > 18) // Can just arbitrarily assign slots.
                {
                    Util.Shuffle(slotArray);
                    for (int s = 0; s < max.Length; s++)
                    {
                        int slot = slotArray[s];
                        if (spec[slot].SelectedIndex != 0) // If the slot is in use
                        {
                            list[slot] = RandomList[Util.rand.Next(0, RandomList.Length)];
                        }
                    }
                    used = countUnique(list);
                    if (used != RandomList.Length)
                    {
                        ShuffleSlots(ref list, RandomList.Length);
                    }
                    used = countUnique(list);
                }
                // If Distinct Hordes are selected, homogenize
                int hordeslot = 0;
                if (CHK_HomogeneousHordes.Checked)
                {
                    for (int slot = max.Length - 15; slot < max.Length; slot++)
                    {
                        list[slot] = list[slot - hordeslot % 5];
                        hordeslot++;
                    }
                }

                // Fill Slots
                for (int slot = 0; slot < max.Length; slot++)
                {
                    if (spec[slot].SelectedIndex != 0)
                    {
                        spec[slot].SelectedIndex = list[slot];
                        setRandomForm(slot, spec[slot].SelectedIndex);
                    }
                }

                B_Save_Click(sender, e);
            }
            Enabled = true;
            WinFormsUtil.Alert("Randomized all Wild Encounters according to specification!", "Press the Dump Tables button to view the new Wild Encounter information!");
        }
Example #7
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Randomizer Options tab.") != DialogResult.Yes)
            {
                return;
            }

            var formrand = new FormRandomizer(Main.Config)
            {
                AllowMega = false, AllowAlolanForm = false
            };
            var specrand = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = false,

                E = CHK_E.Checked,
                L = CHK_L.Checked,

                rBST = CHK_BST.Checked,
            };

            specrand.Initialize();
            var items = Randomizer.getRandomItemList();

            for (int i = 0; i < LB_Encounters.Items.Count; i++)
            {
                LB_Encounters.SelectedIndex = i;
                int species = CB_Species.SelectedIndex;

                // replace Legendaries with another Legendary
                if (CHK_ReplaceLegend.Checked && ReplaceLegend.Contains(species))
                {
                    int randLegend() => (int)(Util.rnd32() % ReplaceLegend.Length);

                    species = ReplaceLegend[randLegend()];
                }

                // every other entry
                else
                {
                    species = specrand.GetRandomSpecies(species);
                }

                if (CHK_AllowMega.Checked)
                {
                    formrand.AllowMega = true;
                }

                if (CHK_Item.Checked)
                {
                    CB_HeldItem.SelectedIndex = items[Util.rnd32() % items.Length];
                }

                if (CHK_Level.Checked)
                {
                    NUD_Level.Value = Randomizer.getModifiedLevel((int)NUD_Level.Value, NUD_LevelBoost.Value);
                }

                if (CHK_RemoveShinyLock.Checked)
                {
                    CHK_ShinyLock.Checked = false;
                }

                if (CHK_RandomAbility.Checked)
                {
                    CB_Ability.SelectedIndex = (Util.rand.Next(1, 4)); // 1, 2 , or H
                }
                if (CHK_ForceFullyEvolved.Checked && NUD_Level.Value >= NUD_ForceFullyEvolved.Value && !FinalEvo.Contains(species))
                {
                    int randFinalEvo() => (int)(Util.rnd32() % FinalEvo.Length);

                    species = FinalEvo[randFinalEvo()];
                }

                CB_Species.SelectedIndex = species;
                NUD_Form.Value           = formrand.GetRandomForme(species);
                CB_Gender.SelectedIndex  = 0; // random
            }
            WinFormsUtil.Alert("Randomized all Static Encounters according to specification!");
        }
Example #8
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Randomizer Options tab.") != DialogResult.Yes)
            {
                return;
            }

            var formrand = new FormRandomizer(Main.Config)
            {
                AllowMega = false, AllowAlolanForm = false
            };
            var specrand = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = false,

                E = CHK_E.Checked,
                L = CHK_L.Checked,

                rBST = CHK_BST.Checked,
            };

            specrand.Initialize();
            var helditems = Randomizer.getRandomItemList();

            for (int i = 0; i < LB_Gifts.Items.Count; i++)
            {
                LB_Gifts.SelectedIndex = i;
                int species = CB_Species.SelectedIndex;

                if (MegaDictionary.Values.Any(z => z.Contains(CB_HeldItem.SelectedIndex))) // Mega Stone Gifts (Lucario, Latias/Latios)
                {
                    if (!CHK_ReplaceMega.Checked)
                    {
                        continue; // skip Lucario, battle needs to Mega Evolve
                    }
                    int[] items = GetRandomMega(out species);
                    CB_HeldItem.SelectedIndex = items[Util.rand.Next(0, items.Length)];
                }
                else
                {
                    species = specrand.GetRandomSpecies(species);

                    if (CHK_Item.Checked)
                    {
                        CB_HeldItem.SelectedIndex = helditems[Util.rnd32() % helditems.Length];
                    }
                }

                if (CHK_AllowMega.Checked)
                {
                    formrand.AllowMega = true;
                }

                CB_Species.SelectedIndex = species;
                NUD_Form.Value           = formrand.GetRandomForme(species);
                CB_Gender.SelectedIndex  = 0; // random
                CB_Nature.SelectedIndex  = 0; // random

                if (MegaDictionary.Values.Any(z => z.Contains(CB_HeldItem.SelectedIndex)) && NUD_Form.Value > 0)
                {
                    NUD_Form.Value = 0; // don't allow Mega Stone Gifts to be form 1
                }
                if (CHK_RemoveShinyLock.Checked)
                {
                    CHK_ShinyLock.Checked = false;
                }

                if (CHK_Level.Checked)
                {
                    NUD_Level.Value = Randomizer.getModifiedLevel((int)NUD_Level.Value, NUD_LevelBoost.Value);
                }

                if (CHK_RandomAbility.Checked)
                {
                    CB_Ability.SelectedIndex = (Util.rand.Next(1, 4)); // 1, 2 , or H
                }
            }
            WinFormsUtil.Alert("Randomized all Gift Pokémon according to specification!");
        }
Example #9
0
        private void RandomizeWild(SpeciesRandomizer rand, bool fill, bool boost)
        {
            var pt = ROM.Data.PersonalData;

            bool IsGrassOrWater(int s) => pt[s].IsType((int)Types.Water) || pt[s].IsType((int)Types.Grass);

            foreach (var area in Tables.EncounterTables)
            {
                if (boost)
                {
                    area.GroundTableLevelMin = Legal.GetModifiedLevel(area.GroundTableLevelMin, (double)NUD_LevelBoost.Value);
                    area.GroundTableLevelMax = Legal.GetModifiedLevel(area.GroundTableLevelMax, (double)NUD_LevelBoost.Value);

                    area.WaterTableLevelMin = Legal.GetModifiedLevel(area.WaterTableLevelMin, (double)NUD_LevelBoost.Value);
                    area.WaterTableLevelMax = Legal.GetModifiedLevel(area.WaterTableLevelMax, (double)NUD_LevelBoost.Value);

                    area.SkyTableLevelMin = Legal.GetModifiedLevel(area.SkyTableLevelMin, (double)NUD_LevelBoost.Value);
                    area.SkyTableLevelMax = Legal.GetModifiedLevel(area.SkyTableLevelMax, (double)NUD_LevelBoost.Value);
                }
                ApplyRand(area.GroundTable);
                ApplyRand(area.WaterTable);
                ApplyRand(area.SkyTable);

                ApplyRand(area.OldRodTable);
                ApplyRand(area.GoodRodTable);
                ApplyRand(area.SuperRodTable);
            }

            void ApplyRand(IList <EncounterSlot7b> slots)
            {
                if (slots[0].Species == 0)
                {
                    return;
                }

                for (int i = 0; i < slots.Count; i++)
                {
                    var s = slots[i];
                    if (s.Species == 0)
                    {
                        if (!fill)
                        {
                            continue;
                        }
                        s.Species = slots.FirstOrDefault(z => z.Species != 0)?.Species ?? rand.GetRandomSpecies();
                    }

                    s.Species = rand.GetRandomSpecies(s.Species);
                    s.Form    = 0; // mega & alolan forms don't spawn :(
                    if (fill)
                    {
                        s.Probability = RandomScaledRates[slots.Count][i];
                    }
                }
            }

            if (CHK_ForceType.Checked)
            {
                var table = Tables.EncounterTables[0];
                var slots = table.GroundTable;
                while (!slots.Any(z => IsGrassOrWater(z.Species)))
                {
                    ApplyRand(slots);
                }
            }
        }
Example #10
0
        public void EditGift()
        {
            var arc  = ROM.GetFile(GameFile.EncounterGift);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterGift8Archive>(data);

            var gifts = objs.Table;
            var names = Enumerable.Range(0, gifts.Length).Select(z => $"{z:000}").ToArray();
            var cache = new DirectCache <EncounterGift8>(gifts);

            void Randomize()
            {
                int[] PossibleHeldItems = Legal.GetRandomItemList(ROM.Game);
                var   pt = ROM.Data.PersonalData;

                int[] 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();

                var spec  = EditUtil.Settings.Species;
                var srand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);
                var frand = new FormRandomizer(ROM.Data.PersonalData);

                srand.Initialize(spec, ban);
                foreach (var t in gifts)
                {
                    // swap gmax gifts and kubfu for other gmax capable species
                    if (t.CanGigantamax || t.Species == (int)Species.Kubfu)
                    {
                        t.Species = Legal.GigantamaxForms[Randomization.Util.Random.Next(Legal.GigantamaxForms.Length)];
                        t.Form    = (byte)(t.Species == (int)Species.Pikachu || t.Species == (int)Species.Meowth ? 0 : frand.GetRandomForme(t.Species, false, false, false, false, ROM.Data.PersonalData.Table)); // Pikachu & Meowth altforms can't gmax
                    }
                    else
                    {
                        t.Species = srand.GetRandomSpecies(t.Species);
                        t.Form    = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    }

                    t.Ability   = Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.Ball      = (Ball)Randomization.Util.Random.Next(1, EncounterGift8.BallToItem.Length);
                    t.HeldItem  = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature    = (int)Nature.Random25;
                    t.Gender    = (byte)FixedGender.Random;
                    t.ShinyLock = (int)Shiny.Random;
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }

                UpdateStarters(); // update placement critter data to match new randomized species
            }

            void UpdateStarters()
            {
                var container = ROM.GetFile(GameFile.Placement);
                var placement = new GFPack(container[0]);

                // a_r0501_i0101.bin for Toxel
                // a_bt0101.bin for Type: Null
                // a_wr0201_i0101.bin for Bulbasaur, Squirtle, Porygon, and Kubfu
                // a_wr0301_i0401.bin for Cosmog
                // a_d0901.bin for Poipole
                const string file     = "a_0101.bin";
                var          table    = placement.GetDataFileName(file);
                var          obj      = FlatBufferConverter.DeserializeFrom <PlacementArea8Archive>(table);
                var          critters = obj.Table[0].Critters;

                // Grookey
                critters[3].Species = (uint)gifts[0].Species;
                critters[3].Form    = gifts[0].Form;

                // Scorbunny
                critters[1].Species = (uint)gifts[3].Species;
                critters[1].Form    = gifts[3].Form;

                // Sobble
                critters[2].Species = (uint)gifts[4].Species;
                critters[2].Form    = gifts[4].Form;

                var bin = FlatBufferConverter.SerializeFrom(obj);

                placement.SetDataFileName(file, bin);
                container[0] = placement.Write();
            }

            using var form = new GenericEditor <EncounterGift8>(cache, names, "Gift Pokémon Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Example #11
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings in the Randomizer Options tab.") != DialogResult.Yes)
            {
                return;
            }

            var formrand = new FormRandomizer(Main.Config)
            {
                AllowMega = false, AllowAlolanForm = false
            };
            var specrand = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = false,

                E = CHK_E.Checked,
                L = CHK_L.Checked,

                rBST = CHK_BST.Checked,
            };

            specrand.Initialize();

            // add Legendary/Mythical to final evolutions if checked
            if (CHK_L.Checked)
            {
                FinalEvo = FinalEvo.Concat(Legendary).ToArray();
            }
            if (CHK_E.Checked)
            {
                FinalEvo = FinalEvo.Concat(Mythical).ToArray();
            }

            var helditems = Randomizer.GetRandomItemList();

            for (int i = 0; i < LB_Gifts.Items.Count; i++)
            {
                LB_Gifts.SelectedIndex = i;
                int species = CB_Species.SelectedIndex;

                if (MegaDictionary.Values.Any(z => z.Contains(CB_HeldItem.SelectedIndex))) // Mega Stone Gifts (Lucario, Latias/Latios)
                {
                    if (!CHK_ReplaceMega.Checked)
                    {
                        continue; // skip Lucario, battle needs to Mega Evolve
                    }
                    int[] items = GetRandomMega(out species);
                    CB_HeldItem.SelectedIndex = items[Util.Rand.Next(0, items.Length)];
                }
                else
                {
                    species = specrand.GetRandomSpecies(species);
                    if (CHK_Item.Checked)
                    {
                        CB_HeldItem.SelectedIndex = helditems[Util.Random32() % helditems.Length];
                    }
                }

                if (CHK_AllowMega.Checked)
                {
                    formrand.AllowMega = true;
                }

                if (CHK_RemoveShinyLock.Checked)
                {
                    CHK_ShinyLock.Checked = false;
                }

                if (CHK_Level.Checked)
                {
                    NUD_Level.Value = Randomizer.GetModifiedLevel((int)NUD_Level.Value, NUD_LevelBoost.Value);
                }

                if (CHK_RandomAbility.Checked)
                {
                    CB_Ability.SelectedIndex = (Util.Rand.Next(1, 4)); // 1, 2 , or H
                }
                if (CHK_ForceFullyEvolved.Checked && NUD_Level.Value >= NUD_ForceFullyEvolved.Value && !FinalEvo.Contains(species))
                {
Example #12
0
        public void EditGift()
        {
            var arc  = ROM.GetFile(GameFile.EncounterGift);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterGift8Archive>(data);

            var gifts = objs.Table;
            var names = Enumerable.Range(0, gifts.Length).Select(z => $"{z:000}").ToArray();
            var cache = new DirectCache <EncounterGift8>(gifts);

            void Randomize()
            {
                int[] PossibleHeldItems = Legal.GetRandomItemList(ROM.Game);
                var   pt = ROM.Data.PersonalData;

                int[] 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();

                var spec  = EditUtil.Settings.Species;
                var srand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);
                var frand = new FormRandomizer(ROM.Data.PersonalData);

                srand.Initialize(spec, ban);
                foreach (var t in gifts)
                {
                    // swap gmax gifts and kubfu for other gmax capable species
                    if (t.CanGigantamax || t.Species == Species.Kubfu)
                    {
                        t.Species = (Species)Legal.GigantamaxForms[Randomization.Util.Random.Next(Legal.GigantamaxForms.Length)];
                        t.AltForm = t.Species == Species.Pikachu || t.Species == Species.Meowth ? 0 : frand.GetRandomForme((int)t.Species, false, false, false, false, ROM.Data.PersonalData.Table); // Pikachu & Meowth altforms can't gmax
                    }
                    else
                    {
                        t.Species = (Species)srand.GetRandomSpecies((int)t.Species);
                        t.AltForm = frand.GetRandomForme((int)t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    }

                    t.Ability   = Randomization.Util.Random.Next(1, 4);        // 1, 2, or H
                    t.Ball      = (Ball)Randomization.Util.Random.Next(1, 15); // packed bit, only allows for 15 balls
                    t.HeldItem  = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature    = Nature.Random25;
                    t.Gender    = FixedGender.Random;
                    t.ShinyLock = Shiny.Random;
                    if (t.IV_Hp != -4)
                    {
                        t.IV_Hp = t.IV_Atk = t.IV_Def = t.IV_SpAtk = t.IV_SpDef = t.IV_Spe = -1;
                    }
                }
            }

            using var form = new GenericEditor <EncounterGift8>(cache, names, "Gift Pokémon Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Example #13
0
        // Randomization
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings at the bottom left.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;
            int  slotStart;
            int  slotStop;
            bool copy = false;

            switch (CB_SlotRand.SelectedIndex)
            {
            default:     // All
                slotStart = 0;
                slotStop  = -1;
                break;

            case 1:     // Regular Only
                slotStart = 0;
                slotStop  = 1;
                break;

            case 2:     // SOS Only
                slotStart = 1;
                slotStop  = -1;
                break;

            case 3:     // Regular Only, Copy to SOS
                slotStart = 0;
                slotStop  = 1;
                copy      = true;
                break;
            }

            var rnd = new SpeciesRandomizer(Main.Config)
            {
                G1 = CHK_G1.Checked,
                G2 = CHK_G2.Checked,
                G3 = CHK_G3.Checked,
                G4 = CHK_G4.Checked,
                G5 = CHK_G5.Checked,
                G6 = CHK_G6.Checked,
                G7 = CHK_G7.Checked,

                E    = CHK_E.Checked,
                L    = CHK_L.Checked,
                rBST = CHK_BST.Checked,
            };

            rnd.Initialize();

            foreach (var Map in Areas)
            {
                foreach (var Table in Map.Tables)
                {
                    if (CHK_Level.Checked)
                    {
                        Table.MinLevel = Randomizer.getModifiedLevel(Table.MinLevel, NUD_LevelAmp.Value);
                        Table.MaxLevel = Randomizer.getModifiedLevel(Table.MaxLevel, NUD_LevelAmp.Value);
                    }

                    int end = slotStop < 0 ? Table.Encounters.Length : slotStop;
                    for (int s = slotStart; s < end; s++)
                    {
                        var EncounterSet = Table.Encounters[s];
                        foreach (var enc in EncounterSet.Where(enc => enc.Species != 0))
                        {
                            enc.Species = (uint)rnd.GetRandomSpecies((int)enc.Species);
                            enc.Forme   = GetRandomForme((int)enc.Species);
                        }
                    }

                    if (copy) // copy row 0 to rest
                    {
                        var table = Table.Encounters;
                        var s0    = table[0];
                        for (int r = 1; r < table.Length; r++)
                        {
                            var slots = table[r];
                            for (int s = 0; s < slots.Length; s++)
                            {
                                slots[s].Species = s0[s].Species;
                                slots[s].Forme   = s0[s].Forme;
                            }
                        }
                    }

                    Table.Write();
                }
                encdata[Map.FileNumber] = getMapData(Map.Tables);
            }
            updatePanel(sender, e);
            Enabled = true;
            WinFormsUtil.Alert("Randomized all Wild Encounters according to specification!", "Press the Dump Tables button to view the new Wild Encounter information!");
        }
Example #14
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            bool blind = DialogResult.Yes ==
                         WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Hide randomization, save, and close?",
                                             "If you want the Starters to be a surprise :)");

            if (blind)
            {
                Hide();
            }

            // Iterate for each group of Starters
            for (int i = 0; i < Count; i++)
            {
                // Get Species List

                int gen  = int.Parse(Labels[i].Text[4] + "");
                var rand = new SpeciesRandomizer(Main.Config)
                {
                    G1 = !CHK_Gen.Checked || gen == 1,
                    G2 = !CHK_Gen.Checked || gen == 2,
                    G3 = !CHK_Gen.Checked || gen == 3,
                    G4 = !CHK_Gen.Checked || gen == 4,
                    G5 = !CHK_Gen.Checked || gen == 5,
                    G6 = !CHK_Gen.Checked || gen == 6,

                    L        = CHK_L.Checked,
                    E        = CHK_E.Checked,
                    Shedinja = false,
                };
                rand.Initialize();
                // Assign Species
                for (int j = 0; j < 3; j++)
                {
                    // int oldSpecies = BitConverter.ToUInt16(Data, offset + (((i * 3) + j) * 0x54));
                    if (CHK_BasicStarter.Checked)
                    {
                        if (CHK_Gen.Checked)
                        {
                            int basic() => (int)(Util.Random32() % BasicStarterPerGen[gen - 1].Length);

                            Choices[i][j].SelectedIndex = BasicStarterPerGen[gen - 1][basic()];
                        }
                        else
                        {
                            int basic() => (int)(Util.Random32() % BasicStarter.Length);

                            Choices[i][j].SelectedIndex = BasicStarter[basic()];
                        }
                    }
                    else
                    {
                        Choices[i][j].SelectedIndex = rand.GetRandomSpecies(i);
                    }
                }
            }

            if (blind)
            {
                SaveData();
                Close();
            }
        }
Example #15
0
    private void RandomizeArea(ResidentArea8a area, SpeciesSettings settings)
    {
        var pt   = ROM.Data.PersonalData;
        var rand = new SpeciesRandomizer(ROM.Info, pt);

        var hasForm = new HashSet <int>();
        var banned  = new HashSet <int>();

        foreach (var pi in pt.Table.Cast <PersonalInfoLA>())
        {
            if (pi.IsPresentInGame)
            {
                banned.Remove(pi.Species);
                hasForm.Add(pi.Species);
            }
            else if (!hasForm.Contains(pi.Species))
            {
                banned.Add(pi.Species);
            }
        }

        settings.Legends = false; // Legendary encounter slot conditions require you to not have captured the Legendary in order to encounter them; ban altogether.
        rand.Initialize(settings, banned.ToArray());

        var formRand = pt.Table
                       .Cast <PersonalInfoLA>()
                       .Where(z => z.IsPresentInGame && !(Legal.BattleExclusiveForms.Contains(z.Species) || Legal.BattleFusions.Contains(z.Species)))
                       .GroupBy(z => z.Species)
                       .ToDictionary(z => z.Key, z => z.ToList());

        var encounters = area.Encounters;

        foreach (var table in encounters)
        {
            foreach (var enc in table.Table)
            {
                if (enc.ShinyLock is not ShinyType8a.Random)
                {
                    continue;
                }

                // to progress the story in Cobalt Coastlands, you are required to show Iscan a Dusclops; ensure one can be captured
                if (enc.Species is (int)Dusclops && table.TableID is 7663383561364099763)
                {
                    continue;
                }

                var spec = rand.GetRandomSpecies(enc.Species);
                enc.Species = spec;
                enc.Form    = GetRandomForm(spec);
                enc.ClearMoves();
            }
        }
        int GetRandomForm(int spec)
        {
            if (!formRand.TryGetValue(spec, out var entries))
            {
                return(0);
            }
            var count = entries.Count;

            return((Species)spec switch
            {
                Growlithe or Arcanine or Voltorb or Electrode or Typhlosion or Qwilfish or Samurott or Lilligant or Zorua or Zoroark or Braviary or Sliggoo or Goodra or Avalugg or Decidueye => 1,
                Basculin => 2,
                Kleavor => 0,
                _ => Util.Random.Next(0, count),
            });
        }