Files
tbd-station-14/Content.Server/Sound/EmitSoundSystem.cs
Ed 498ad2d5d7 Lock Anomaly generator to research access (#24464)
* small patch

* fix

* remove garbage

* fix

* moved to shared events

* fix

* LocId

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-02-01 19:45:24 +11:00

56 lines
1.8 KiB
C#

using Content.Server.Explosion.EntitySystems;
using Content.Server.Sound.Components;
using Content.Shared.UserInterface;
using Content.Shared.Sound;
using Robust.Shared.Random;
namespace Content.Server.Sound;
public sealed class EmitSoundSystem : SharedEmitSoundSystem
{
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<SpamEmitSoundComponent>();
while (query.MoveNext(out var uid, out var soundSpammer))
{
if (!soundSpammer.Enabled)
continue;
soundSpammer.Accumulator += frameTime;
if (soundSpammer.Accumulator < soundSpammer.RollInterval)
{
continue;
}
soundSpammer.Accumulator -= soundSpammer.RollInterval;
if (Random.Prob(soundSpammer.PlayChance))
{
if (soundSpammer.PopUp != null)
Popup.PopupEntity(Loc.GetString(soundSpammer.PopUp), uid);
TryEmitSound(uid, soundSpammer, predict: false);
}
}
}
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmitSoundOnTriggerComponent, TriggerEvent>(HandleEmitSoundOnTrigger);
SubscribeLocalEvent<EmitSoundOnUIOpenComponent, AfterActivatableUIOpenEvent>(HandleEmitSoundOnUIOpen);
}
private void HandleEmitSoundOnUIOpen(EntityUid uid, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
{
TryEmitSound(uid, component, args.User, false);
}
private void HandleEmitSoundOnTrigger(EntityUid uid, EmitSoundOnTriggerComponent component, TriggerEvent args)
{
TryEmitSound(uid, component, args.User, false);
args.Handled = true;
}
}