RandomHumanoidAppearanceSystem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Server.CharacterAppearance.Components;
  2. using Content.Shared.Humanoid;
  3. using Content.Shared.Preferences;
  4. namespace Content.Server.Humanoid.Systems;
  5. public sealed class RandomHumanoidAppearanceSystem : EntitySystem
  6. {
  7. [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
  8. [Dependency] private readonly MetaDataSystem _metaData = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<RandomHumanoidAppearanceComponent, MapInitEvent>(OnMapInit);
  13. }
  14. private void OnMapInit(EntityUid uid, RandomHumanoidAppearanceComponent component, MapInitEvent args)
  15. {
  16. // If we have an initial profile/base layer set, do not randomize this humanoid.
  17. if (!TryComp(uid, out HumanoidAppearanceComponent? humanoid) || !string.IsNullOrEmpty(humanoid.Initial))
  18. {
  19. return;
  20. }
  21. var profile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
  22. //If we have a specified hair style, change it to this
  23. if(component.Hair != null)
  24. profile = profile.WithCharacterAppearance(profile.Appearance.WithHairStyleName(component.Hair));
  25. _humanoid.LoadProfile(uid, profile, humanoid);
  26. if (component.RandomizeName)
  27. _metaData.SetEntityName(uid, profile.Name);
  28. }
  29. }