| 12345678910111213141516171819202122232425262728293031323334353637 |
- 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);
- }
- }
|