36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
|
|
using Content.Server.CharacterAppearance.Components;
|
|||
|
|
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.Random(component.IgnoredSpecies);
|
|||
|
|
|
|||
|
|
_humanoid.LoadProfile(uid, profile);
|
|||
|
|
|
|||
|
|
if (component.RandomizeName)
|
|||
|
|
{
|
|||
|
|
var meta = MetaData(uid);
|
|||
|
|
meta.EntityName = profile.Name;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|