mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-06-09 10:06:49 +02:00
61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using Content.Shared.CCVar;
|
|
using Content.Shared.Speech.Synthesis;
|
|
using Content.Shared.Speech.Synthesis.Components;
|
|
using Robust.Server.Audio;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Prototypes;
|
|
using Content.Shared.Chat;
|
|
|
|
namespace Content.Server.Speech.Synthesis.System;
|
|
|
|
/// <summary>
|
|
/// Обрабатывает барки для сущностей.
|
|
/// </summary>
|
|
public sealed partial class BarkSystem : EntitySystem
|
|
{
|
|
[Dependency] private AudioSystem _audio = default!;
|
|
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private IEntityManager _entityManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<SpeechSynthesisComponent, EntitySpokeEvent>(OnEntitySpoke);
|
|
|
|
SubscribeNetworkEvent<RequestPreviewBarkEvent>(OnRequestPreviewBark);
|
|
}
|
|
|
|
private void OnEntitySpoke(EntityUid uid, SpeechSynthesisComponent comp, EntitySpokeEvent args)
|
|
{
|
|
if (comp.VoicePrototypeId is null ||
|
|
!_prototypeManager.TryIndex<BarkPrototype>(comp.VoicePrototypeId, out var barkProto) ||
|
|
!_configurationManager.GetCVar(WegaCVars.BarksEnabled))
|
|
return;
|
|
|
|
bool isObfuscated = args.ObfuscatedMessage != null;
|
|
var sourceEntity = _entityManager.GetNetEntity(uid);
|
|
var soundPath = barkProto.SoundFiles[new Random().Next(barkProto.SoundFiles.Count)];
|
|
RaiseNetworkEvent(new PlayBarkEvent(soundPath, sourceEntity, args.Message, comp.PlaybackSpeed, isObfuscated));
|
|
}
|
|
|
|
private async void OnRequestPreviewBark(RequestPreviewBarkEvent ev, EntitySessionEventArgs args)
|
|
{
|
|
if (string.IsNullOrEmpty(ev.BarkVoiceId) || !_prototypeManager.TryIndex<BarkPrototype>(ev.BarkVoiceId, out var barkProto)
|
|
|| !_configurationManager.GetCVar(WegaCVars.BarksEnabled))
|
|
return;
|
|
|
|
var soundPath = barkProto.SoundFiles[new Random().Next(barkProto.SoundFiles.Count)];
|
|
var soundSpecifier = new SoundPathSpecifier(soundPath);
|
|
|
|
var audioParams = new AudioParams
|
|
{
|
|
Pitch = 1.0f,
|
|
Volume = 4f,
|
|
Variation = 0.125f
|
|
};
|
|
|
|
_audio.PlayGlobal(soundSpecifier, args.SenderSession, audioParams);
|
|
}
|
|
}
|