Exemplo n.º 1
0
        private void calcStats()
        {
            Move[] MoveData = Moves.getMoves();

            byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last());

            int movectr = 0;
            int max     = 0;
            int spec    = 0;
            int stab    = 0;
            int species = 0;

            for (int i = 0; i < 722; i++)
            {
                byte[] movedata = File.ReadAllBytes(files[i]);
                if (movedata.Length <= 2)
                {
                    continue;
                }
                int movecount = BitConverter.ToUInt16(movedata, 0);
                if (movecount == 65535 || movecount < 0)
                {
                    continue;
                }
                species++;
                movectr += movecount; // Average Moves
                if (max < movecount)
                {
                    max = movecount; spec = i;
                }                                                   // Max Moves (and species)
                for (int m = 1; m < movedata.Length / 2; m++)
                {
                    int move = BitConverter.ToUInt16(movedata, m * 2);
                    if (move == 65535)
                    {
                        movectr--;
                        continue;
                    }
                    if (MoveData[move].Type == personalData[6 + (Main.oras ? 0x50 : 0x40) * i] ||
                        MoveData[move].Type == personalData[7 + (Main.oras ? 0x50 : 0x40) * i])
                    {
                        stab++;
                    }
                }
            }
            Util.Alert(
                $"Moves Learned: {movectr}\r\nMost Learned: {max} @ {spec}\r\nSTAB Count: {stab}\r\nSpecies with EggMoves: {species}");
        }
Exemplo n.º 2
0
        public void calcStats() // Debug Function
        {
            Move[] MoveData = Moves.getMoves();

            byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last());

            int movectr = 0;
            int max     = 0;
            int spec    = 0;
            int stab    = 0;

            for (int i = 0; i < 722; i++)
            {
                byte[] movedata  = File.ReadAllBytes(files[i]);
                int    movecount = (movedata.Length - 4) / 4;
                if (movecount == 65535)
                {
                    continue;
                }
                movectr += movecount; // Average Moves
                if (max < movecount)
                {
                    max = movecount; spec = i;
                }                                                   // Max Moves (and species)
                for (int m = 0; m < movedata.Length / 4; m++)
                {
                    int move = BitConverter.ToUInt16(movedata, m * 4);
                    if (move == 65535)
                    {
                        movectr--;
                        continue;
                    }
                    if (MoveData[move].Type == personalData[6 + (Main.oras ? 0x50 : 0x40) * i] ||
                        MoveData[move].Type == personalData[7 + (Main.oras ? 0x50 : 0x40) * i])
                    {
                        stab++;
                    }
                }
            }
            Util.Alert($"Moves Learned: {movectr}\r\nMost Learned: {max} @ {spec}\r\nSTAB Count: {stab}");
        }
Exemplo n.º 3
0
        private void Randomize()
        {
            int[] banned = { 165, 621 }; // Struggle, Hyperspace Fury
            rImportant = new string[CB_TrainerID.Items.Count];
            rTags      = Main.oras ? GetTagsORAS() : GetTagsXY();
            mEvoTypes  = GetMegaEvolvableTypes();
            List <int> GymE4Types = new List <int>();

            // Fetch Move Stats for more difficult randomization
            var moveData = Moves.getMoves();

            int[] moveList = Enumerable.Range(1, movelist.Count() - 1).ToArray();
            int   mctr     = 0;

            Util.Shuffle(moveList);

            if (rEnsureMEvo.Length > 0)
            {
                if (mEvoTypes.Length < 13 && rTypeTheme)
                {
                    Util.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]]);
            }
            randomizing = true;
            for (int i = 1; i < CB_TrainerID.Items.Count; i++)
            {
                CB_TrainerID.SelectedIndex = i; // data is loaded

                // Setup
                checkBox_Moves.Checked = rMove || (!rNoMove && checkBox_Moves.Checked);
                checkBox_Item.Checked  = rItem || checkBox_Item.Checked;

                if (r6PKM && rImportant[i] != null) // skip the first rival battles
                {
                    // Copy the last slot to random pokemon
                    int lastPKM = Math.Max(CB_numPokemon.SelectedIndex - 1, 0); // 0,1-6 => 0-5 (never is 0)
                    CB_numPokemon.SelectedIndex = 6;
                    for (int f = lastPKM + 1; f < 6; f++)
                    {
                        trpk_pkm[f].SelectedIndex = trpk_IV[lastPKM].SelectedIndex;
                        trpk_lvl[f].SelectedIndex = Math.Min(trpk_lvl[f - 1].SelectedIndex + 1, 100);
                    }
                }

                // Randomize Trainer Stats
                if (rDiffAI)
                {
                    if (CB_Battle_Type.SelectedIndex == 0)
                    {
                        CB_AI.SelectedIndex = 7; // Max Single
                    }
                    else if (CB_Battle_Type.SelectedIndex == 1)
                    {
                        CB_AI.SelectedIndex = 135; // Max Double
                    }
                }
                if (
                    rClass && // Classes selected to be randomized
                    (!rOnlySingles || CB_Battle_Type.SelectedIndex == 0) && //  Nonsingles only get changed if rOnlySingles
                    !rIgnoreClass.Contains(CB_Trainer_Class.SelectedIndex)    // Current class isn't a special class
                    )
                {
                    int rv = (int)(rnd32() % CB_Trainer_Class.Items.Count);
                    // Ensure the Random Class isn't an exclusive class
                    while (rIgnoreClass.Contains(rv) && !trClass[rv].StartsWith("[~")) // don't allow disallowed classes
                    {
                        rv = (int)(rnd32() % CB_Trainer_Class.Items.Count);
                    }

                    CB_Trainer_Class.SelectedIndex = rv;
                }

                if (rGift && rnd32() % 100 < rGiftPercent)
                #region Random Prize Logic
                {
                    ushort[] items;
                    uint     rnd = rnd32() % 10;
                    if (rnd < 2) // held item
                    {
                        items = Main.oras ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
                    }
                    else if (rnd < 5) // medicine
                    {
                        items = Main.oras ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY;
                    }
                    else // berry
                    {
                        items = Legal.Pouch_Berry_XY;
                    }
                    CB_Prize.SelectedIndex = items[rnd32() % items.Length];
                }
                #endregion
                else if (rGift)
                {
                    CB_Prize.SelectedIndex = 0;
                }

                ushort[] itemvals = Main.oras ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY;
                itemvals = itemvals.Concat(Legal.Pouch_Berry_XY).ToArray();
                int itemC = itemvals.Length;
                int ctr   = 0;

                // Trainer Type/Mega Evo
                int  type     = GetRandomType(i);
                bool mevo     = rEnsureMEvo.Contains(i);
                bool typerand = rTypeTheme && !rGymE4Only ||
                                (rTypeTheme && rImportant[i] != null && (rImportant[i].Contains("GYM") || rImportant[i].Contains("ELITE") || rImportant[i].Contains("CHAMPION")));

                // Randomize Pokemon
                for (int p = 0; p < CB_numPokemon.SelectedIndex; p++)
                {
                    PersonalInfo oldpkm = Main.SpeciesStat[trpk_pkm[p].SelectedIndex];
                    PersonalInfo pkm    = null;
                    if (rPKM)
                    {
                        // randomize pokemon
                        int species;
                        pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                        if (typerand)
                        {
                            int tries = 0;
                            while (((pkm.Types[0] != type && pkm.Types[1] != type) || mevo && p == CB_numPokemon.SelectedIndex - 1 && !megaEvos.Contains(species)) && tries < 0x10000)
                            {
                                if (p == CB_numPokemon.SelectedIndex - 1 && mevo)
                                {
                                    pkm = Main.SpeciesStat[species = GetRandomMegaEvolvablePokemon(type)];
                                }
                                else if (rSmart) // Get a new Pokemon with a close BST
                                {
                                    pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                                    while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && pkm.BST * (6 + ++tries / 722) / 5 > oldpkm.BST))
                                    {
                                        pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                                    }
                                }
                                else
                                {
                                    pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                                }
                            }
                        }
                        else if (p == CB_numPokemon.SelectedIndex - 1 && mevo)
                        {
                            pkm = Main.SpeciesStat[species = megaEvos[rnd32() % megaEvos.Length]];
                        }
                        else if (rSmart) // Get a new Pokemon with a close BST
                        {
                            int tries = 0;
                            while (!((pkm.BST * (5 - ++tries / 722) / 6 < oldpkm.BST) && pkm.BST * (6 + ++tries / 722) / 5 > oldpkm.BST))
                            {
                                pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                            }
                        }

                        trpk_pkm[p].SelectedIndex = species;
                        // Set Gender to Random
                        trpk_gender[p].SelectedIndex = 0;

                        if (trpk_form[p].Items.Count > 0)
                        {
                            trpk_form[p].SelectedIndex = 0;
                        }
                        // Randomize form
                        if (trpk_form[p].Items.Count > 0 && (!megaEvos.Contains(species) || rRandomMegas))
                        {
                            trpk_form[p].SelectedIndex = (int)(rnd32() % trpk_form[p].Items.Count);
                        }
                    }
                    if (rLevel)
                    {
                        trpk_lvl[p].SelectedIndex = Math.Max(1, Math.Min((int)(trpk_lvl[p].SelectedIndex * ((100 + rLevelPercent) / 100)), 100));
                    }
                    if (rAbility)
                    {
                        trpk_abil[p].SelectedIndex = (int)(1 + rnd32() % 3);
                    }
                    if (rDiffIV)
                    {
                        trpk_IV[p].SelectedIndex = 255;
                    }
                    if (mevo && p == CB_numPokemon.SelectedIndex - 1)
                    {
                        int[] megastones = GetMegaStones(trpk_pkm[p].SelectedIndex);
                        if (megastones.Length > 0)
                        {
                            trpk_item[p].SelectedIndex = megastones[rnd32() % megastones.Length];
                        }
                    }
                    else if (rItem)
                    #region RandomItem
                    {
                        trpk_item[p].SelectedIndex = itemvals[rnd32() % itemC];
                    }
                    #endregion

                    if (rMove)
                    {
                        pkm = pkm ?? Main.SpeciesStat[trpk_pkm[p].SelectedIndex];
                        int[] pkMoves = new int[4];
                        var   moves   = new[] { trpk_m1[p], trpk_m2[p], trpk_m3[p], trpk_m4[p] };

                        int loopctr = 0;
getMoves:               // Get list of moves
                        loopctr++;
                        for (int m = 0; m < 4; m++)
                        {
                            int mv = Randomizer.getRandomSpecies(ref moveList, ref mctr);
                            while (banned.Contains(mv) || pkMoves.Contains(mv))
                            {
                                mv = Randomizer.getRandomSpecies(ref moveList, ref mctr);
                            }

                            pkMoves[m] = mv;
                        }

                        // If a certain amount of damaging moves is required, check.
                        if (rDMG)
                        {
                            int damagingMoves = pkMoves.Count(move => moveData[move].Category != 0);
                            if (damagingMoves < rDMGCount && loopctr < 666)
                            {
                                goto getMoves;
                            }
                        }
                        if (rSTAB)
                        {
                            int STAB = pkMoves.Count(move => pkm.Types.Contains(moveData[move].Type));
                            if (STAB < rSTABCount && loopctr < 666)
                            {
                                goto getMoves;
                            }
                        }

                        // Assign Moves
                        for (int m = 0; m < 4; m++)
                        {
                            moves[m].SelectedIndex = pkMoves[m];
                        }
                    }
                }
            }
            randomizing = false;
            CB_TrainerID.SelectedIndex = 1;
            Util.Alert("Randomized all trainers according to specification!", "Press the Dump to TXT to view the new trainer information!");
        }
Exemplo n.º 4
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            /*
             * 3111 Egg Moves Learned by 290 Species (10.73 avg)
             * 18 is the most
             * 1000 moves learned were STAB (32.1%)
             */
            Random rnd = new Random();

            ushort[] HMs = { 15, 19, 57, 70, 127, 249, 291 };
            ushort[] TMs = { };
            if (CHK_HMs.Checked && Main.ExeFSPath != null)
            {
                TMHM.getTMHMList(Main.oras, ref TMs, ref HMs);
            }

            int[] banned = new int[HMs.Length];
            for (int i = 0; i < banned.Length; i++)
            {
                banned[i] = HMs[i];
            }
            banned = banned.Concat(new[] { 165, 621 }).ToArray(); // Struggle, Hyperspace Fury

            // Move Stats
            Move[] moveTypes = Moves.getMoves();

            // Personal Stats
            byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last());

            // Set up Randomized Moves
            int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray();
            Util.Shuffle(randomMoves);
            int ctr = 0;

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                int count   = dgv.Rows.Count - 1;
                int species = Util.getIndex(CB_Species);
                if (count == 0)
                {
                    continue;
                }

                if (CHK_Expand.Checked && (int)NUD_Moves.Value > count)
                {
                    dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count);
                }
                for (int j = 0; j < dgv.Rows.Count - 1; j++)
                {
                    // Assign New Moves
                    bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value;
                    int  move      = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);
                    while (                                                                                // Move is invalid
                        (!CHK_HMs.Checked && banned.Contains(move)) || // HM Moves Not Allowed
                        (forceSTAB &&                                                                      // STAB is required
                         !(
                             moveTypes[move].Type == personalData[6 + (Main.oras ? 0x50 : 0x40) * species] // Type 1
                             ||
                             moveTypes[move].Type == personalData[7 + (Main.oras ? 0x50 : 0x40) * species] // Type 2
                             )
                        )
                        )
                    {
                        move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);
                    }

                    // Assign Move
                    dgv.Rows[j].Cells[0].Value = movelist[move];
                }
            }
            CB_Species.SelectedIndex = 0;
            Util.Alert("All Pokemon's Egg Moves have been randomized!");
        }
Exemplo n.º 5
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            // ORAS: 10682 moves learned on levelup/birth.
            // 5593 are STAB. 52.3% are STAB.
            // Steelix learns the most @ 25 (so many level 1)!
            // Move relearner ingame does not behave properly if the count exceeds 25:
            // https://twitter.com/Drayano60/status/630044237883666433
            Random rnd = new Random();

            int[] firstMoves = { 1, 40, 52, 55, 64, 71, 84, 98, 122, 141 };
            // Pound, Poison Sting, Ember, Water Gun, Peck, Absorb, Thunder Shock, Quick Attack, Lick, Leech Life

            ushort[] HMs = { 15, 19, 57, 70, 127, 249, 291 };
            ushort[] TMs = {};
            if (CHK_HMs.Checked && Main.ExeFSPath != null)
            {
                TMHM.getTMHMList(Main.oras, ref TMs, ref HMs);
            }

            int[] banned = new int[HMs.Length];
            for (int i = 0; i < banned.Length; i++)
            {
                banned[i] = HMs[i];
            }
            banned = banned.Concat(new[] { 165, 621 }).ToArray(); // Struggle, Hyperspace Fury

            // Move Stats
            Move[] moveTypes = Moves.getMoves();

            // Personal Stats
            byte[] personalData = File.ReadAllBytes(Directory.GetFiles("personal").Last());

            // Set up Randomized Moves
            int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray();
            Util.Shuffle(randomMoves);
            int ctr = 0;

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                int count   = dgv.Rows.Count - 1;
                int species = Util.getIndex(CB_Species);
                if (CHK_Expand.Checked && (int)NUD_Moves.Value > count)
                {
                    dgv.Rows.AddCopies(count, (int)NUD_Moves.Value - count);
                }

                // Default First Move
                dgv.Rows[0].Cells[0].Value = 1;
                dgv.Rows[0].Cells[1].Value = movelist[firstMoves[rnd.Next(0, firstMoves.Length)]];
                for (int j = 1; j < dgv.Rows.Count - 1; j++)
                {
                    // Assign New Moves
                    bool forceSTAB = CHK_STAB.Checked && rnd.Next(0, 99) < NUD_STAB.Value;
                    int  move      = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);
                    while (                                                                                // Move is invalid
                        (!CHK_HMs.Checked && banned.Contains(move)) || // HM Moves Not Allowed
                        (forceSTAB &&                                                                      // STAB is required
                         !(
                             moveTypes[move].Type == personalData[6 + (Main.oras ? 0x50 : 0x40) * species] // Type 1
                             ||
                             moveTypes[move].Type == personalData[7 + (Main.oras ? 0x50 : 0x40) * species] // Type 2
                             )
                        )
                        )
                    {
                        move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);
                    }

                    // Assign Move
                    dgv.Rows[j].Cells[1].Value = movelist[move];
                    // Assign Level
                    if (j >= count)
                    {
                        string level = (dgv.Rows[count - 1].Cells[0].Value ?? 0).ToString();
                        ushort lv;
                        UInt16.TryParse(level, out lv);
                        if (lv > 100)
                        {
                            lv = 100;
                        }
                        else if (lv == 0)
                        {
                            lv = 1;
                        }
                        dgv.Rows[j].Cells[0].Value = lv + (j - count) + 1;
                    }
                    if (CHK_Spread.Checked)
                    {
                        dgv.Rows[j].Cells[0].Value = (j * (NUD_Level.Value / (dgv.Rows.Count - 1))).ToString();
                    }
                }
            }
            CB_Species.SelectedIndex = 0;
            Util.Alert("All Pokemon's Level Up Moves have been randomized!");
        }