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(); 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(HandleEmitSoundOnTrigger); SubscribeLocalEvent(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; } }