Example #1
0
        public void EditTrade()
        {
            var arc  = ROM.GetFile(GameFile.EncounterTrade);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterTrade8Archive>(data);

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

            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 trades)
                {
                    // what you receive
                    t.Species       = srand.GetRandomSpecies(t.Species);
                    t.Form          = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.AbilityNumber = (byte)Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.Ball          = (Ball)Randomization.Util.Random.Next(1, EncounterTrade8.BallToItem.Length);
                    t.HeldItem      = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature        = (int)Nature.Random25;
                    t.Gender        = (int)FixedGender.Random;
                    t.ShinyLock     = (int)Shiny.Random;
                    t.Relearn1      = 0;
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;

                    // what you trade
                    t.RequiredSpecies = srand.GetRandomSpecies(t.RequiredSpecies);
                    t.RequiredForm    = (byte)frand.GetRandomForme(t.RequiredSpecies, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.RequiredNature  = (int)Nature.Random25; // any
                }
            }

            using var form = new GenericEditor <EncounterTrade8>(cache, names, "In-Game Trades Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Example #2
0
        public void EditTrade()
        {
            var file  = ROM[GameFile.EncounterTrade];
            var data  = file[0];
            var objs  = data.GetArray(z => new EncounterTrade7b(z), EncounterTrade7b.SIZE); // binary
            var names = Enumerable.Range(0, objs.Length).Select(z => $"{z:00}").ToArray();
            var cache = new DirectCache <EncounterTrade7b>(objs);

            void Randomize()
            {
                var spec = EditUtil.Settings.Species;

                spec.Gen2 = spec.Gen3 = spec.Gen4 = spec.Gen5 = spec.Gen6 = spec.Gen7 = false;
                var srand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);

                srand.Initialize(spec);
                foreach (var t in objs)
                {
                    t.Species         = srand.GetRandomSpecies(t.Species);
                    t.Form            = Legal.GetRandomForme(t.Species, false, true, ROM.Data.PersonalData);
                    t.RequiredSpecies = srand.GetRandomSpecies(t.RequiredSpecies);
                }
            }

            using var form = new GenericEditor <EncounterTrade7b>(cache, names, "Trade Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                file.CancelEdits();
            }
            else
            {
                file[0] = objs.SelectMany(z => z.Write()).ToArray();
            }
        }
Example #3
0
        public void EditTrade()
        {
            var file  = ROM[GameFile.EncounterTrade];
            var data  = file[0];
            var objs  = data.GetArray(z => new EncounterTrade7b(z), EncounterTrade7b.SIZE); // binary
            var names = Enumerable.Range(0, objs.Length).Select(z => $"{z:000}").ToArray();
            var cache = new DirectCache <EncounterTrade7b>(objs);

            void Randomize()
            {
                var spec = EditUtil.Settings.Species;

                spec.Gen2 = spec.Gen3 = spec.Gen4 = spec.Gen5 = spec.Gen6 = spec.Gen7 = false;
                var srand = new SpeciesRandomizer(ROM.Info, Data.PersonalData);
                var frand = new FormRandomizer(Data.PersonalData);

                srand.Initialize(spec, 808, 809); // can only catch 1-151 in wild
                foreach (var t in objs)
                {
                    t.Species         = (Species)srand.GetRandomSpecies((int)t.Species);
                    t.RequiredSpecies = (Species)srand.GetRandomSpecies((int)t.Species);
                    t.Form            = frand.GetRandomForme((int)t.Species, false, false, true, false, Data.PersonalData.Table);
                    t.RequiredForm    = 0; // can't catch wild alolan forms
                    t.Nature          = Nature.Random - 1;
                    t.Gender          = FixedGender.Random;
                    t.Shiny           = Shiny.Random;
                    t.RelearnMoves    = new[] { 0, 0, 0, 0 };
                    if (t.IV_HP != -4)
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }
            }

            using var form = new GenericEditor <EncounterTrade7b>(cache, names, "Trade Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                file.CancelEdits();
            }
            else
            {
                file[0] = objs.SelectMany(z => z.Write()).ToArray();
            }
        }
Example #4
0
        public void EditStatic()
        {
            var arc  = ROM.GetFile(GameFile.EncounterStatic);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterStatic8Archive>(data);

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

            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 encounters)
                {
                    if (t.Species >= (int)Species.Zacian && t.Species <= (int)Species.Eternatus) // Eternatus crashes when changed, keep Zacian and Zamazenta to make final boss battle fair
                    {
                        continue;
                    }
                    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.HeldItem  = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)];
                    t.Nature    = (int)Nature.Random25;
                    t.Gender    = (int)FixedGender.Random;
                    t.ShinyLock = (int)Shiny.Random;
                    t.Moves     = new[] { 0, 0, 0, 0 };
                    if (t.IV_HP != -4 && t.IVs.Any(z => z != 31))
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }
            }

            using var form = new GenericEditor <EncounterStatic8>(cache, names, "Static Encounter Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Example #5
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();
            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 gift pkm (only lucario?)
                {
                    if (!CHK_Mega.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);
                }

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

                if (CHK_Level.Checked)
                {
                    NUD_Level.Value = Randomizer.getModifiedLevel((int)NUD_Level.Value, NUD_LevelBoost.Value);
                }
            }
            WinFormsUtil.Alert("Randomized all Gift Pokémon according to specification!");
        }
Example #6
0
        private void RandomizeWild(SpeciesRandomizer rand, bool fill)
        {
            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)
            {
                ApplyRand(area.GroundTable);
                ApplyRand(area.WaterTable);
                ApplyRand(area.SkyTable);

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

            void ApplyRand(IList <EncounterSlot> 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 #7
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        = false,
                    E        = false,
                    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)
                    {
                        int basic() => (int)(Util.rnd32() % BasicStarter.Length);

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

            if (blind)
            {
                saveData();
                Close();
            }
        }
Example #8
0
        public void EditRaids()
        {
            IFileContainer fp            = ROM.GetFile(GameFile.NestData);
            var            data_table    = new GFPack(fp[0]);
            const string   nest          = "nest_hole_encount.bin";
            var            nest_encounts = FlatBufferConverter.DeserializeFrom <EncounterNest8Archive>(data_table.GetDataFileName(nest));

            var arr   = nest_encounts.Table;
            var cache = new DataCache <EncounterNest8Table>(arr);
            var games = new[] { "Sword", "Shield" };
            var names = arr.Select((z, i) => $"{games[z.GameVersion - 1]} - {i / 2}").ToArray();

            void Randomize()
            {
                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 arr)
                {
                    foreach (var p in t.Entries)
                    {
                        p.Species      = srand.GetRandomSpecies(p.Species);
                        p.Form         = frand.GetRandomForme(p.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                        p.Ability      = 4;     // "A4" -- 1, 2, or H
                        p.Gender       = 0;     // random
                        p.IsGigantamax = false; // don't allow gmax flag on non-gmax species
                    }
                }
            }

            using var form = new GenericEditor <EncounterNest8Table>(cache, names, "Max Raid Battles Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                return;
            }
            var data = FlatBufferConverter.SerializeFrom(nest_encounts);

            data_table.SetDataFileName(nest, data);
            fp[0] = data_table.Write();
        }
Example #9
0
        private void RandomizeWild(SpeciesRandomizer rand, bool fill, bool boost)
        {
            var pt = ROM.Data.PersonalData;
            var fr = new FormRandomizer(pt);

            foreach (var area in Symbols.EncounterTables.Concat(Hidden.EncounterTables))
            {
                foreach (var sub in area.SubTables)
                {
                    if (boost)
                    {
                        sub.LevelMin = Legal.GetModifiedLevel(sub.LevelMin, (double)NUD_LevelBoost.Value);
                        sub.LevelMax = Legal.GetModifiedLevel(sub.LevelMax, (double)NUD_LevelBoost.Value);
                    }
                    ApplyRand(sub.Slots);
                }
            }

            void ApplyRand(IList <EncounterSlot8> 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.Form    = 0; // ensure it's not junk
                    }

                    s.Species = rand.GetRandomSpecies(s.Species);
                    s.Form    = fr.GetRandomForme(s.Species);
                    if (fill)
                    {
                        s.Probability = RandomScaledRates[slots.Count][i];
                    }
                }
            }
        }
Example #10
0
        public void EditStatic()
        {
            var file  = ROM[GameFile.EncounterStatic];
            var data  = file[0];
            var objs  = data.GetArray(z => new EncounterStatic7b(z), EncounterStatic7b.SIZE); // binary
            var names = Enumerable.Range(0, objs.Length).Select(z => $"{z:000}").ToArray();
            var cache = new DirectCache <EncounterStatic7b>(objs);

            void Randomize()
            {
                var spec = EditUtil.Settings.Species;

                spec.Gen2 = spec.Gen3 = spec.Gen4 = spec.Gen5 = spec.Gen6 = spec.Gen7 = false;
                var srand = new SpeciesRandomizer(ROM.Info, Data.PersonalData);
                var frand = new FormRandomizer(Data.PersonalData);

                srand.Initialize(spec);
                for (int i = 2; i < objs.Length; i++) // skip starters
                {
                    var t = objs[i];
                    t.Species      = (Species)srand.GetRandomSpecies((int)t.Species);
                    t.Form         = frand.GetRandomForme((int)t.Species, false, false, true, false, Data.PersonalData.Table);
                    t.Nature       = Nature.Random25;
                    t.Gender       = FixedGender.Random;
                    t.Shiny        = Shiny.Random;
                    t.RelearnMoves = new[] { 0, 0, 0, 0 };
                    if (t.IV_HP != -4)
                    {
                        t.IVs = new[] { -1, -1, -1, -1, -1, -1 }
                    }
                    ;
                }
            }

            using var form = new GenericEditor <EncounterStatic7b>(cache, names, "Static Encounter Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                file.CancelEdits();
            }
            else
            {
                file[0] = objs.SelectMany(z => z.Write()).ToArray();
            }
        }
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();
            for (int i = 0; i < LB_Encounters.Items.Count; i++)
            {
                LB_Encounters.SelectedIndex = i;

                int species = CB_Species.SelectedIndex;
                species = specrand.GetRandomSpecies(species);
                CB_Species.SelectedIndex = species;
                NUD_Form.Value           = formrand.GetRandomForme(species);
                NUD_Gender.Value         = 0; // random

                if (CHK_Level.Checked)
                {
                    NUD_Level.Value = Randomizer.getModifiedLevel((int)NUD_Level.Value, NUD_LevelBoost.Value);
                }
            }
            WinFormsUtil.Alert("Randomized all Static Encounters according to specification!");
        }
Example #12
0
    public void EditTrainers()
    {
        var folder = ROM.GetFilteredFolder(GameFile.TrainerData);
        var cache  = new DataCache <TrData8a>(folder)
        {
            Create = FlatBufferConverter.DeserializeFrom <TrData8a>,
            Write  = FlatBufferConverter.SerializeFrom,
        };
        var names = folder.GetPaths().Select(Path.GetFileNameWithoutExtension).ToArray();

        using var form = new GenericEditor <TrData8a>(cache, names, "Trainers", Randomize, canSave: true);
        form.ShowDialog();

        void Randomize()
        {
            var settings = EditUtil.Settings.Species;
            var rand     = new SpeciesRandomizer(ROM.Info, Data.PersonalData);

            rand.Initialize(settings, GetSpeciesBanlist());

            for (int i = 0; i < cache.Length; i++)
            {
                foreach (var t in cache[i].Team)
                {
                    t.Species          = rand.GetRandomSpecies(t.Species);
                    t.Form             = GetRandomForm(t.Species);
                    t.Gender           = (int)FixedGender.Random;
                    t.Nature           = NatureType8a.Random;
                    t.Move_01.Move     = t.Move_02.Move = t.Move_03.Move = t.Move_04.Move = 0;
                    t.Move_01.Mastered = t.Move_02.Mastered = t.Move_03.Mastered = t.Move_04.Mastered = true;
                    t.Shiny            = Randomization.Util.Random.Next(0, 100 + 1) < 3;
                    t.IsOybn           = Randomization.Util.Random.Next(0, 100 + 1) < 3;
                }
            }
        }

        if (!form.Modified)
        {
            cache.CancelEdits();
        }
        else
        {
            cache.Save();
        }
    }
Example #13
0
        public void EditDynamaxAdv()
        {
            var arc  = ROM.GetFile(GameFile.DynamaxDens);
            var data = arc[0];
            var objs = FlatBufferConverter.DeserializeFrom <EncounterUnderground8Archive>(data);

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

            void Randomize()
            {
                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 table)
                {
                    // what you receive
                    t.Species = srand.GetRandomSpecies(t.Species);
                    t.Form    = (byte)frand.GetRandomForme(t.Species, false, false, true, true, ROM.Data.PersonalData.Table);
                    t.Ability = (uint)Randomization.Util.Random.Next(1, 4); // 1, 2, or H
                    t.Move0   = t.Move1 = t.Move2 = t.Move3 = 0;
                }
            }

            using var form = new GenericEditor <EncounterUnderground8>(cache, names, "Dynamax Adventures Encounter Editor", Randomize);
            form.ShowDialog();
            if (!form.Modified)
            {
                arc.CancelEdits();
            }
            else
            {
                arc[0] = FlatBufferConverter.SerializeFrom(objs);
            }
        }
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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),
            });
        }