Files
tbd-station-14/Content.Server/Traits/Assorted/UncontrollableSnoughSystem.cs
Moony 0c46f99004 Blindness, Narcolepsy, Pacifism, and uncontrollable sneezing (#11489)
* start work

* blindness actually works now

* doc

* doc you too.

* i desire to sneeze my lungs out

* no punchie

* s

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2022-09-29 18:23:12 -05:00

53 lines
1.7 KiB
C#

using Content.Server.Disease;
using Content.Shared.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Traits.Assorted;
/// <summary>
/// This handles making people randomly cough/sneeze without a disease.
/// </summary>
public sealed class UncontrollableSnoughSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly DiseaseSystem _diseaseSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<UncontrollableSnoughComponent, ComponentStartup>(SetupSnough);
}
private void SetupSnough(EntityUid uid, UncontrollableSnoughComponent component, ComponentStartup args)
{
component.NextIncidentTime =
_random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var snough in EntityQuery<UncontrollableSnoughComponent>())
{
snough.NextIncidentTime -= frameTime;
if (snough.NextIncidentTime >= 0)
continue;
// Set the new time.
snough.NextIncidentTime +=
_random.NextFloat(snough.TimeBetweenIncidents.X, snough.TimeBetweenIncidents.Y);
if (snough.SnoughSound != null)
_audioSystem.PlayPvs(snough.SnoughSound, snough.Owner);
_diseaseSystem.SneezeCough(snough.Owner, null, snough.SnoughMessage, false);
}
}
}