Example #1
0
        private void writeFile()
        {
            // Set Trainer Data
            tr.Moves      = checkBox_Moves.Checked;
            tr.Item       = checkBox_Item.Checked;
            tr.Class      = CB_Trainer_Class.SelectedIndex;
            tr.BattleType = (byte)CB_Battle_Type.SelectedIndex;
            tr.NumPokemon = (byte)CB_numPokemon.SelectedIndex;
            if (tr.NumPokemon == 0)
            {
                tr.NumPokemon = 1; // No empty teams!
            }
            tr.Items[0] = (ushort)CB_Item_1.SelectedIndex;
            tr.Items[1] = (ushort)CB_Item_2.SelectedIndex;
            tr.Items[2] = (ushort)CB_Item_3.SelectedIndex;
            tr.Items[3] = (ushort)CB_Item_4.SelectedIndex;
            tr.AI       = (byte)CB_AI.SelectedIndex;
            tr.Healer   = checkBox_Healer.Checked;
            tr.Money    = (byte)CB_Money.SelectedIndex;
            tr.Prize    = (ushort)CB_Prize.SelectedIndex;

            // Set Pokemon Data
            Array.Resize(ref tr.Team, tr.NumPokemon);
            for (int i = 0; i < tr.NumPokemon; i++)
            {
                if (tr.Team[i] == null)
                {
                    tr.Team[i] = new trdata6.Pokemon(new byte[100], false, false); // Initialize with zeroes
                }
                tr.Team[i].IVs     = (byte)trpk_IV[i].SelectedIndex;
                tr.Team[i].Ability = trpk_abil[i].SelectedIndex;
                tr.Team[i].Gender  = trpk_gender[i].SelectedIndex;
                tr.Team[i].Level   = (ushort)trpk_lvl[i].SelectedIndex;
                tr.Team[i].Species = (ushort)trpk_pkm[i].SelectedIndex;
                tr.Team[i].Form    = (ushort)trpk_form[i].SelectedIndex;
                tr.Team[i].Item    = (ushort)trpk_item[i].SelectedIndex;

                tr.Team[i].Moves[0] = (ushort)trpk_m1[i].SelectedIndex;
                tr.Team[i].Moves[1] = (ushort)trpk_m2[i].SelectedIndex;
                tr.Team[i].Moves[2] = (ushort)trpk_m3[i].SelectedIndex;
                tr.Team[i].Moves[3] = (ushort)trpk_m4[i].SelectedIndex;
            }
            byte[] trd = tr.Write();
            trdata[index] = trd;
            byte[] trp = tr.WriteTeam();
            trpoke[index] = trp;
        }
Example #2
0
        private void Randomize()
        {
            List <int> banned = new List <int> {
                165, 621
            };                                             // Struggle, Hyperspace Fury

            if (rNoFixedDamage)
            {
                banned.AddRange(MoveRandomizer.FixedDamageMoves);
            }
            var move = new MoveRandomizer(Main.Config)
            {
                rDMG        = rDMG,
                rSTAB       = rSTAB,
                rSTABCount  = rSTABCount,
                rDMGCount   = rDMGCount,
                BannedMoves = banned,
            };

            rImportant = new string[CB_TrainerID.Items.Count];
            rTags      = Main.Config.ORAS ? GetTagsORAS() : GetTagsXY();
            mEvoTypes  = GetMegaEvolvableTypes();
            List <int> GymE4Types = new List <int>();

            // Fetch Move Stats for more difficult randomization

            if (rEnsureMEvo.Length > 0)
            {
                if (mEvoTypes.Length < 13 && rTypeTheme)
                {
                    WinFormsUtil.Alert("There are insufficient Types with at least one mega evolution to Guarantee story Mega Evos while keeping Type theming.",
                                       "Re-Randomize Personal or don't choose both options."); return;
                }
                GymE4Types.AddRange(mEvoTypes);
            }
            else
            {
                GymE4Types.AddRange(Enumerable.Range(0, types.Length).ToArray());
            }
            foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1] != "" && !TagTypes.Keys.Contains(rTags[t1])))
            {
                int t;
                if (rTags[t1].Contains("GYM") || rTags[t1].Contains("ELITE") || rTags[t1].Contains("CHAMPION"))
                {
                    t = GymE4Types[(int)(rnd32() % GymE4Types.Count)];
                    GymE4Types.Remove(t);
                }
                else
                {
                    t = mEvoTypes[rnd32() % mEvoTypes.Length];
                }
                TagTypes[rTags[t1]] = t;
            }
            foreach (string t1 in Tags)
            {
                if (!TagTypes.Keys.Contains(t1) && t1 != "")
                {
                    int t;
                    if (t1.Contains("GYM") || t1.Contains("ELITE") || t1.Contains("CHAMPION"))
                    {
                        t = GymE4Types[(int)(rnd32() % GymE4Types.Count)];
                        GymE4Types.Remove(t);
                    }
                    else
                    {
                        t = (int)(rnd32() % types.Length);
                    }

                    TagTypes[t1] = t;
                }
                Console.WriteLine(t1 + ": " + types[TagTypes[t1]]);
            }

            CB_TrainerID.SelectedIndex = 0; // fake a writeback
            ushort[] itemvals = Main.Config.ORAS ? Legal.Pouch_Items_AO : Legal.Pouch_Items_XY;
            itemvals = itemvals.Concat(Legal.Pouch_Berry_XY).ToArray();

            string[] ImportantClasses = { "GYM", "ELITE", "CHAMPION" };
            for (int i = 1; i < CB_TrainerID.Items.Count; i++)
            {
                // Trainer Type/Mega Evo
                int  type     = GetRandomType(i);
                bool mevo     = rEnsureMEvo.Contains(i);
                bool typerand = rTypeTheme && !rGymE4Only ||
                                rTypeTheme && rImportant[i] != null && ImportantClasses.Contains(rImportant[i]);
                rSpeciesRand.rType = typerand;

                byte[] trd = trdata[i];
                byte[] trp = trpoke[i];
                var    t   = new trdata6(trd, trp, Main.Config.ORAS)
                {
                    Moves = rMove || !rNoMove && checkBox_Moves.Checked,
                    Item  = rItem || checkBox_Item.Checked
                };

                InitializeTrainerTeamInfo(t, rImportant[i] == null);
                RandomizeTrainerAIClass(t, trClass);
                RandomizeTrainerPrizeItem(t);
                RandomizeTeam(t, move, learn, itemvals, type, mevo, typerand);

                trdata[i] = t.Write();
                trpoke[i] = t.WriteTeam();
            }
            CB_TrainerID.SelectedIndex = 1;
            WinFormsUtil.Alert("Randomized all Trainers according to specification!", "Press the Dump to .TXT button to view the new Trainer information!");
        }