Port honkbots from nyano (#9698)
This commit is contained in:
18
Content.Server/Sound/Components/SpamEmitSoundComponent.cs
Normal file
18
Content.Server/Sound/Components/SpamEmitSoundComponent.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Content.Server.Sound.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Rolls to play a sound every few seconds.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SpamEmitSoundComponent : BaseEmitSoundComponent
|
||||
{
|
||||
[DataField("accumulator")]
|
||||
public float Accumulator = 0f;
|
||||
|
||||
[DataField("rollInterval")]
|
||||
public float RollInterval = 2f;
|
||||
|
||||
[DataField("playChance")]
|
||||
public float PlayChance = 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,25 @@ namespace Content.Server.Sound
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
foreach (var soundSpammer in EntityQuery<SpamEmitSoundComponent>())
|
||||
{
|
||||
soundSpammer.Accumulator += frameTime;
|
||||
if (soundSpammer.Accumulator < soundSpammer.RollInterval)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
soundSpammer.Accumulator -= soundSpammer.RollInterval;
|
||||
|
||||
if (_random.Prob(soundSpammer.PlayChance))
|
||||
{
|
||||
TryEmitSound(soundSpammer);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Reference in New Issue
Block a user