From 02b2323d15937d93ead2242d386c53ae33a7aff7 Mon Sep 17 00:00:00 2001 From: Nifyr Date: Tue, 26 Sep 2023 23:31:56 +0200 Subject: [PATCH] Fixed evolution logic condition in wild randomizer --- Randomizer.cs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Randomizer.cs b/Randomizer.cs index 17ff42f..0bd4d6c 100644 --- a/Randomizer.cs +++ b/Randomizer.cs @@ -599,18 +599,16 @@ private void RandomizeTrainerPokemonSpecies(IDistribution distribution, bool leg foreach (TrainerPokemon trainerPokemon in trainer.trainerPokemon) { - Pokemon pokemon = GetRandom(gameData.dexEntries[distribution.Next(trainerPokemon.dexID)].forms); - if (evolveLogic) - pokemon = FindStage(pokemon, trainerPokemon.level, false); bool acceptLegendary = !legendLogic || P(trainerPokemon.level); - while (!pokemon.IsValid() || - typeThemes && typing != -1 && !pokemon.GetTyping().Contains(typing) || - !acceptLegendary && legendaryDexIDs.Contains(pokemon.dexID)) + Pokemon pokemon = gameData.GetPokemon(trainerPokemon.dexID, trainerPokemon.formID); + do { pokemon = GetRandom(gameData.dexEntries[distribution.Next(pokemon.dexID)].forms); if (evolveLogic) pokemon = FindStage(pokemon, trainerPokemon.level, false); - } + } while (!pokemon.IsValid() || + typeThemes && typing != -1 && !pokemon.GetTyping().Contains(typing) || + !acceptLegendary && legendaryDexIDs.Contains(pokemon.dexID)); trainerPokemon.dexID = pokemon.dexID; trainerPokemon.formID = (ushort)pokemon.formID; @@ -761,28 +759,21 @@ private void RandomizeEncounterList(List encounters, bool randomizeSp if (randomizeSpecies) { bool acceptLegendary = !legendLogic || P(encounter.GetAvgLevel()); - encounter.dexID = speciesDistribution.Next((ushort)encounter.dexID); - if (randomizeFormIDs) - { - encounter.dexID += rng.Next(gameData.dexEntries[(ushort)encounter.dexID].forms.Count) << 16; - Pokemon p = FindStage(gameData.GetPokemon((ushort)encounter.dexID, encounter.dexID >> 16), (int)encounter.GetAvgLevel(), true); - encounter.dexID = p.dexID + (p.formID << 16); - } - else - encounter.dexID = FindStage(gameData.personalEntries[(ushort)encounter.dexID], (int)encounter.GetAvgLevel(), true).dexID; - while (!gameData.GetPokemon((ushort)encounter.dexID, encounter.dexID >> 16).IsValid() || - !acceptLegendary && legendaryDexIDs.Contains((ushort)encounter.dexID)) + Func resolveStage = evolveLogic ? p => FindStage(p, (int)encounter.GetAvgLevel(), true) : p => p; + + do { encounter.dexID = speciesDistribution.Next((ushort)encounter.dexID); if (randomizeFormIDs) { encounter.dexID += rng.Next(gameData.dexEntries[(ushort)encounter.dexID].forms.Count) << 16; - Pokemon p = FindStage(gameData.GetPokemon((ushort)encounter.dexID, encounter.dexID >> 16), (int)encounter.GetAvgLevel(), true); + Pokemon p = resolveStage(gameData.GetPokemon((ushort)encounter.dexID, encounter.dexID >> 16)); encounter.dexID = p.dexID + (p.formID << 16); } else - encounter.dexID = FindStage(gameData.personalEntries[(ushort)encounter.dexID], (int)encounter.GetAvgLevel(), true).dexID; - } + encounter.dexID = resolveStage(gameData.personalEntries[(ushort)encounter.dexID]).dexID; + } while (!gameData.GetPokemon((ushort)encounter.dexID, encounter.dexID >> 16).IsValid() || + !acceptLegendary && legendaryDexIDs.Contains((ushort)encounter.dexID)); } } }