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

37 lines
1.1 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 HumanoidSystem _humanoid = 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 HumanoidComponent? humanoid) || !string.IsNullOrEmpty(humanoid.Initial))
{
return;
}
var profile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
_humanoid.LoadProfile(uid, profile, humanoid);
if (component.RandomizeName)
{
var meta = MetaData(uid);
meta.EntityName = profile.Name;
}
}
}