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); } }
private void B_RandAll_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Static Encounters? Cannot undo.", "Double check Randomization Settings before continuing.") != DialogResult.Yes) { return; } setGift(); setEncounter(); setTrade(); var specrand = getRandomizer(); var formrand = new FormRandomizer(Main.Config) { AllowMega = false, AllowAlolanForm = true }; var move = new LearnsetRandomizer(Main.Config, Main.Config.Learnsets); for (int i = 3; i < Gifts.Length; i++) // Skip Starters { var t = Gifts[i]; t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } } foreach (EncounterStatic7 t in Encounters) { t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); t.RelearnMoves = move.GetCurrentMoves(t.Species, t.Form, t.Level, 4); if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } } foreach (EncounterTrade7 t in Trades) { t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); t.TradeRequestSpecies = specrand.GetRandomSpecies(t.TradeRequestSpecies); if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } } getListBoxEntries(); getGift(); getEncounter(); getTrade(); WinFormsUtil.Alert("Randomized Static Encounters according to specification!"); }
private void B_Starters_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Starters? Cannot undo.", "Double check Randomization settings before continuing.") != DialogResult.Yes) { return; } setGift(); var specrand = getRandomizer(); var formrand = new FormRandomizer(Main.Config) { AllowMega = false, AllowAlolanForm = true }; // Assign Species for (int i = 0; i < 3; i++) { var t = Gifts[i]; t.Species = specrand.GetRandomSpecies(oldStarters[i]); t.Form = formrand.GetRandomForme(t.Species); // no level boosting } getListBoxEntries(); getGift(); WinFormsUtil.Alert("Randomized Starters according to specification!"); }
private void B_Starters_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Starters? Cannot undo.", "Double check Randomization settings before continuing.") != DialogResult.Yes) { return; } setGift(); var specrand = getRandomizer(); var formrand = new FormRandomizer(Main.Config) { AllowMega = false, AllowAlolanForm = true }; var items = Randomizer.getRandomItemList(); // Assign Species for (int i = 0; i < 3; i++) { var t = Gifts[i]; t.Species = specrand.GetRandomSpecies(oldStarters[i]); t.Form = formrand.GetRandomForme(t.Species); t.Nature = -1; // random if (CHK_AllowMega.Checked) { formrand.AllowMega = true; } if (CHK_Item.Checked) { t.HeldItem = items[Util.rnd32() % items.Length]; } if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } if (CHK_RemoveShinyLock.Checked) { t.ShinyLock = false; // in case any user modifications locked the starters } if (CHK_SpecialMove.Checked) { t.SpecialMove = Util.rand.Next(1, CB_SpecialMove.Items.Count); // don't allow none } if (CHK_RandomAbility.Checked) { t.Ability = (sbyte)(Util.rand.Next(0, 3)); // 1, 2, or H } } getListBoxEntries(); getGift(); WinFormsUtil.Alert("Randomized Starters according to specification!"); }
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!"); }
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); } }
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(); }
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]; } } } }
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(); } }
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(); } }
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!"); }
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); } }
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!"); }
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!"); }
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); } }
private void B_RandAll_Click(object sender, EventArgs e) { if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Randomize Static Encounters? Cannot undo.", "Double check Randomization Settings before continuing.") != DialogResult.Yes) { return; } setGift(); setEncounter(); setTrade(); var specrand = getRandomizer(); var formrand = new FormRandomizer(Main.Config) { AllowMega = false, AllowAlolanForm = true }; var move = new LearnsetRandomizer(Main.Config, Main.Config.Learnsets); var items = Randomizer.getRandomItemList(); for (int i = 3; i < Gifts.Length; i++) // Skip Starters { var t = Gifts[i]; t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); t.Nature = -1; // random if (CHK_AllowMega.Checked) { formrand.AllowMega = true; } if (CHK_Item.Checked) { t.HeldItem = items[Util.rnd32() % items.Length]; } if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } if (CHK_RemoveShinyLock.Checked) { t.ShinyLock = false; } if (CHK_SpecialMove.Checked) { t.SpecialMove = Util.rand.Next(1, CB_SpecialMove.Items.Count); // don't allow none } if (CHK_RandomAbility.Checked) { t.Ability = (sbyte)(Util.rand.Next(0, 3)); // 1, 2, or H } } foreach (EncounterStatic7 t in Encounters) { t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); t.RelearnMoves = move.GetCurrentMoves(t.Species, t.Form, t.Level, 4); t.Gender = 0; // random t.Nature = 0; // random if (CHK_AllowMega.Checked) { formrand.AllowMega = true; } if (CHK_Item.Checked) { t.HeldItem = items[Util.rnd32() % items.Length]; } if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } if (CHK_RemoveShinyLock.Checked) { t.ShinyLock = false; } if (CHK_RandomAura.Checked && t.Aura != 0) // don't apply aura to a pkm without it { t.Aura = Util.rand.Next(1, CB_Aura.Items.Count); // don't allow none } if (CHK_RandomAbility.Checked) { t.Ability = (sbyte)(Util.rand.Next(1, 4)); // 1, 2, or H } } foreach (EncounterTrade7 t in Trades) { t.Species = specrand.GetRandomSpecies(t.Species); t.Form = formrand.GetRandomForme(t.Species); t.TradeRequestSpecies = specrand.GetRandomSpecies(t.TradeRequestSpecies); t.Nature = (int)(Util.rnd32() % CB_TNature.Items.Count); // randomly selected if (CHK_AllowMega.Checked) { formrand.AllowMega = true; } if (CHK_Item.Checked) { t.HeldItem = items[Util.rnd32() % items.Length]; } if (CHK_Level.Checked) { t.Level = Randomizer.getModifiedLevel(t.Level, NUD_LevelBoost.Value); } if (CHK_RandomAbility.Checked) { t.Ability = (sbyte)(Util.rand.Next(0, 3)); // 1, 2, or H } } getListBoxEntries(); getGift(); getEncounter(); getTrade(); WinFormsUtil.Alert("Randomized Static Encounters according to specification!"); }
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); } }