-using Content.Shared.Examine;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
-using Content.Shared.IdentityManagement;
using Content.Shared.Preferences;
using Content.Shared.Verbs;
using Robust.Shared.GameObjects.Components.Localization;
-using Robust.Shared.Prototypes;
namespace Content.Server.Humanoid;
public sealed partial class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem
{
[Dependency] private readonly MarkingManager _markingManager = default!;
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override void Initialize()
{
base.Initialize();
+
SubscribeLocalEvent<HumanoidAppearanceComponent, HumanoidMarkingModifierMarkingSetMessage>(OnMarkingsSet);
SubscribeLocalEvent<HumanoidAppearanceComponent, HumanoidMarkingModifierBaseLayersSetMessage>(OnBaseLayersSet);
SubscribeLocalEvent<HumanoidAppearanceComponent, GetVerbsEvent<Verb>>(OnVerbsRequest);
- SubscribeLocalEvent<HumanoidAppearanceComponent, ExaminedEvent>(OnExamined);
- }
-
- private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args)
- {
- var identity = Identity.Entity(uid, EntityManager);
- var species = GetSpeciesRepresentation(component.Species).ToLower();
- var age = GetAgeRepresentation(component.Species, component.Age);
-
- args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
}
// this was done enough times that it only made sense to do it here
Dirty(uid, humanoid);
}
-
- /// <summary>
- /// Takes ID of the species prototype, returns UI-friendly name of the species.
- /// </summary>
- public string GetSpeciesRepresentation(string speciesId)
- {
- if (_prototypeManager.TryIndex<SpeciesPrototype>(speciesId, out var species))
- {
- return Loc.GetString(species.Name);
- }
- else
- {
- return Loc.GetString("humanoid-appearance-component-unknown-species");
- }
- }
-
- public string GetAgeRepresentation(string species, int age)
- {
- _prototypeManager.TryIndex<SpeciesPrototype>(species, out var speciesPrototype);
-
- if (speciesPrototype == null)
- {
- 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");
- }
}
using System.Linq;
using Content.Shared.Decals;
+using Content.Shared.Examine;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
+using Content.Shared.IdentityManagement;
using Content.Shared.Preferences;
using Robust.Shared.GameObjects.Components.Localization;
using Robust.Shared.Network;
public abstract class SharedHumanoidAppearanceSystem : EntitySystem
{
[Dependency] private readonly INetManager _netManager = default!;
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+ [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MarkingManager _markingManager = default!;
[ValidatePrototypeId<SpeciesPrototype>]
public override void Initialize()
{
base.Initialize();
+
SubscribeLocalEvent<HumanoidAppearanceComponent, ComponentInit>(OnInit);
+ SubscribeLocalEvent<HumanoidAppearanceComponent, ExaminedEvent>(OnExamined);
}
private void OnInit(EntityUid uid, HumanoidAppearanceComponent humanoid, ComponentInit args)
}
if (string.IsNullOrEmpty(humanoid.Initial)
- || !_prototypeManager.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
+ || !_proto.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
{
LoadProfile(uid, HumanoidCharacterProfile.DefaultWithSpecies(humanoid.Species), humanoid);
return;
LoadProfile(uid, startingSet.Profile, humanoid);
}
+ private void OnExamined(EntityUid uid, HumanoidAppearanceComponent component, ExaminedEvent args)
+ {
+ var identity = Identity.Entity(uid, EntityManager);
+ var species = GetSpeciesRepresentation(component.Species).ToLower();
+ var age = GetAgeRepresentation(component.Species, component.Age);
+
+ args.PushText(Loc.GetString("humanoid-appearance-component-examine", ("user", identity), ("age", age), ("species", species)));
+ }
+
/// <summary>
/// Toggles a humanoid's sprite layer visibility.
/// </summary>
/// <param name="humanoid">Humanoid component of the entity</param>
public void SetSpecies(EntityUid uid, string species, bool sync = true, HumanoidAppearanceComponent? humanoid = null)
{
- if (!Resolve(uid, ref humanoid) || !_prototypeManager.TryIndex<SpeciesPrototype>(species, out var prototype))
+ if (!Resolve(uid, ref humanoid) || !_proto.TryIndex<SpeciesPrototype>(species, out var prototype))
{
return;
}
humanoid.Species = species;
humanoid.MarkingSet.EnsureSpecies(species, humanoid.SkinColor, _markingManager);
var oldMarkings = humanoid.MarkingSet.GetForwardEnumerator().ToList();
- humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _prototypeManager);
+ humanoid.MarkingSet = new(oldMarkings, prototype.MarkingPoints, _markingManager, _proto);
if (sync)
Dirty(uid, humanoid);
if (!Resolve(uid, ref humanoid))
return;
- if (!_prototypeManager.TryIndex<SpeciesPrototype>(humanoid.Species, out var species))
+ if (!_proto.TryIndex<SpeciesPrototype>(humanoid.Species, out var species))
{
return;
}
// Hair/facial hair - this may eventually be deprecated.
// We need to ensure hair before applying it or coloring can try depend on markings that can be invalid
- var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _prototypeManager)
+ var hairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.Hair, out var hairAlpha, _proto)
? profile.Appearance.SkinColor.WithAlpha(hairAlpha) : profile.Appearance.HairColor;
- var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _prototypeManager)
+ var facialHairColor = _markingManager.MustMatchSkin(profile.Species, HumanoidVisualLayers.FacialHair, out var facialHairAlpha, _proto)
? profile.Appearance.SkinColor.WithAlpha(facialHairAlpha) : profile.Appearance.FacialHairColor;
if (_markingManager.Markings.TryGetValue(profile.Appearance.HairStyleId, out var hairPrototype) &&
- _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _prototypeManager))
+ _markingManager.CanBeApplied(profile.Species, profile.Sex, hairPrototype, _proto))
{
AddMarking(uid, profile.Appearance.HairStyleId, hairColor, false);
}
if (_markingManager.Markings.TryGetValue(profile.Appearance.FacialHairStyleId, out var facialHairPrototype) &&
- _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _prototypeManager))
+ _markingManager.CanBeApplied(profile.Species, profile.Sex, facialHairPrototype, _proto))
{
AddMarking(uid, profile.Appearance.FacialHairStyleId, facialHairColor, false);
}
- humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _prototypeManager);
+ humanoid.MarkingSet.EnsureSpecies(profile.Species, profile.Appearance.SkinColor, _markingManager, _proto);
// Finally adding marking with forced colors
foreach (var (marking, prototype) in markingFColored)
if (sync)
Dirty(uid, humanoid);
}
+
+ /// <summary>
+ /// Takes ID of the species prototype, returns UI-friendly name of the species.
+ /// </summary>
+ public string GetSpeciesRepresentation(string speciesId)
+ {
+ if (_proto.TryIndex<SpeciesPrototype>(speciesId, out var species))
+ {
+ return Loc.GetString(species.Name);
+ }
+
+ Log.Error("Tried to get representation of unknown species: {speciesId}");
+ return Loc.GetString("humanoid-appearance-component-unknown-species");
+ }
+
+ public string GetAgeRepresentation(string species, int age)
+ {
+ if (!_proto.TryIndex<SpeciesPrototype>(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");
+ }
}