Files
OldThink/Content.Server/Sound/EmitSoundSystem.cs

54 lines
1.7 KiB
C#
Raw Normal View History

2023-01-04 12:56:35 -06:00
using Content.Server.Explosion.EntitySystems;
2021-06-27 21:55:18 +02:00
using Content.Server.Sound.Components;
using Content.Server.UserInterface;
2023-01-04 12:56:35 -06:00
using Content.Shared.Sound;
using Robust.Shared.Random;
2023-01-04 12:56:35 -06:00
namespace Content.Server.Sound;
public sealed class EmitSoundSystem : SharedEmitSoundSystem
{
2023-01-04 12:56:35 -06:00
public override void Update(float frameTime)
{
2023-01-04 12:56:35 -06:00
base.Update(frameTime);
foreach (var soundSpammer in EntityQuery<SpamEmitSoundComponent>())
2022-07-15 03:54:34 -04:00
{
2023-01-04 12:56:35 -06:00
if (!soundSpammer.Enabled)
continue;
2022-07-15 03:54:34 -04:00
2023-01-04 12:56:35 -06:00
soundSpammer.Accumulator += frameTime;
if (soundSpammer.Accumulator < soundSpammer.RollInterval)
{
continue;
2022-07-15 03:54:34 -04:00
}
2023-01-04 12:56:35 -06:00
soundSpammer.Accumulator -= soundSpammer.RollInterval;
2022-08-31 12:24:21 +02:00
2023-01-04 12:56:35 -06:00
if (Random.Prob(soundSpammer.PlayChance))
{
if (soundSpammer.PopUp != null)
Popup.PopupEntity(Loc.GetString(soundSpammer.PopUp), soundSpammer.Owner);
TryEmitSound(soundSpammer);
}
2021-07-12 13:38:05 +02:00
}
2023-01-04 12:56:35 -06:00
}
2021-07-12 13:38:05 +02:00
2023-01-04 12:56:35 -06:00
public override void Initialize()
{
base.Initialize();
2023-01-04 12:56:35 -06:00
SubscribeLocalEvent<EmitSoundOnTriggerComponent, TriggerEvent>(HandleEmitSoundOnTrigger);
SubscribeLocalEvent<EmitSoundOnUIOpenComponent, AfterActivatableUIOpenEvent>(HandleEmitSoundOnUIOpen);
}
2023-01-04 12:56:35 -06:00
private void HandleEmitSoundOnUIOpen(EntityUid eUI, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
{
TryEmitSound(component, args.User);
}
2023-01-04 12:56:35 -06:00
private void HandleEmitSoundOnTrigger(EntityUid uid, EmitSoundOnTriggerComponent component, TriggerEvent args)
{
TryEmitSound(component);
2023-01-04 12:56:35 -06:00
args.Handled = true;
}
}