Unhardcode species age ranges (#11979)

This commit is contained in:
Rane
2022-10-22 18:13:46 -04:00
committed by GitHub
parent 471f5dbf10
commit 916c4f9522
5 changed files with 50 additions and 17 deletions

View File

@@ -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<SpeciesPrototype>(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)