diff --git a/PersonalityGen.cs b/PersonalityGen.cs index d03a313..8a67c5b 100644 --- a/PersonalityGen.cs +++ b/PersonalityGen.cs @@ -2,15 +2,61 @@ namespace PersonaForge; public static class PersonalityGen { - int MaxPoints = 10; - int TotalBudget = 25; + const int MaxPoints = 10; + const int TotalBudget = 25; + static readonly Random rng = new(); public static PersonalityProfile GeneratePersonalityProfile() { var profile = PersonalityProfile.Create(); var traits = new List { "Outgoing", "Nice", "Playful", "Neat", "Active" }; + var remaining = TotalBudget; + while (remaining > 0) + { + var trait = traits[rng.Next(traits.Count)]; + var current = GetCurrentTraitPoints(profile, trait); + if (current < MaxPoints) + { + var add = (rng.NextDouble() < 0.1) ? Math.Min(2, MaxPoints - current) : 1; + add = Math.Min(add, remaining); + SetTraitPoints(profile, trait, current + add); + remaining -= add; + } + } return profile; } + + static int GetCurrentTraitPoints(PersonalityProfile p, string trait) => trait switch + { + "Outgoing" => p.Outgoing, + "Nice" => p.Nice, + "Playful" => p.Playful, + "Neat" => p.Neat, + "Active" => p.Active, + _ => 0 + }; + + static void SetTraitPoints(PersonalityProfile p, string trait, int points) + { + switch (trait) + { + case "Outgoing": + p.Outgoing = points; + break; + case "Nice": + p.Nice = points; + break; + case "Playful": + p.Playful = points; + break; + case "Neat": + p.Neat = points; + break; + case "Active": + p.Active = points; + break; + } + } } diff --git a/README.md b/README.md index 7e82cf6..5e642e1 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ PersonaForge is intended to help you generate a personality for The Sims 2. It i ### 🔍 Background -With Sims 3 and later, creating personalities is as simple as selecting a trait. Sims 2 doesn’t have traits in the same way later installments do. You had to figure out what kind of Sim you wanted based on the traits and points you had to spend. Even if you knew what you wanted, you didn’t know how to spend the rest. This was created to solve that. +With Sims 3 and later, creating personalities is as simple as selecting a trait. Sims 2 doesn’t have traits in the same way later installments do. You had to figure out what kind of Sim you wanted based on certain qualities and points you had to spend. Even if you knew what you wanted, you didn’t know how to spend the rest. This was created to solve that. ## 📄 License