1
0

SpeechSystem.cs 854 B

123456789101112131415161718192021222324252627282930313233
  1. namespace Content.Shared.Speech
  2. {
  3. public sealed class SpeechSystem : EntitySystem
  4. {
  5. public override void Initialize()
  6. {
  7. base.Initialize();
  8. SubscribeLocalEvent<SpeakAttemptEvent>(OnSpeakAttempt);
  9. }
  10. public void SetSpeech(EntityUid uid, bool value, SpeechComponent? component = null)
  11. {
  12. if (value && !Resolve(uid, ref component))
  13. return;
  14. component = EnsureComp<SpeechComponent>(uid);
  15. if (component.Enabled == value)
  16. return;
  17. component.Enabled = value;
  18. Dirty(uid, component);
  19. }
  20. private void OnSpeakAttempt(SpeakAttemptEvent args)
  21. {
  22. if (!TryComp(args.Uid, out SpeechComponent? speech) || !speech.Enabled)
  23. args.Cancel();
  24. }
  25. }
  26. }