private (int index, ResidentArea8a area) LoadAreaByName(string name) { var index = Array.IndexOf(AreaNames, name); var area = new ResidentArea8a(Resident, Settings.Find(name)); area.LoadInfo(); return(index, area); }
private void RandomizeArea(ResidentArea8a area, SpeciesSettings settings) { var pt = ROM.Data.PersonalData; var rand = new SpeciesRandomizer(ROM.Info, pt); var hasForm = new HashSet <int>(); var banned = new HashSet <int>(); foreach (var pi in pt.Table.Cast <PersonalInfoLA>()) { if (pi.IsPresentInGame) { banned.Remove(pi.Species); hasForm.Add(pi.Species); } else if (!hasForm.Contains(pi.Species)) { banned.Add(pi.Species); } } settings.Legends = false; // Legendary encounter slot conditions require you to not have captured the Legendary in order to encounter them; ban altogether. rand.Initialize(settings, banned.ToArray()); var formRand = pt.Table .Cast <PersonalInfoLA>() .Where(z => z.IsPresentInGame && !(Legal.BattleExclusiveForms.Contains(z.Species) || Legal.BattleFusions.Contains(z.Species))) .GroupBy(z => z.Species) .ToDictionary(z => z.Key, z => z.ToList()); var encounters = area.Encounters; foreach (var table in encounters) { foreach (var enc in table.Table) { if (enc.ShinyLock is not ShinyType8a.Random) { continue; } // to progress the story in Cobalt Coastlands, you are required to show Iscan a Dusclops; ensure one can be captured if (enc.Species is (int)Dusclops && table.TableID is 7663383561364099763) { continue; } var spec = rand.GetRandomSpecies(enc.Species); enc.Species = spec; enc.Form = GetRandomForm(spec); enc.ClearMoves(); } } int GetRandomForm(int spec) { if (!formRand.TryGetValue(spec, out var entries)) { return(0); } var count = entries.Count; return((Species)spec switch { Growlithe or Arcanine or Voltorb or Electrode or Typhlosion or Qwilfish or Samurott or Lilligant or Zorua or Zoroark or Braviary or Sliggoo or Goodra or Avalugg or Decidueye => 1, Basculin => 2, Kleavor => 0, _ => Util.Random.Next(0, count), }); }