EmoteSystem.cs 729 B

123456789101112131415161718192021222324252627282930
  1. namespace Content.Shared.Emoting;
  2. public sealed class EmoteSystem : EntitySystem
  3. {
  4. public override void Initialize()
  5. {
  6. base.Initialize();
  7. SubscribeLocalEvent<EmoteAttemptEvent>(OnEmoteAttempt);
  8. }
  9. public void SetEmoting(EntityUid uid, bool value, EmotingComponent? component = null)
  10. {
  11. if (value && !Resolve(uid, ref component))
  12. return;
  13. component = EnsureComp<EmotingComponent>(uid);
  14. if (component.Enabled == value)
  15. return;
  16. Dirty(uid, component);
  17. }
  18. private void OnEmoteAttempt(EmoteAttemptEvent args)
  19. {
  20. if (!TryComp(args.Uid, out EmotingComponent? emote) || !emote.Enabled)
  21. args.Cancel();
  22. }
  23. }