diff --git a/Content.Server/Speech/SpeechNoiseSystem.cs b/Content.Server/Speech/SpeechNoiseSystem.cs index d85c4e6d35..d5fec29672 100644 --- a/Content.Server/Speech/SpeechNoiseSystem.cs +++ b/Content.Server/Speech/SpeechNoiseSystem.cs @@ -12,69 +12,46 @@ namespace Content.Server.Speech { public sealed class SpeechSoundSystem : EntitySystem { - - [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IPrototypeManager _protoManager = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnEntitySpoke); - SubscribeLocalEvent(OnStartup); } - private void OnStartup(EntityUid uid, SharedSpeechComponent component, ComponentStartup args) - { - //Cache prototype on component startup. - if (_proto.TryIndex(component.SpeechSoundsId, out SpeechSoundsPrototype? speechsnds)) - { - if (speechsnds != null) - { - component.SpeechSoundsCache = speechsnds; - } - } - } - - private void OnEntitySpoke(EntityUid uid, SharedSpeechComponent component, EntitySpokeEvent args) { - if (!component.PlaySpeechSound) return; + if (component.SpeechSounds == null) return; + + var currentTime = _gameTiming.CurTime; var cooldown = TimeSpan.FromSeconds(component.SoundCooldownTime); - //Ensure more than the cooldown time has passed since last speaking - if ((_gameTiming.CurTime - component.LastTimeSoundPlayed) < cooldown) return; - //Play speech sound + // Ensure more than the cooldown time has passed since last speaking + if (currentTime - component.LastTimeSoundPlayed < cooldown) return; - if (component.SpeechSoundsCache != null) + // Play speech sound + string contextSound; + var prototype = _protoManager.Index(component.SpeechSounds); + + // Different sounds for ask/exclaim based on last character + switch (args.Message[^1]) { - //Re-Index sounds prototype if cached proto ID is outdated, allows VV and changing the voice. - if (component.SpeechSoundsCache.ID != component.SpeechSoundsId) - { - if (_proto.TryIndex(component.SpeechSoundsId, out SpeechSoundsPrototype? speechsnds)) - { - if (speechsnds != null) - { - component.SpeechSoundsCache = speechsnds; - } - } - } - var contextSound = component.SpeechSoundsCache.SaySound; - //Different sounds for ask/exclaim based on last character - switch (args.Message[args.Message.Length-1]) - { - case '?': - contextSound = component.SpeechSoundsCache.AskSound; - break; - case '!': - contextSound = component.SpeechSoundsCache.ExclaimSound; - break; - - } - component.LastTimeSoundPlayed = _gameTiming.CurTime; - SoundSystem.Play(Filter.Pvs(uid), contextSound.GetSound(), uid, component.AudioParams); + case '?': + contextSound = prototype.AskSound.GetSound(); + break; + case '!': + contextSound = prototype.ExclaimSound.GetSound(); + break; + default: + contextSound = prototype.SaySound.GetSound(); + break; } - } + component.LastTimeSoundPlayed = currentTime; + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), contextSound, uid, component.AudioParams); + } } } diff --git a/Content.Shared/Speech/SharedSpeechComponent.cs b/Content.Shared/Speech/SharedSpeechComponent.cs index 9c28936dc2..784ea7240c 100644 --- a/Content.Shared/Speech/SharedSpeechComponent.cs +++ b/Content.Shared/Speech/SharedSpeechComponent.cs @@ -21,12 +21,8 @@ namespace Content.Shared.Speech private bool _enabled = true; [ViewVariables(VVAccess.ReadWrite)] - [DataField("playSpeechSound")] - public bool PlaySpeechSound = false; - - [ViewVariables(VVAccess.ReadWrite)] - [DataField("speechSoundsId", customTypeSerializer:typeof(PrototypeIdSerializer))] - public string SpeechSoundsId { get; set; } = "Alto"; + [DataField("speechSounds", customTypeSerializer:typeof(PrototypeIdSerializer))] + public string? SpeechSounds; [DataField("audioParams")] public AudioParams AudioParams = AudioParams.Default.WithVolume(5f); @@ -37,12 +33,6 @@ namespace Content.Shared.Speech public TimeSpan LastTimeSoundPlayed = TimeSpan.Zero; - //Don't use this. - //Cache for SpeechSoundsPrototype to avoid Indexing every single time someone talks. - public SpeechSoundsPrototype? SpeechSoundsCache = null; - - - public bool Enabled { get => _enabled; diff --git a/Resources/Audio/Machines/license.txt b/Resources/Audio/Machines/license.txt index eb1ca88436..38dc720b70 100644 --- a/Resources/Audio/Machines/license.txt +++ b/Resources/Audio/Machines/license.txt @@ -1,7 +1,9 @@ -diagnoser_printing.ogg taken from https://freesound.org/people/RobSp1derp1g/sounds/615419/ and edited +circuitprinter.ogg taken from https://freesound.org/people/OroborosNZ/sounds/273649/ and https://freesound.org/people/170048@virtualwindow.co.za/sounds/408041/ and edited -vaccinator_running.ogg taken from https://freesound.org/people/RutgerMuller/sounds/365413/ and edited +diagnoser_printing.ogg taken from https://freesound.org/people/RobSp1derp1g/sounds/615419/ and edited uniformprinter.ogg taken from https://freesound.org/people/sukaton/sounds/60640/ and edited -circuitprinter.ogg taken from https://freesound.org/people/OroborosNZ/sounds/273649/ and https://freesound.org/people/170048@virtualwindow.co.za/sounds/408041/ and edited +vaccinator_running.ogg taken from https://freesound.org/people/RutgerMuller/sounds/365413/ and edited + +vending_jingle.ogg made by github.com/hubismal licensed under CC-BY-3.0 \ No newline at end of file diff --git a/Resources/Audio/Voice/Talk/license.txt b/Resources/Audio/Voice/Talk/license.txt index e9e7b8134c..01f4445cb3 100644 --- a/Resources/Audio/Voice/Talk/license.txt +++ b/Resources/Audio/Voice/Talk/license.txt @@ -11,5 +11,5 @@ speak_4_ask.ogg speak_4_exclaim.ogg speak_4.ogg all taken from -https://github.com/goonstation/goonstation/tree/master/sound/misc/talk +https://github.com/goonstation/goonstation/tree/eb3e7df6292d23f6af2f18b4372d3a8ba4b0fda7/sound/misc/talk licensed under CC BY-NC-SA 3.0 diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml index 31f6fd4179..189071e141 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml @@ -18,7 +18,7 @@ sprite: Mobs/Animals/bat.rsi - type: Physics - type: Speech - speechSoundsId: Squeak + speechSounds: Squeak - type: Fixtures fixtures: - shape: @@ -666,8 +666,7 @@ name: mouse description: A hungry and mischievous mouse. - type: Speech - playSpeechSound: true - speechSoundsId: Squeak + speechSounds: Squeak - type: Sprite drawdepth: FloorObjects layers: diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index fb6a072c5e..5f0c062f1f 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -180,7 +180,7 @@ Arms: points: 2 required: false - + - type: Physics bodyType: KinematicController - type: Fixtures @@ -309,7 +309,6 @@ # - type: Recyclable Turns out turning off recycler safeties without considering the instagib is a bad idea # safe: false - type: Speech - playSpeechSound: true - type: Vocal - type: Emoting - type: Grammar diff --git a/Resources/Prototypes/Entities/Structures/Machines/vending_machines.yml b/Resources/Prototypes/Entities/Structures/Machines/vending_machines.yml index 3bbe8f5d6a..2ce09b2b7a 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/vending_machines.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/vending_machines.yml @@ -53,8 +53,7 @@ LayoutId: Vending - type: Anchorable - type: Speech - playSpeechSound: true - speechSoundsId: Vending + speechSounds: Vending - type: DoAfter - type: Electrified enabled: false