BodyEmotesSystem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Chat.Systems;
  2. using Content.Server.Emoting.Components;
  3. using Content.Shared.Chat.Prototypes;
  4. using Content.Shared.Hands.Components;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.Emoting.Systems;
  7. public sealed class BodyEmotesSystem : EntitySystem
  8. {
  9. [Dependency] private readonly IPrototypeManager _proto = default!;
  10. [Dependency] private readonly ChatSystem _chat = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<BodyEmotesComponent, ComponentStartup>(OnStartup);
  15. SubscribeLocalEvent<BodyEmotesComponent, EmoteEvent>(OnEmote);
  16. }
  17. private void OnStartup(EntityUid uid, BodyEmotesComponent component, ComponentStartup args)
  18. {
  19. if (component.SoundsId == null)
  20. return;
  21. _proto.TryIndex(component.SoundsId, out component.Sounds);
  22. }
  23. private void OnEmote(EntityUid uid, BodyEmotesComponent component, ref EmoteEvent args)
  24. {
  25. if (args.Handled)
  26. return;
  27. var cat = args.Emote.Category;
  28. if (cat.HasFlag(EmoteCategory.Hands))
  29. {
  30. args.Handled = TryEmoteHands(uid, args.Emote, component);
  31. }
  32. }
  33. private bool TryEmoteHands(EntityUid uid, EmotePrototype emote, BodyEmotesComponent component)
  34. {
  35. // check that user actually has hands to do emote sound
  36. if (!TryComp(uid, out HandsComponent? hands) || hands.Count <= 0)
  37. return false;
  38. return _chat.TryPlayEmoteSound(uid, component.Sounds, emote);
  39. }
  40. }