Exemplo n.º 1
0
        private static void RandomizeTrainerAIClass(trdata6 t, string[] trClass)
        {
            if (rDiffAI)
            {
                t.AI |= 7;                                                                       // Set first 3 bits, keep any other flag if present
            }
            if (rClass && rModelRestricted.Contains(t.Class) && !rIgnoreClass.Contains(t.Class)) // shuffle classes with 3D models
            {
                int randClass() => (int)(Rand() % rModelRestricted.Length);

                t.Class = rModelRestricted[randClass()];
            }
            else
            if (
                rClass && // Classes selected to be randomized
                (!rOnlySingles || t.BattleType == 0) && //  Nonsingles only get changed if rOnlySingles
                !rIgnoreClass.Contains(t.Class)    // Current class isn't a special class
                )
            {
                int randClass() => (int)(Rand() % trClass.Length);

                int rv; do
                {
                    rv = randClass();
                }while (rIgnoreClass.Contains(rv) || trClass[rv].StartsWith("[~") || (Main.Config.ORAS && (rv >= 0 && rv <= 63)) || (rv >= 68 && rv <= 126)); // don't allow disallowed classes
                t.Class = rv;
            }
        }
Exemplo n.º 2
0
 private static void RandomizeTrainerPrizeItem(trdata6 t)
 {
     if (rGift && rnd32() % 100 < rGiftPercent)
     {
         ushort[] items;
         uint     rnd = rnd32() % 10;
         if (rnd < 2) // held item
         {
             items = Main.Config.ORAS ? Legal.Pouch_Items_AO : Legal.Pouch_Items_XY;
         }
         else if (rnd < 5) // medicine
         {
             items = Main.Config.ORAS ? Legal.Pouch_Medicine_AO : Legal.Pouch_Medicine_XY;
         }
         else // berry
         {
             items = Legal.Pouch_Berry_XY;
         }
         t.Prize = items[rnd32() % items.Length];
     }
     else if (rGift)
     {
         t.Prize = 0;
     }
 }
Exemplo n.º 3
0
        private static void SetFullParties(trdata6 t, bool important)
        {
            int lastPKM  = Math.Max(t.NumPokemon - 1, 0); // 0,1-6 => 0-5 (never is 0)
            var avgBST   = (int)t.Team.Average(pk => Main.SpeciesStat[pk.Species].BST);
            int avgLevel = (int)t.Team.Average(pk => pk.Level);
            var pinfo    = Main.SpeciesStat.OrderBy(pk => Math.Abs(avgBST - pk.BST)).First();
            int avgSpec  = Array.IndexOf(Main.SpeciesStat, pinfo);

            // 6 pkm for important trainers, skip the first rival battles
            if (!r6PKM || important)
            {
                return;
            }

            t.NumPokemon = 6;
            for (int f = lastPKM + 1; f < t.NumPokemon; f++)
            {
                Array.Resize(ref t.Team, t.NumPokemon);
                t.Team[f] = // clone last pkm, keeping an average level for all new pkm
                            new trdata6.Pokemon(t.Team[lastPKM].Write(t.Item, t.Moves), t.Item, t.Moves)
                {
                    Species = (ushort)rSpeciesRand.GetRandomSpecies(avgSpec),
                    Level   = (ushort)avgLevel,
                };
            }
        }
Exemplo n.º 4
0
        private static void SetMinMaxPKM(trdata6 t)
        {
            int lastPKM  = Math.Max(t.NumPokemon - 1, 0); // 0,1-6 => 0-5 (never is 0)
            var avgBST   = (int)t.Team.Average(pk => Main.SpeciesStat[pk.Species].BST);
            int avgLevel = (int)t.Team.Average(pk => pk.Level);
            var pinfo    = Main.SpeciesStat.OrderBy(pk => Math.Abs(avgBST - pk.BST)).First();
            int avgSpec  = Array.IndexOf(Main.SpeciesStat, pinfo);

            // set minimum pkm, don't modify hordes
            if (t.NumPokemon < rMinPKM && t.BattleType != 4)
            {
                t.NumPokemon = (byte)rMinPKM;
                for (int f = lastPKM + 1; f < t.NumPokemon; f++)
                {
                    Array.Resize(ref t.Team, (int)rMinPKM);
                    t.Team[f] = // clone last pkm, keeping an average level for all new pkm
                                new trdata6.Pokemon(t.Team[lastPKM].Write(t.Item, t.Moves), t.Item, t.Moves)
                    {
                        Species = (ushort)rSpeciesRand.GetRandomSpecies(avgSpec),
                        Level   = (ushort)avgLevel,
                    };
                }
            }

            // set maximum pkm, don't modify hordes
            if (t.NumPokemon > rMaxPKM && t.BattleType != 4)
            {
                Array.Resize(ref t.Team, (int)rMaxPKM);
                t.NumPokemon = (byte)rMaxPKM;
            }
        }
Exemplo n.º 5
0
        private static void RandomizeTrainerAIClass(trdata6 t, string[] trClass)
        {
            if (rDiffAI)
            {
                t.AI |= 7; // Set first 3 bits, keep any other flag if present
            }
            if (rOnlySingles)
            {
                t.AI &= 7;
            }

            if (rClass && rModelRestricted.Contains(t.Class)) // Classes selected to be randomized
            {
                //if (rIgnoreClass.Any()) // ignored special classes
                //    return;
                int randClass() => (int)(rnd32() % rModelRestricted.Length);

                t.Class = rModelRestricted[randClass()];
            }
            else
            if (
                rClass && // Classes selected to be randomized
                (!rOnlySingles || t.BattleType == 0) && //  Nonsingles only get changed if rOnlySingles
                !rIgnoreClass.Contains(t.Class)    // Current class isn't a special class
                )
            {
                int randClass() => (int)(rnd32() % trClass.Length);

                int rv; do
                {
                    rv = randClass();
                }
                // Ensure the Random Class isn't an exclusive class
                while (rIgnoreClass.Contains(rv) || trClass[rv].StartsWith("[~")); // don't allow disallowed classes
                t.Class = rv;

                if (Main.Config.ORAS && t.Class <= 126) // 0 to 126 from XY, re-randomize to something from ORAS
                {
                    int fixClass() => (int)(rnd32() % rTrainerClasses.Length);

                    t.Class = rTrainerClasses[fixClass()];
                }
            }
        }
Exemplo n.º 6
0
        private static void InitializeTrainerTeamInfo(trdata6 t, bool important)
        {
            // skip the first rival battles
            if (!r6PKM || important)
            {
                return;
            }

            // Copy the last slot to random pokemon
            int lastPKM = Math.Max(t.NumPokemon - 1, 0); // 0,1-6 => 0-5 (never is 0)

            t.NumPokemon = 6;
            Array.Resize(ref t.Team, t.NumPokemon);
            for (int f = lastPKM + 1; f < t.NumPokemon; f++)
            {
                t.Team[f] = // clone last pkm then increment level by 1
                            new trdata6.Pokemon(t.Team[lastPKM].Write(t.Item, t.Moves), t.Item, t.Moves)
                {
                    Level = (ushort)Math.Min(t.Team[f - 1].Level + 1, 100)
                };
            }
        }
Exemplo n.º 7
0
        private static void RandomizeTeam(trdata6 t, MoveRandomizer move, LearnsetRandomizer learn, ushort[] itemvals, int type, bool mevo, bool typerand)
        {
            int last = t.Team.Length - 1;

            for (int p = 0; p < t.Team.Length; p++)
            {
                var   pk     = t.Team[p];
                int[] stones = null;
                if (rPKM)
                {
                    // randomize pokemon
                    int species;
                    if (typerand)
                    {
                        species = rSpeciesRand.GetRandomSpeciesType(pk.Species, type);
                        if (p == last && mevo)
                        {
                            int tries = 0;
                            do
                            {
                                stones = GetRandomMega(out species);
                            }while (Main.Config.Personal[species].Types.All(z => z != type) && tries++ < 100);
                        }
                    }
                    else if (p == last && mevo)
                    {
                        stones = GetRandomMega(out species);
                    }
                    else
                    {
                        species = rSpeciesRand.GetRandomSpecies(pk.Species);
                    }

                    pk.Species = (ushort)species;
                    pk.Gender  = 0;                                  // Set Gender to Random
                    bool mega = rRandomMegas & !(mevo && p == last); // except if mega evolution is forced for the last slot
                    pk.Form = (ushort)Randomizer.GetRandomForme(pk.Species, mega, true, Main.SpeciesStat);
                }
                if (rLevel)
                {
                    pk.Level = (ushort)Randomizer.getModifiedLevel(pk.Level, rLevelMultiplier);
                }
                if (rAbility)
                {
                    pk.Ability = (int)(1 + rnd32() % 3);
                }
                if (rDiffIV)
                {
                    pk.IVs = 255;
                }

                if (mevo && p == last && stones != null)
                {
                    pk.Item = (ushort)stones[rnd32() % stones.Length];
                }
                else if (rItem)
                {
                    pk.Item = itemvals[rnd32() % itemvals.Length];
                }

                if (rForceFullyEvolved && pk.Level >= rForceFullyEvolvedLevel && !rFinalEvo.Contains(pk.Species))
                {
                    int randFinalEvo() => (int)(Util.rnd32() % rFinalEvo.Length);

                    pk.Species = (ushort)rFinalEvo[randFinalEvo()];
                    pk.Form    = (ushort)Randomizer.GetRandomForme(pk.Species, rRandomMegas, true, Main.SpeciesStat);
                }

                // random
                if (rMove)
                {
                    var pkMoves = move.GetRandomMoveset(pk.Species, 4);
                    for (int m = 0; m < 4; m++)
                    {
                        pk.Moves[m] = (ushort)pkMoves[m];
                    }
                }

                // levelup
                if (rNoMove)
                {
                    t.Moves = true;
                    var pkMoves = learn.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4);
                    for (int m = 0; m < 4; m++)
                    {
                        pk.Moves[m] = (ushort)pkMoves[m];
                    }
                }

                // high-power attacks
                if (rForceHighPower && pk.Level >= rForceHighPowerLevel)
                {
                    var pkMoves = learn.GetHighPoweredMoves(pk.Species, pk.Form, 4);
                    for (int m = 0; m < 4; m++)
                    {
                        pk.Moves[m] = (ushort)pkMoves[m];
                    }
                }
            }
        }
Exemplo n.º 8
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!");
        }
Exemplo n.º 9
0
        private void readFile()
        {
            if (start)
            {
                return;
            }
            index   = CB_TrainerID.SelectedIndex;
            loading = true;

            if (index == 0)
            {
                return;
            }

            tabControl1.Enabled = true;
            byte[] trd = trdata[index];
            byte[] trp = trpoke[index];
            tr = new trdata6(trd, trp, Main.Config.ORAS);

            // Load Trainer Data
            CB_Trainer_Class.SelectedIndex = tr.Class;
            checkBox_Item.Checked          = tr.Item;
            checkBox_Moves.Checked         = tr.Moves;
            CB_Battle_Type.SelectedIndex   = tr.BattleType;
            CB_numPokemon.SelectedIndex    = tr.NumPokemon;
            CB_Item_1.SelectedIndex        = tr.Items[0];
            CB_Item_2.SelectedIndex        = tr.Items[1];
            CB_Item_3.SelectedIndex        = tr.Items[2];
            CB_Item_4.SelectedIndex        = tr.Items[3];
            CB_AI.SelectedIndex            = tr.AI;
            checkBox_Healer.Checked        = tr.Healer;
            CB_Money.SelectedIndex         = tr.Money;
            CB_Prize.SelectedIndex         = tr.Prize;

            // Load Pokemon Data
            for (int i = 0; i < tr.NumPokemon; i++)
            {
                trpk_IV[i].SelectedIndex  = tr.Team[i].IVs;
                trpk_lvl[i].SelectedIndex = tr.Team[i].Level;
                trpk_pkm[i].SelectedIndex = tr.Team[i].Species;
                FormUtil.setForms(tr.Team[i].Species, trpk_form[i], AltForms);
                trpk_form[i].SelectedIndex = tr.Team[i].Form % trpk_form[i].Items.Count; // stupid X/Y buggy edge cases (220 / 222)
                refreshPKMSlotAbility(i);                                                // Repopulate Abilities

                trpk_abil[i].SelectedIndex   = tr.Team[i].Ability;
                trpk_gender[i].SelectedIndex = tr.Team[i].Gender;

                trpk_item[i].SelectedIndex = tr.Team[i].Item;
                trpk_m1[i].SelectedIndex   = tr.Team[i].Moves[0];
                trpk_m2[i].SelectedIndex   = tr.Team[i].Moves[1];
                trpk_m3[i].SelectedIndex   = tr.Team[i].Moves[2];
                trpk_m4[i].SelectedIndex   = tr.Team[i].Moves[3];
            }
            loading = false;
            changeTrainerType(null, null); // Prompt cleaning update of PKM fields

            // Refresh Team View
            if (!loading)
            {
                for (int i = 0; i < 6; i++)
                {
                    showTeams(i);
                }
                // showText(); // Commented out for now, have to figure out how text is assigned.
            }
        }
Exemplo n.º 10
0
        private void readFile()
        {
            if (start) return;
            index = CB_TrainerID.SelectedIndex;
            loading = true;

            if (index == 0) return;

            tabControl1.Enabled = true;
            byte[] trd = trdata[index];
            byte[] trp = trpoke[index];
            tr = new trdata6(trd, trp, Main.Config.ORAS);

            // Load Trainer Data
            CB_Trainer_Class.SelectedIndex = tr.Class;
            checkBox_Item.Checked = tr.Item;
            checkBox_Moves.Checked = tr.Moves;
            CB_Battle_Type.SelectedIndex = tr.BattleType;
            CB_numPokemon.SelectedIndex = tr.NumPokemon;
            CB_Item_1.SelectedIndex = tr.Items[0];
            CB_Item_2.SelectedIndex = tr.Items[1];
            CB_Item_3.SelectedIndex = tr.Items[2];
            CB_Item_4.SelectedIndex = tr.Items[3];
            CB_AI.SelectedIndex = tr.AI;
            checkBox_Healer.Checked = tr.Healer;
            CB_Money.SelectedIndex = tr.Money;
            CB_Prize.SelectedIndex = tr.Prize;

            // Load Pokemon Data
            for (int i = 0; i < tr.NumPokemon; i++)
            {
                trpk_IV[i].SelectedIndex = tr.Team[i].IVs;
                trpk_lvl[i].SelectedIndex = tr.Team[i].Level;
                trpk_pkm[i].SelectedIndex = tr.Team[i].Species;
                FormUtil.setForms(tr.Team[i].Species, trpk_form[i], AltForms);
                trpk_form[i].SelectedIndex = tr.Team[i].Form % trpk_form[i].Items.Count; // stupid X/Y buggy edge cases (220 / 222)
                refreshPKMSlotAbility(i); // Repopulate Abilities

                trpk_abil[i].SelectedIndex = tr.Team[i].Ability;
                trpk_gender[i].SelectedIndex = tr.Team[i].Gender;

                trpk_item[i].SelectedIndex = tr.Team[i].Item;
                trpk_m1[i].SelectedIndex = tr.Team[i].Moves[0];
                trpk_m2[i].SelectedIndex = tr.Team[i].Moves[1];
                trpk_m3[i].SelectedIndex = tr.Team[i].Moves[2];
                trpk_m4[i].SelectedIndex = tr.Team[i].Moves[3];
            }
            loading = false;
            changeTrainerType(null, null); // Prompt cleaning update of PKM fields

            // Refresh Team View
            if (!loading && !randomizing)
            {
                for (int i = 0; i < 6; i++) showTeams(i);
                // showText(); // Commented out for now, have to figure out how text is assigned.
            }
        }
Exemplo n.º 11
0
        private static void RandomizeTeam(trdata6 t, MoveRandomizer move, ushort[] itemvals, int type, bool mevo, bool typerand)
        {
            int last = t.Team.Length - 1;

            for (int p = 0; p < t.Team.Length; p++)
            {
                var   pk     = t.Team[p];
                int[] stones = null;
                if (rPKM)
                {
                    // randomize pokemon
                    int species;
                    if (typerand)
                    {
                        species = rSpeciesRand.GetRandomSpeciesType(pk.Species, type);
                        if (p == last && mevo)
                        {
                            int tries = 0;
                            do
                            {
                                stones = GetRandomMega(out species);
                            }while (Main.Config.Personal[species].Types.All(z => z != type) && tries++ < 100);
                        }
                    }
                    else if (p == last && mevo)
                    {
                        stones = GetRandomMega(out species);
                    }
                    else
                    {
                        species = rSpeciesRand.GetRandomSpecies(pk.Species);
                    }

                    pk.Species = (ushort)species;
                    pk.Gender  = 0;                                  // Set Gender to Random
                    bool mega = rRandomMegas & !(mevo && p == last); // except if mega evolution is forced for the last slot
                    pk.Form = (ushort)Randomizer.GetRandomForme(pk.Species, mega, true, Main.SpeciesStat);
                }
                if (rLevel)
                {
                    pk.Level = (ushort)Randomizer.getModifiedLevel(pk.Level, rLevelMultiplier);
                }
                if (rAbility)
                {
                    pk.Ability = (int)(1 + rnd32() % 3);
                }
                if (rDiffIV)
                {
                    pk.IVs = 255;
                }

                if (mevo && p == last && stones != null)
                {
                    pk.Item = (ushort)stones[rnd32() % stones.Length];
                }
                else if (rItem)
                {
                    pk.Item = itemvals[rnd32() % itemvals.Length];
                }

                if (rMove)
                {
                    var pkMoves = move.GetRandomMoveset(pk.Species, 4);
                    for (int m = 0; m < 4; m++)
                    {
                        pk.Moves[m] = (ushort)pkMoves[m];
                    }
                }
            }
        }