Files
tbd-station-14/Content.Server/Humanoid/Systems/RandomHumanoidAppearanceSystem.cs

38 lines
1.3 KiB
C#

using Content.Server.CharacterAppearance.Components;
using Content.Shared.Humanoid;
using Content.Shared.Preferences;
namespace Content.Server.Humanoid.Systems;
public sealed class RandomHumanoidAppearanceSystem : EntitySystem
{
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RandomHumanoidAppearanceComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(EntityUid uid, RandomHumanoidAppearanceComponent component, MapInitEvent args)
{
// If we have an initial profile/base layer set, do not randomize this humanoid.
if (!TryComp(uid, out HumanoidAppearanceComponent? humanoid) || !string.IsNullOrEmpty(humanoid.Initial))
{
return;
}
var profile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
//If we have a specified hair style, change it to this
if(component.Hair != null)
profile = profile.WithCharacterAppearance(profile.Appearance.WithHairStyleName(component.Hair));
_humanoid.LoadProfile(uid, profile, humanoid);
if (component.RandomizeName)
_metaData.SetEntityName(uid, profile.Name);
}
}