From 1c7e301fd8e67da4e65d707190bbf060376b9a13 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Mon, 28 Apr 2025 10:46:43 -0400 Subject: [PATCH] Choose an archetype with fallback to random --- PersonaForge.csproj | 2 +- PersonalityArchetype.cs | 51 +++++++++++++++++++++++++++++++++++++---- PersonalityGen.cs | 14 ++++++++++- Program.cs | 22 ++++++++++++++++-- README.md | 4 ++-- 5 files changed, 82 insertions(+), 11 deletions(-) diff --git a/PersonaForge.csproj b/PersonaForge.csproj index 2b92219..c1b130b 100644 --- a/PersonaForge.csproj +++ b/PersonaForge.csproj @@ -2,7 +2,7 @@ Exe - 0.3.101 + 0.4.101 net9.0 enable enable diff --git a/PersonalityArchetype.cs b/PersonalityArchetype.cs index aecdfb7..6f1ceee 100644 --- a/PersonalityArchetype.cs +++ b/PersonalityArchetype.cs @@ -1,14 +1,14 @@ namespace PersonaForge; -public class PersonalityArchetype +public class Archetypes { public string Name { get; set; } public Dictionary TraitBiases { get; set; } = new(); // TODO: Load default archetypes from a file or database - public static List DefaultArchetypes() => new() + public static List DefaultArchetypes() => new() { - new PersonalityArchetype + new Archetypes { Name = "Grumpy", TraitBiases = new Dictionary @@ -20,7 +20,7 @@ public class PersonalityArchetype { "Active", 0.5 } } }, - new PersonalityArchetype + new Archetypes { Name = "Party Animal", TraitBiases = new Dictionary @@ -31,6 +31,47 @@ public class PersonalityArchetype { "Nice", 0.5 }, { "Neat", 0.3 } } + }, + new Archetypes + { + Name = "Lazy", + TraitBiases = new Dictionary + { + { "Nice", 0.8 }, + { "Playful", 0.6 }, + { "Outgoing", 0.4 }, + { "Neat", 0.2 }, + { "Active", 0.1 } + } + }, + new Archetypes + { + Name = "Shy", + TraitBiases = new Dictionary + { + { "Nice", 0.9 }, + { "Playful", 0.7 }, + { "Outgoing", 0.3 }, + { "Neat", 0.5 }, + { "Active", 0.2 } + } + }, + new Archetypes + { + Name = "Energetic", + TraitBiases = new Dictionary + { + { "Nice", 0.7 }, + { "Playful", 0.6 }, + { "Outgoing", 0.5 }, + { "Neat", 0.4 }, + { "Active", 0.3 } + } + }, + new Archetypes + { + Name = "Random", + TraitBiases = new() } - }; + }; } diff --git a/PersonalityGen.cs b/PersonalityGen.cs index d43ad20..636a674 100644 --- a/PersonalityGen.cs +++ b/PersonalityGen.cs @@ -6,12 +6,24 @@ public static class PersonalityGen const int TotalBudget = 25; static readonly Random rng = new(); - public static PersonalityTraits GenerateRandom() + public static PersonalityTraits GenerateRandom(Dictionary? bias = null) { var profile = PersonalityTraits.Create(); var traits = new List { "Outgoing", "Nice", "Playful", "Neat", "Active" }; var remaining = TotalBudget; + if (bias != null) + { + foreach (var kvp in bias) + { + var trait = kvp.Key; + var points = Convert.ToInt32(kvp.Value); + var safePoints = Math.Min(points, MaxPoints); + SetTraitPoints(profile, trait, safePoints); + remaining -= points; + } + } + while (remaining > 0) { var trait = traits[rng.Next(traits.Count)]; diff --git a/Program.cs b/Program.cs index c859975..80901dd 100644 --- a/Program.cs +++ b/Program.cs @@ -8,12 +8,30 @@ Console.WriteLine("=== Welcome to The Sims 2 Personality Generator ==="); Console.Write("Enter Sim's name: "); string name = Console.ReadLine() ?? "Unndanmed Sim"; -var qualities = PersonalityGen.GenerateRandom(); +// Move the conversion logic to a separate method +Console.WriteLine("\nAvailable Archetypes:"); +var archetypeList = Archetypes.DefaultArchetypes(); +var archetypeDict = new Dictionary>(); +foreach (var archetype in archetypeList) +{ + Console.WriteLine($"- {archetype.Name}"); + archetypeDict.Add(archetype.Name, archetype.TraitBiases); +} + +Console.Write("Enter archetype: "); +string archetypeInput = Console.ReadLine() ?? "Random"; +if (!archetypeDict.ContainsKey(archetypeInput)) +{ + Console.WriteLine("Invalid archetype. Using Random."); + archetypeInput = "Random"; +} + +var qualities = PersonalityGen.GenerateRandom(archetypeDict[archetypeInput]); var profile = new PersonaProfile { Name = name, Qualities = qualities, - Archetype = "Random" + Archetype = archetypeInput }; Console.WriteLine($"{name}'s Profile{Environment.NewLine}{PersonaProfile.ToJson(profile)}"); diff --git a/README.md b/README.md index 86ee6c9..71db207 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ With Sims 3 and later, creating personalities is as simple as selecting a trait. | ----- | ------------------------------------------- | ------ | | v0.1 | Core random point generator (working) | ✅ | | v0.2 | PersonalityProfile class | ✅ | -| v0.3 | Interactive JSON export | ✅ | -| v0.4 | Archetypes with weighted biases | 🔜 | +| v0.3 | Interactive JSON export | ✅ | +| v0.4 | Archetypes with weighted biases | ✅ | | v0.5 | Profile import/load from JSON | 🔜 | | v1.0 | Stable "Release" version with documentation | 🔜 |