namespace HSchool.People; /// /// A name set can speak several native languages; the school picks one. Empty request rolls from /// the school seed so the same create always lands on the same tongue. /// public static class NativeLanguages { public static bool Allows(NameSetDef names, string skill) => names.Spoken.Contains(skill, StringComparer.Ordinal); /// /// must already be in the set, or empty. Invalid ids return /// null so the create path can 400. When omitted, a new school rolls; a reload without a /// saved pick takes the first listed language so old saves do not reshuffle intake. /// public static string? Pick(NameSetDef names, int schoolSeed, string? requested, bool rollIfOmitted) { var spoken = names.Spoken; if (spoken.Count == 0) { return null; } if (!string.IsNullOrWhiteSpace(requested)) { return Allows(names, requested) ? requested : null; } if (!rollIfOmitted || spoken.Count == 1) { return spoken[0]; } var rng = new Random(Seed.ForSchool(schoolSeed, Seed.NativeLanguageSalt)); return spoken[rng.Next(spoken.Count)]; } }