private TrainerRandomizer GetRandomizer() { var moves = Game.Data.MoveData.LoadAll(); var rmove = new MoveRandomizer(Game.Info, moves, Personal); int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves.Length); rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned); int[] ban = new int[0]; if (Game.Info.SWSH) { var pt = Game.Data.PersonalData; ban = pt.Table.Take(Game.Info.MaxSpeciesID + 1) .Select((z, i) => new { Species = i, Present = ((PersonalInfoSWSH)z).IsPresentInGame }) .Where(z => !z.Present).Select(z => z.Species).ToArray(); } var rspec = new SpeciesRandomizer(Game.Info, Personal); rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject, ban); learn.Moves = moves; var evos = Game.Data.EvolutionData; var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll(), evos.LoadAll()) { ClassCount = CB_Trainer_Class.Items.Count, Learn = learn, RandMove = rmove, RandSpec = rspec, GetBlank = () => (Game.Info.SWSH ? (TrainerPoke) new TrainerPoke8() : new TrainerPoke7b()), // this should probably be less specific }; trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject); return(trand); }
private void B_Randomize_Click(object sender, EventArgs e) { SaveEntry(); var moves = Game.Data.MoveData.LoadAll(); var rmove = new MoveRandomizer(Game.Info, moves, Personal); int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves); rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned); var rspec = new SpeciesRandomizer(Game.Info, Personal); rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject); var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll()) { ClassCount = CB_Trainer_Class.Items.Count, Learn = learn, RandMove = rmove, RandSpec = rspec, GetBlank = () => new TrainerPoke7b(), // this should probably be less specific }; trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject); trand.Execute(); LoadEntry(); System.Media.SystemSounds.Asterisk.Play(); }
private TrainerRandomizer GetRandomizer() { var moves = Game.Data.MoveData.LoadAll(); var rmove = new MoveRandomizer(Game.Info, moves, Personal); int[] banned = Legal.GetBannedMoves(Game.Info.Game, moves.Length); rmove.Initialize((MovesetRandSettings)PG_Moves.SelectedObject, banned); var rspec = new SpeciesRandomizer(Game.Info, Personal); rspec.Initialize((SpeciesSettings)PG_Species.SelectedObject); learn.Moves = moves; var evos = Game.Data.EvolutionData; var trand = new TrainerRandomizer(Game.Info, Personal, Trainers.LoadAll(), evos.LoadAll()) { ClassCount = CB_Trainer_Class.Items.Count, Learn = learn, RandMove = rmove, RandSpec = rspec, GetBlank = () => (Game.Info.SWSH ? (TrainerPoke) new TrainerPoke8() : new TrainerPoke7b()), // this should probably be less specific }; trand.Initialize((TrainerRandSettings)PG_RTrainer.SelectedObject); return(trand); }
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!"); }
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]; } } } }
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!"); }
private static void Main(string[] args) { string inPath = null, outPath = $"{DateTime.Now.Ticks}.nds"; if (args.Length > 0) { inPath = args[0]; } if (args.Length > 1) { outPath = args[1]; } if (inPath == null) { Console.WriteLine(@"Input path was not specified"); return; } var romHandler = new Gen5RomHandler(inPath); // TODO: Given pokemons were not randomized // TODO: Field items not randomized var world = new WorldRandomizer(romHandler); world.RandomizeStarters(true); world.RandomizeStaticPokemon(true); world.RandomizeIngameTrades(true, true, true); world.RandomizeFieldItems(true); world.RandomizeHiddenHollowPokemon(); // TODO: Only Shedinjas var trainer = new TrainerRandomizer(romHandler); trainer.TypeThemeTrainerPokes(true, false, true, true); var wild = new WildRandomizer(romHandler); wild.RandomEncounters(EncountersRandomization.CatchEmAll, false); // TODO: TMs were not randomized var move = new MoveRandomizer(romHandler); move.RandomizeTmMoves(true, false, true, 1.0); move.RandomizeTmhmCompatibility(TmsHmsCompatibility.RandomPreferType); move.RandomizeMoveTutorMoves(true, false, 1.0); move.RandomizeMoveTutorCompatibility(true); var util = new UtilityTweacker(romHandler); util.ApplyFastestText(); util.RemoveBrokenMoves(); util.RemoveTradeEvolutions(false); if (File.Exists(outPath)) { for (;;) { Console.Write(@"{0} allready exists. Want to replace it? [Y/n]: "); var readLine = Console.ReadLine(); if (readLine == null) { continue; } var answer = readLine.Trim().ToLower(); Console.WriteLine(); if (answer == "" || answer == "y") { File.Delete(outPath); romHandler.SaveRom(outPath); break; } if (answer == "n") { break; } } } else { romHandler.SaveRom(outPath); } }
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 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) { 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 = move.GetRandomMoveset(pk.Species, 4); break; case 2: // Current LevelUp pk.Moves = learn.GetCurrentMoves(pk.Species, pk.Form, pk.Level, 4); break; case 3: // High Attacks pk.Moves = learn.GetHighPoweredMoves(pk.Species, pk.Form, 4); break; } // 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!"); }
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]; } } } }