Audible emotes (#12708)
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
This commit is contained in:
24
Content.Server/Emoting/Components/BodyEmotesComponent.cs
Normal file
24
Content.Server/Emoting/Components/BodyEmotesComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Server.Emoting.Systems;
|
||||
using Content.Shared.Chat.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Emoting.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Component required for entities to be able to do body emotions (clap, flip, etc).
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(BodyEmotesSystem))]
|
||||
public sealed class BodyEmotesComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Emote sounds prototype id for body emotes.
|
||||
/// </summary>
|
||||
[DataField("soundsId", customTypeSerializer: typeof(PrototypeIdSerializer<EmoteSoundsPrototype>))]
|
||||
public string? SoundsId;
|
||||
|
||||
/// <summary>
|
||||
/// Loaded emote sounds prototype used for body emotes.
|
||||
/// </summary>
|
||||
public EmoteSoundsPrototype? Sounds;
|
||||
}
|
||||
48
Content.Server/Emoting/Systems/BodyEmotesSystem.cs
Normal file
48
Content.Server/Emoting/Systems/BodyEmotesSystem.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Emoting.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Shared.Chat.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Emoting.Systems;
|
||||
|
||||
public sealed class BodyEmotesSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<BodyEmotesComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<BodyEmotesComponent, EmoteEvent>(OnEmote);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, BodyEmotesComponent component, ComponentStartup args)
|
||||
{
|
||||
if (component.SoundsId == null)
|
||||
return;
|
||||
_proto.TryIndex(component.SoundsId, out component.Sounds);
|
||||
}
|
||||
|
||||
private void OnEmote(EntityUid uid, BodyEmotesComponent component, ref EmoteEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
var cat = args.Emote.Category;
|
||||
if (cat.HasFlag(EmoteCategory.Hands))
|
||||
{
|
||||
args.Handled = TryEmoteHands(uid, args.Emote, component);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryEmoteHands(EntityUid uid, EmotePrototype emote, BodyEmotesComponent component)
|
||||
{
|
||||
// check that user actually has hands to do emote sound
|
||||
if (!TryComp(uid, out HandsComponent? hands) || hands.Count <= 0)
|
||||
return false;
|
||||
|
||||
return _chat.TryPlayEmoteSound(uid, component.Sounds, emote);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user