Refactor magic speak system to be a component added to actions (#36328)
This commit is contained in:
39
Content.Server/Speech/EntitySystems/SpeakOnActionSystem.cs
Normal file
39
Content.Server/Speech/EntitySystems/SpeakOnActionSystem.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Shared.Speech.Components;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
using Content.Shared.Speech.Muting;
|
||||
using Content.Shared.Actions.Events;
|
||||
|
||||
|
||||
namespace Content.Server.Speech.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// As soon as the chat refactor moves to Shared
|
||||
/// the logic here can move to the shared <see cref="SharedSpeakOnActionSystem"/>
|
||||
/// </summary>
|
||||
public sealed class SpeakOnActionSystem : SharedSpeakOnActionSystem
|
||||
{
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SpeakOnActionComponent, ActionPerformedEvent>(OnActionPerformed);
|
||||
}
|
||||
|
||||
private void OnActionPerformed(Entity<SpeakOnActionComponent> ent, ref ActionPerformedEvent args)
|
||||
{
|
||||
var user = args.Performer;
|
||||
|
||||
// If we can't speak, we can't speak
|
||||
if (!HasComp<SpeechComponent>(user) || HasComp<MutedComponent>(user))
|
||||
return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ent.Comp.Sentence))
|
||||
return;
|
||||
|
||||
_chat.TrySendInGameICMessage(user, Loc.GetString(ent.Comp.Sentence), InGameICChatType.Speak, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user