using System.Numerics; // DeltaV using Content.Shared.Examine; using Content.Shared.Humanoid.Prototypes; using Content.Shared.IdentityManagement; using Content.Shared.Preferences; using Content.Shared.Sprite; // DeltaV 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!; [Dependency] private readonly SharedScaleVisualsSystem _scale = default!; // DeltaV public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnExamined); } public void ApplyProfileTo(Entity 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; ent.Comp.Height = profile.Height; // DeltaV Dirty(ent); var sexChanged = new SexChangedEvent(ent.Comp.Sex, profile.Sex); RaiseLocalEvent(ent, ref sexChanged); if (TryComp(ent, out var grammar)) { _grammar.SetGender((ent, grammar), profile.Gender); } // START DeltaV - Apply profile/species size Vector2 scale = new(profile.Height, profile.Height); // If visuals already exist, then re-apply if (TryComp(ent, out var scaledVisuals)) scale *= scaledVisuals.Scale; var speciesProto = _prototype.Index(profile.Species); scale *= speciesProto.BaseScale; _scale.SetSpriteScale(ent, scale); // END DeltaV } private void OnExamined(Entity 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))); } /// /// Takes ID of the species prototype, returns UI-friendly name of the species. /// public string GetSpeciesRepresentation(ProtoId 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"); } /// /// Takes ID of the species prototype and an age, returns an approximate description /// public string GetAgeRepresentation(ProtoId 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"); } }