public void RandomizeStaticPokemon(bool legendForLegend) { // Load var currentStaticPokemon = RomHandler.StaticPokemon; if (legendForLegend) { var legendariesLeft = ValidPokemons.ToList(); var nonlegsLeft = ValidPokemons.ToList(); legendariesLeft.RemoveAll(p => !p.Legendary); nonlegsLeft.RemoveAll(p => p.Legendary); for (var i = 0; i < currentStaticPokemon.Length; ++i) { if (currentStaticPokemon[i].Legendary) { var num = Random.Next(legendariesLeft.Count); currentStaticPokemon[i] = legendariesLeft[num]; legendariesLeft.RemoveAt(num); if (legendariesLeft.Count != 0) { continue; } legendariesLeft.AddRange(ValidPokemons.Where(p => p.Legendary)); } else { var num = Random.Next(nonlegsLeft.Count); currentStaticPokemon[i] = nonlegsLeft[num]; nonlegsLeft.RemoveAt(num); if (nonlegsLeft.Count != 0) { continue; } nonlegsLeft.AddRange(ValidPokemons.Where(p => !p.Legendary)); } } } else { var pokemonLeft = ValidPokemons.ToList(); for (var i = 0; i < currentStaticPokemon.Length; i++) { var num = Random.Next(pokemonLeft.Count); currentStaticPokemon[i] = pokemonLeft[num]; pokemonLeft.RemoveAt(num); if (pokemonLeft.Count == 0) { pokemonLeft.AddRange(ValidPokemons); } } } }
public void Game1To1Encounters(bool useTimeOfDay, bool usePowerLevels, bool noLegendaries) { var pickFrom = noLegendaries ? ValidPokemons.Where(p => !p.Legendary) : ValidPokemons; var enumerable = pickFrom as Pokemon[] ?? pickFrom.ToArray(); // Build the full 1-to-1 map var translateMap = new Dictionary <Pokemon, Pokemon>(); var remainingLeft = ValidPokemons.ToList(); var remainingRight = enumerable.ToList(); while (remainingLeft.Count != 0) { if (usePowerLevels) { var pickedLeft = Random.Next(remainingLeft.Count); var pickedLeftP = remainingLeft[pickedLeft]; remainingLeft.RemoveAt(pickedLeft); var pickedRightP = remainingRight.Count == 1 ? remainingRight[0] : PickWildPowerLvlReplacement(remainingRight, pickedLeftP, true, null); remainingRight.Remove(pickedRightP); translateMap[pickedLeftP] = pickedRightP; } else { var pickedLeft = Random.Next(remainingLeft.Count); var pickedRight = Random.Next(remainingRight.Count); var pickedLeftP = remainingLeft[pickedLeft]; var pickedRightP = remainingRight[pickedRight]; remainingLeft.RemoveAt(pickedLeft); while (pickedLeftP.Id == pickedRightP.Id && remainingRight.Count != 1) { // Reroll for a different pokemon if at all possible pickedRight = Random.Next(remainingRight.Count); pickedRightP = remainingRight[pickedRight]; } remainingRight.RemoveAt(pickedRight); translateMap[pickedLeftP] = pickedRightP; } if (remainingRight.Count != 0) { continue; } remainingRight.AddRange(enumerable); } // Map remaining to themselves just in case var allPokes = ValidPokemons; foreach (var poke in allPokes) { if (!translateMap.ContainsKey(poke)) { translateMap[poke] = poke; } } foreach (var area in RomHandler.Encounters) { foreach (var enc in area.Encounters) { // Apply the map enc.Pokemon1 = translateMap[enc.Pokemon1]; if (!area.BannedPokemon.Contains(enc.Pokemon1)) { continue; } // Ignore the map and put a random non-banned poke var tempPickable = enumerable.ToList(); tempPickable.RemoveAll(area.BannedPokemon.Contains); if (tempPickable.Count == 0) { throw new NotImplementedException("ERROR: Couldn\'t replace a wild Pokemon!"); } if (usePowerLevels) { enc.Pokemon1 = PickWildPowerLvlReplacement(tempPickable, enc.Pokemon1, false, null); } else { var picked = Random.Next(tempPickable.Count); enc.Pokemon1 = tempPickable[picked]; } } } }