Files
tbd-station-14/Content.Shared/Speech/SpeechSystem.cs

32 lines
809 B
C#

namespace Content.Shared.Speech
{
public sealed class SpeechSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpeakAttemptEvent>(OnSpeakAttempt);
}
public void SetSpeech(EntityUid uid, bool value, SpeechComponent? component = null)
{
if (value && !Resolve(uid, ref component))
return;
component = EnsureComp<SpeechComponent>(uid);
if (component.Enabled == value)
return;
Dirty(component);
}
private void OnSpeakAttempt(SpeakAttemptEvent args)
{
if (!TryComp(args.Uid, out SpeechComponent? speech) || !speech.Enabled)
args.Cancel();
}
}
}