Skip to content

Commit

Permalink
Fixed evolution logic condition in wild randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nifyr committed Sep 26, 2023
1 parent d89361d commit 02b2323
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -761,28 +759,21 @@ private void RandomizeEncounterList(List<Encounter> 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<Pokemon, Pokemon> 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));
}
}
}
Expand Down

0 comments on commit 02b2323

Please sign in to comment.