diff --git a/Content.Server/Humanoid/Components/HumanoidComponent.cs b/Content.Server/Humanoid/Components/HumanoidComponent.cs index 062613d117..e3a6b1c90a 100644 --- a/Content.Server/Humanoid/Components/HumanoidComponent.cs +++ b/Content.Server/Humanoid/Components/HumanoidComponent.cs @@ -34,5 +34,5 @@ public sealed class HumanoidComponent : SharedHumanoidComponent // Couldn't these be somewhere else? [ViewVariables] public Gender Gender = default!; - [ViewVariables] public int Age = HumanoidCharacterProfile.MinimumAge; + [ViewVariables] public int Age = 18; } diff --git a/Content.Server/Humanoid/Systems/HumanoidSystem.cs b/Content.Server/Humanoid/Systems/HumanoidSystem.cs index 40eb8529c4..0cd90643f1 100644 --- a/Content.Server/Humanoid/Systems/HumanoidSystem.cs +++ b/Content.Server/Humanoid/Systems/HumanoidSystem.cs @@ -71,7 +71,7 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem { var identity = Identity.Entity(component.Owner, EntityManager); var species = GetSpeciesRepresentation(component.Species).ToLower(); - var age = GetAgeRepresentation(component.Age); + var age = GetAgeRepresentation(component.Species, component.Age); args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species))); } @@ -498,14 +498,23 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem } } - public string GetAgeRepresentation(int age) + public string GetAgeRepresentation(string species, int age) { - return age switch + _prototypeManager.TryIndex(species, out var speciesPrototype); + + if (speciesPrototype == null) { - <= 30 => Loc.GetString("identity-age-young"), - > 30 and <= 60 => Loc.GetString("identity-age-middle-aged"), - > 60 => Loc.GetString("identity-age-old") - }; + Logger.Error("Tried to get age representation of species that couldn't be indexed: " + species); + return Loc.GetString("identity-age-young"); + } + + if (age < speciesPrototype.YoungAge) + return Loc.GetString("identity-age-young"); + + if (age < speciesPrototype.OldAge) + Loc.GetString("identity-age-middle-aged"); + + return Loc.GetString("identity-age-old"); } private void EnsureDefaultMarkings(EntityUid uid, HumanoidComponent? humanoid) diff --git a/Content.Server/IdentityManagement/IdentitySystem.cs b/Content.Server/IdentityManagement/IdentitySystem.cs index 42e12944d5..54480db51b 100644 --- a/Content.Server/IdentityManagement/IdentitySystem.cs +++ b/Content.Server/IdentityManagement/IdentitySystem.cs @@ -121,7 +121,7 @@ public class IdentitySystem : SharedIdentitySystem InventoryComponent? inventory=null, HumanoidComponent? appearance=null) { - int age = HumanoidCharacterProfile.MinimumAge; + int age = 18; Gender gender = Gender.Epicene; // Always use their actual age and gender, since that can't really be changed by an ID. diff --git a/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs b/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs index 7b36f9c30e..fe6fe5b3fd 100644 --- a/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs +++ b/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs @@ -95,6 +95,31 @@ public sealed class SpeciesPrototype : IPrototype [DataField("sexes")] public List Sexes { get; } = new List(){ Sex.Male, Sex.Female }; + + /// + /// Characters younger than this are too young to be hired by Nanotrasen. + /// + [DataField("minAge")] + public int MinAge = 18; + + /// + /// Characters younger than this appear young. + /// + [DataField("youngAge")] + public int YoungAge = 30; + + /// + /// Characters older than this appear old. Characters in between young and old age appear middle aged. + /// + [DataField("oldAge")] + public int OldAge = 60; + + /// + /// Characters cannot be older than this. Only used for restrictions... + /// although imagine if ghosts could age people WYCI... + /// + [DataField("maxAge")] + public int MaxAge = 120; } public enum SpeciesNaming : byte diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index 157b464385..a7867e06c0 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -24,8 +24,6 @@ namespace Content.Shared.Preferences [Serializable, NetSerializable] public sealed class HumanoidCharacterProfile : ICharacterProfile { - public const int MinimumAge = 18; - public const int MaximumAge = 120; public const int MaxNameLength = 32; public const int MaxDescLength = 512; @@ -110,7 +108,7 @@ namespace Content.Shared.Preferences "John Doe", "", SharedHumanoidSystem.DefaultSpecies, - MinimumAge, + 18, Sex.Male, Gender.Male, HumanoidCharacterAppearance.Default(), @@ -136,7 +134,7 @@ namespace Content.Shared.Preferences "John Doe", "", species, - MinimumAge, + 18, Sex.Male, Gender.Male, HumanoidCharacterAppearance.DefaultWithSpecies(species), @@ -172,15 +170,16 @@ namespace Content.Shared.Preferences var random = IoCManager.Resolve(); var sex = Sex.Unsexed; + var age = 18; if (prototypeManager.TryIndex(species, out var speciesPrototype)) { sex = random.Pick(speciesPrototype.Sexes); + age = random.Next(speciesPrototype.MinAge, speciesPrototype.OldAge); // people don't look and keep making 119 year old characters with zero rp, cap it at middle aged } var gender = sex == Sex.Male ? Gender.Male : Gender.Female; var name = GetName(species, gender); - var age = random.Next(MinimumAge, MaximumAge); return new HumanoidCharacterProfile(name, "", species, age, sex, gender, HumanoidCharacterAppearance.Random(species, sex), ClothingPreference.Jumpsuit, BackpackPreference.Backpack, new Dictionary @@ -354,8 +353,6 @@ namespace Content.Shared.Preferences public void EnsureValid() { - var age = Math.Clamp(Age, MinimumAge, MaximumAge); - var prototypeManager = IoCManager.Resolve(); prototypeManager.TryIndex(Species, out var speciesPrototype); @@ -368,13 +365,15 @@ namespace Content.Shared.Preferences _ => Sex.Male // Invalid enum values. }; - // ensure the species can be that sex + // ensure the species can be that sex and their age fits the founds + var age = Age; if (speciesPrototype != null) { if (!speciesPrototype.Sexes.Contains(sex)) { sex = speciesPrototype.Sexes[0]; } + age = Math.Clamp(Age, speciesPrototype.MinAge, speciesPrototype.MaxAge); } var gender = Gender switch