From caf9e635b42fc7ed95bba25bf7bee2eec9314dbb Mon Sep 17 00:00:00 2001 From: sora10pls Date: Wed, 1 Jul 2020 15:16:03 -0400 Subject: [PATCH] Add AllowRandomFusions to Trainer Randomizer Settings Move BattleExclusiveForms outside of Tables7 since it'll be used for every Generation, and update it with Gen 8 species. Also fix FormRandomizer allowing Zen/Galarian Zen Darmanitan. --- .../Randomizers/EvolutionRandomizer.cs | 2 +- .../Randomizers/FormRandomizer.cs | 14 +++---- .../Settings/TrainerRandSettings.cs | 3 ++ .../Randomizers/TrainerRandomizer.cs | 6 +-- pkNX.Structures/Legality/Legal.cs | 39 +++++++++++++++++++ pkNX.Structures/Legality/Tables7.cs | 36 ----------------- pkNX.WinForms/MainEditor/EditorGG.cs | 6 +-- pkNX.WinForms/MainEditor/EditorSWSH.cs | 23 +++-------- pkNX.WinForms/Subforms/BTTE.cs | 6 ++- pkNX.WinForms/Subforms/SSWE.cs | 2 +- 10 files changed, 66 insertions(+), 71 deletions(-) diff --git a/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs b/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs index cbf7e26d..4bfa88b7 100644 --- a/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs +++ b/pkNX.Randomization/Randomizers/EvolutionRandomizer.cs @@ -47,7 +47,7 @@ private void Randomize(EvolutionSet evos, int species) if (evo.Method != 0) { evo.Species = RandSpec.GetRandomSpecies(evo.Species, species); - evo.Form = RandForm.GetRandomForme(evo.Species, false, true, Game.SWSH, Personal.Table); + evo.Form = RandForm.GetRandomForme(evo.Species, false, false, true, Game.SWSH, Personal.Table); } } } diff --git a/pkNX.Randomization/Randomizers/FormRandomizer.cs b/pkNX.Randomization/Randomizers/FormRandomizer.cs index b6d700ad..7adf0457 100644 --- a/pkNX.Randomization/Randomizers/FormRandomizer.cs +++ b/pkNX.Randomization/Randomizers/FormRandomizer.cs @@ -14,7 +14,7 @@ public FormRandomizer(PersonalTable t) Personal = t; } - public int GetRandomForme(int species, bool mega, bool alola, bool galar, PersonalInfo[] stats = null) + public int GetRandomForme(int species, bool mega, bool fused, bool alola, bool galar, PersonalInfo[] stats = null) { if (stats == null) stats = Personal.Table; @@ -28,7 +28,6 @@ public int GetRandomForme(int species, bool mega, bool alola, bool galar, Person case Sawsbuck: return 31; // Random case Greninja when !mega: - case Eternatus: return 0; case Scatterbug: case Spewpa: @@ -37,15 +36,13 @@ public int GetRandomForme(int species, bool mega, bool alola, bool galar, Person case Minior: return Util.Random.Next(7); // keep the core color a surprise - // Galarian Forms - case Meowth when galar: // Kanto, Alola, Galar - return Util.Random.Next(3); - case Darmanitan when galar: // Standard, Zen, Galar Standard, Galar Zen - return Util.Random.Next(4); + case Meowth when galar: + return Util.Random.Next(3); // Kanto, Alola, Galar // some species have 1 invalid form among several other valid forms, handle them here case Pikachu when Personal.TableLength == 1181: case Slowbro when galar: + case Darmanitan: { int form = Util.Random.Next(stats[species].FormeCount - 1); int banned = GetInvalidForm(species, galar, Personal); @@ -61,7 +58,7 @@ public int GetRandomForme(int species, bool mega, bool alola, bool galar, Person return Util.Random.Next(2); if (galar && Legal.EvolveToGalarForms.Contains(species)) return Util.Random.Next(2); - if (!Legal.BattleExclusiveForms.Contains(species) || mega) + if (!Legal.BattleExclusiveForms.Contains(species) || mega || fused && Legal.BattleFusions.Contains(species)) return Util.Random.Next(stats[species].FormeCount); // Slot-Random return 0; } @@ -72,6 +69,7 @@ public int GetInvalidForm(int species, bool galar, PersonalTable stats) { (int)Pikachu when stats.TableLength == 1181 => 8, // LGPE Partner Pikachu (int)Slowbro when galar => 1, // Mega Slowbro + (int)Darmanitan => 1, // Zen Mode _ => throw new ArgumentOutOfRangeException(nameof(species)) }; } diff --git a/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs b/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs index d5009a58..acf55a94 100644 --- a/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs +++ b/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs @@ -50,6 +50,9 @@ public class TrainerRandSettings [Category(PKM), Description("Allows random Mega Forms when randomizing species.")] public bool AllowRandomMegaForms { get; set; } = false; + [Category(PKM), Description("Allows random Fused PKM when randomizing species.")] + public bool AllowRandomFusions { get; set; } = false; + [Category(PKM), Description("Allows random Held Items when randomizing species.")] public bool AllowRandomHeldItems { get; set; } = false; diff --git a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs index 5ae5e42f..965128a1 100644 --- a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs +++ b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs @@ -162,7 +162,7 @@ private void RandomizeSpecFormItem(IPokeData pk, int Type) else // every other pkm { pk.Species = RandSpec.GetRandomSpeciesType(pk.Species, Type); - pk.Form = RandForm.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, true, Personal.Table); + pk.Form = RandForm.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, Settings.AllowRandomFusions, true, true, Personal.Table); } } @@ -181,7 +181,7 @@ private void RandomizeSpecForm(TrainerPoke7b pk, int type) else { pk.Species = RandSpec.GetRandomSpeciesType(pk.Species, type); - pk.Form = RandForm.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, true, false, Personal.Table); + pk.Form = RandForm.GetRandomForme(pk.Species, Settings.AllowRandomMegaForms, Settings.AllowRandomFusions, true, false, Personal.Table); } } @@ -255,7 +255,7 @@ private void UpdatePKMFromSettings(TrainerPoke pk) return; c.Species = AllowedGigantamaxes[Util.Random.Next(AllowedGigantamaxes.Length)]; - c.Form = c.Species == (int)Species.Pikachu || c.Species == (int)Species.Meowth ? 0 : RandForm.GetRandomForme(c.Species, false, false, false, Personal.Table); // Pikachu & Meowth altforms can't gmax + c.Form = c.Species == (int)Species.Pikachu || c.Species == (int)Species.Meowth ? 0 : RandForm.GetRandomForme(c.Species, false, false, false, false, Personal.Table); // Pikachu & Meowth altforms can't gmax } if (Settings.MaxDynamaxLevel && c.CanDynamax) c.DynamaxLevel = 10; diff --git a/pkNX.Structures/Legality/Legal.cs b/pkNX.Structures/Legality/Legal.cs index 69658236..8843009d 100644 --- a/pkNX.Structures/Legality/Legal.cs +++ b/pkNX.Structures/Legality/Legal.cs @@ -191,5 +191,44 @@ public static int[] GetAllowedMoves(GameVersion infoGame, int moveCount) 406, 417, 420, 430, 438, 446, 453, 483, 492, 499, 503, 504, 525, 529, 583, 585, 605, 742 }; + + public static readonly HashSet BattleForms = new HashSet + { + (int)Species.Castform, + (int)Species.Cherrim, + (int)Species.Meloetta, + (int)Species.Aegislash, + (int)Species.Xerneas, + (int)Species.Wishiwashi, + (int)Species.Mimikyu, + (int)Species.Cramorant, + (int)Species.Eiscue, + (int)Species.Morpeko, + (int)Species.Zacian, + (int)Species.Zamazenta, + (int)Species.Eternatus, + }; + + public static readonly HashSet BattleMegas = new HashSet + { + // XY + (int)Species.Venusaur, (int)Species.Charizard, (int)Species.Blastoise, (int)Species.Alakazam, (int)Species.Gengar, + (int)Species.Kangaskhan, (int)Species.Pinsir, (int)Species.Gyarados, (int)Species.Aerodactyl, (int)Species.Mewtwo, + (int)Species.Ampharos, (int)Species.Scizor, (int)Species.Heracross, (int)Species.Houndoom, (int)Species.Tyranitar, + (int)Species.Blaziken, (int)Species.Gardevoir, (int)Species.Mawile, (int)Species.Aggron, (int)Species.Medicham, + (int)Species.Manectric, (int)Species.Banette, (int)Species.Absol, (int)Species.Latias, (int)Species.Latios, + (int)Species.Garchomp, (int)Species.Lucario, (int)Species.Abomasnow, + + // AO + (int)Species.Beedrill, (int)Species.Pidgeot, (int)Species.Slowbro, (int)Species.Steelix, + (int)Species.Sceptile, (int)Species.Swampert, (int)Species.Sableye, (int)Species.Sharpedo, (int)Species.Camerupt, + (int)Species.Altaria, (int)Species.Glalie, (int)Species.Salamence, (int)Species.Metagross, (int)Species.Rayquaza, + (int)Species.Lopunny, (int)Species.Gallade, + (int)Species.Audino, (int)Species.Diancie, + }; + + public static readonly HashSet BattlePrimals = new HashSet { 382, 383 }; // Kyogre and Groudon + public static readonly HashSet BattleFusions = new HashSet { 646, 800 }; // Kyurem and Necrozma + public static HashSet BattleExclusiveForms = new HashSet(BattleForms.Concat(BattleMegas.Concat(BattlePrimals).Concat(BattleFusions))); } } diff --git a/pkNX.Structures/Legality/Tables7.cs b/pkNX.Structures/Legality/Tables7.cs index ebe44808..ebe1128a 100644 --- a/pkNX.Structures/Legality/Tables7.cs +++ b/pkNX.Structures/Legality/Tables7.cs @@ -233,41 +233,5 @@ public static partial class Legal }; public static readonly ushort[] HeldItemsBuy_SM = new ushort[1].Concat(Pouch_Items_SM).Concat(Pouch_Medicine_SM).ToArray(); - - public static readonly HashSet BattleForms = new HashSet - { - (int)Species.Castform, - (int)Species.Cherrim, - (int)Species.Darmanitan, - (int)Species.Meloetta, - (int)Species.Aegislash, - (int)Species.Xerneas, - (int)Species.Wishiwashi, - (int)Species.Mimikyu, - }; - - public static readonly HashSet BattleMegas = new HashSet - { - // XY - (int)Species.Venusaur, (int)Species.Charizard, (int)Species.Blastoise, (int)Species.Alakazam, (int)Species.Gengar, - (int)Species.Kangaskhan, (int)Species.Pinsir, (int)Species.Gyarados, (int)Species.Aerodactyl, (int)Species.Mewtwo, - (int)Species.Ampharos, (int)Species.Scizor, (int)Species.Heracross, (int)Species.Houndoom, (int)Species.Tyranitar, - (int)Species.Blaziken, (int)Species.Gardevoir, (int)Species.Mawile, (int)Species.Aggron, (int)Species.Medicham, - (int)Species.Manectric, (int)Species.Banette, (int)Species.Absol, (int)Species.Latias, (int)Species.Latios, - (int)Species.Garchomp, (int)Species.Lucario, (int)Species.Abomasnow, - - // AO - (int)Species.Beedrill, (int)Species.Pidgeot, (int)Species.Slowbro, (int)Species.Steelix, - (int)Species.Sceptile, (int)Species.Swampert, (int)Species.Sableye, (int)Species.Sharpedo, (int)Species.Camerupt, - (int)Species.Altaria, (int)Species.Glalie, (int)Species.Salamence, (int)Species.Metagross, (int)Species.Rayquaza, - (int)Species.Lopunny, (int)Species.Gallade, - (int)Species.Audino, (int)Species.Diancie, - - // USUM - (int)Species.Necrozma, // Ultra - }; - - public static readonly HashSet BattlePrimals = new HashSet { 382, 383 }; - public static HashSet BattleExclusiveForms = new HashSet(BattleForms.Concat(BattleMegas.Concat(BattlePrimals))); } } diff --git a/pkNX.WinForms/MainEditor/EditorGG.cs b/pkNX.WinForms/MainEditor/EditorGG.cs index 9fe98119..de3f6735 100644 --- a/pkNX.WinForms/MainEditor/EditorGG.cs +++ b/pkNX.WinForms/MainEditor/EditorGG.cs @@ -125,7 +125,7 @@ void Randomize() foreach (var t in objs) { t.Species = (Species)srand.GetRandomSpecies((int)t.Species); - t.Form = frand.GetRandomForme((int)t.Species, false, true, false, ROM.Data.PersonalData.Table); + t.Form = frand.GetRandomForme((int)t.Species, false, false, true, false, ROM.Data.PersonalData.Table); t.Nature = Nature.Random25; t.Gender = FixedGender.Random; t.Shiny = Shiny.Random; @@ -162,7 +162,7 @@ void Randomize() { t.Species = (Species)srand.GetRandomSpecies((int)t.Species); t.RequiredSpecies = (Species)srand.GetRandomSpecies((int)t.Species); - t.Form = frand.GetRandomForme((int)t.Species, false, true, false, ROM.Data.PersonalData.Table); + t.Form = frand.GetRandomForme((int)t.Species, false, false, true, false, ROM.Data.PersonalData.Table); t.RequiredForm = 0; // can't catch wild alolan forms t.Nature = Nature.Random - 1; t.Gender = FixedGender.Random; @@ -200,7 +200,7 @@ void Randomize() { var t = objs[i]; t.Species = (Species)srand.GetRandomSpecies((int)t.Species); - t.Form = frand.GetRandomForme((int)t.Species, false, true, false, ROM.Data.PersonalData.Table); + t.Form = frand.GetRandomForme((int)t.Species, false, false, true, false, ROM.Data.PersonalData.Table); t.Nature = Nature.Random25; t.Gender = FixedGender.Random; t.Shiny = Shiny.Random; diff --git a/pkNX.WinForms/MainEditor/EditorSWSH.cs b/pkNX.WinForms/MainEditor/EditorSWSH.cs index 98e36367..0a650353 100644 --- a/pkNX.WinForms/MainEditor/EditorSWSH.cs +++ b/pkNX.WinForms/MainEditor/EditorSWSH.cs @@ -244,7 +244,7 @@ void Randomize() foreach (var p in t.Entries) { p.Species = srand.GetRandomSpecies(p.Species); - p.AltForm = frand.GetRandomForme(p.Species, false, true, true, ROM.Data.PersonalData.Table); + p.AltForm = 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 @@ -349,7 +349,7 @@ void Randomize() if (t.Species >= Species.Zacian && t.Species <= Species.Eternatus) // Eternatus crashes when changed, keep Zacian and Zamazenta to make final boss battle fair continue; t.Species = (Species)srand.GetRandomSpecies((int)t.Species); - t.AltForm = frand.GetRandomForme((int)t.Species, false, true, true, ROM.Data.PersonalData.Table); + 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.HeldItem = PossibleHeldItems[Randomization.Util.Random.Next(PossibleHeldItems.Length)]; t.Nature = Nature.Random25; @@ -397,12 +397,12 @@ void Randomize() if (t.CanGigantamax) { 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, ROM.Data.PersonalData.Table); // Pikachu & Meowth altforms can't gmax + 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, true, true, ROM.Data.PersonalData.Table); + 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 @@ -450,7 +450,7 @@ void Randomize() { // what you receive t.Species = (Species)srand.GetRandomSpecies((int)t.Species); - t.AltForm = frand.GetRandomForme((int)t.Species, false, true, true, ROM.Data.PersonalData.Table); + 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)]; @@ -463,7 +463,7 @@ void Randomize() // what you trade t.RequiredSpecies = (Species)srand.GetRandomSpecies((int)t.RequiredSpecies); - t.RequiredForm = frand.GetRandomForme((int)t.RequiredSpecies, false, true, true, ROM.Data.PersonalData.Table); + t.RequiredForm = frand.GetRandomForme((int)t.RequiredSpecies, false, false, true, true, ROM.Data.PersonalData.Table); t.RequiredNature = Nature.Random25; // any } } @@ -476,17 +476,6 @@ void Randomize() arc[0] = FlatBufferConverter.SerializeFrom(objs); } - private bool CreateGenericEditor(ref byte[] data, string title, string[] names = null) where TA : IFlatBufferArchive where T1 : class - { - var objs = FlatBufferConverter.DeserializeFrom(data); - if (names == null) - names = Enumerable.Range(1, objs.Table.Length).Select(z => z.ToString()).ToArray(); - var result = PopEdit(objs.Table, title, names); - if (result) - data = FlatBufferConverter.SerializeFrom(objs); - return result; - } - private bool PopEdit(T[] data, string title, string[] names) where T : class { var cache = new DirectCache(data); diff --git a/pkNX.WinForms/Subforms/BTTE.cs b/pkNX.WinForms/Subforms/BTTE.cs index 47ab5df0..56500f40 100644 --- a/pkNX.WinForms/Subforms/BTTE.cs +++ b/pkNX.WinForms/Subforms/BTTE.cs @@ -487,16 +487,18 @@ private string GetTrainerString(VsTrainer Trainer) sb.AppendLine("======"); sb.Append(file).Append(" - ").Append(trClass[tr.Class]).Append(" ").AppendLine(name); sb.AppendLine("======"); - sb.Append("Pokemon: ").Append(tr.NumPokemon).AppendLine(); + sb.Append("Pokémon: ").Append(tr.NumPokemon).AppendLine(); for (int i = 0; i < tr.NumPokemon; i++) { var pk = team[i]; if (pk.Shiny) sb.Append("Shiny "); sb.Append(specieslist[pk.Species]); + if (pk.Form > 0) + sb.Append("-" + pk.Form); sb.Append(" (Lv. ").Append(pk.Level).Append(") "); if (pk.HeldItem > 0) - sb.Append("@").Append(itemlist[pk.HeldItem]); + sb.Append("@ ").Append(itemlist[pk.HeldItem]); if (pk.Nature != 0) sb.Append(" (Nature: ").Append(natures[pk.Nature]).Append(")"); diff --git a/pkNX.WinForms/Subforms/SSWE.cs b/pkNX.WinForms/Subforms/SSWE.cs index e30caee0..93cae9c0 100644 --- a/pkNX.WinForms/Subforms/SSWE.cs +++ b/pkNX.WinForms/Subforms/SSWE.cs @@ -192,7 +192,7 @@ void ApplyRand(IList slots) } s.Species = rand.GetRandomSpecies(s.Species); - s.Form = fr.GetRandomForme(s.Species, false, true, true, ROM.Data.PersonalData.Table); + s.Form = fr.GetRandomForme(s.Species, false, false, true, true, ROM.Data.PersonalData.Table); if (fill) s.Probability = RandomScaledRates[slots.Count][i]; }