mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using Content.Shared.Examine;
|
|
using Content.Shared.Humanoid.Prototypes;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Preferences;
|
|
using Robust.Shared.GameObjects.Components.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared.Humanoid;
|
|
|
|
public sealed class HumanoidProfileSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly GrammarSystem _grammar = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HumanoidProfileComponent, ExaminedEvent>(OnExamined);
|
|
}
|
|
|
|
public void ApplyProfileTo(Entity<HumanoidProfileComponent?> ent, HumanoidCharacterProfile profile)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return;
|
|
|
|
ent.Comp.Gender = profile.Gender;
|
|
ent.Comp.Age = profile.Age;
|
|
ent.Comp.Species = profile.Species;
|
|
ent.Comp.Sex = profile.Sex;
|
|
Dirty(ent);
|
|
|
|
var sexChanged = new SexChangedEvent(ent.Comp.Sex, profile.Sex);
|
|
RaiseLocalEvent(ent, ref sexChanged);
|
|
|
|
if (TryComp<GrammarComponent>(ent, out var grammar))
|
|
{
|
|
_grammar.SetGender((ent, grammar), profile.Gender);
|
|
}
|
|
}
|
|
|
|
private void OnExamined(Entity<HumanoidProfileComponent> ent, ref ExaminedEvent args)
|
|
{
|
|
var identity = Identity.Entity(ent, EntityManager);
|
|
var species = GetSpeciesRepresentation(ent.Comp.Species).ToLower();
|
|
var age = GetAgeRepresentation(ent.Comp.Species, ent.Comp.Age);
|
|
|
|
args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes ID of the species prototype, returns UI-friendly name of the species.
|
|
/// </summary>
|
|
public string GetSpeciesRepresentation(ProtoId<SpeciesPrototype> species)
|
|
{
|
|
if (_prototype.TryIndex(species, out var speciesPrototype))
|
|
return Loc.GetString(speciesPrototype.Name);
|
|
|
|
Log.Error("Tried to get representation of unknown species: {speciesId}");
|
|
return Loc.GetString("humanoid-appearance-component-unknown-species");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes ID of the species prototype and an age, returns an approximate description
|
|
/// </summary>
|
|
public string GetAgeRepresentation(ProtoId<SpeciesPrototype> species, int age)
|
|
{
|
|
if (!_prototype.TryIndex(species, out var speciesPrototype))
|
|
{
|
|
Log.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)
|
|
{
|
|
return Loc.GetString("identity-age-middle-aged");
|
|
}
|
|
|
|
return Loc.GetString("identity-age-old");
|
|
}
|
|
}
|