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>
This commit is contained in:
53
Content.Server/Traits/Assorted/NarcolepsySystem.cs
Normal file
53
Content.Server/Traits/Assorted/NarcolepsySystem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Traits.Assorted;
|
||||
|
||||
/// <summary>
|
||||
/// This handles narcolepsy, causing the affected to fall asleep uncontrollably at a random interval.
|
||||
/// </summary>
|
||||
public sealed class NarcolepsySystem : EntitySystem
|
||||
{
|
||||
private const string StatusEffectKey = "ForcedSleep"; // Same one used by N2O and other sleep chems.
|
||||
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<NarcolepsyComponent, ComponentStartup>(SetupNarcolepsy);
|
||||
}
|
||||
|
||||
private void SetupNarcolepsy(EntityUid uid, NarcolepsyComponent component, ComponentStartup args)
|
||||
{
|
||||
component.NextIncidentTime =
|
||||
_random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var narcolepsy in EntityQuery<NarcolepsyComponent>())
|
||||
{
|
||||
narcolepsy.NextIncidentTime -= frameTime;
|
||||
|
||||
if (narcolepsy.NextIncidentTime >= 0)
|
||||
continue;
|
||||
|
||||
// Set the new time.
|
||||
narcolepsy.NextIncidentTime +=
|
||||
_random.NextFloat(narcolepsy.TimeBetweenIncidents.X, narcolepsy.TimeBetweenIncidents.Y);
|
||||
|
||||
var duration = _random.NextFloat(narcolepsy.DurationOfIncident.X, narcolepsy.DurationOfIncident.Y);
|
||||
|
||||
// Make sure the sleep time doesn't cut into the time to next incident.
|
||||
narcolepsy.NextIncidentTime += duration;
|
||||
|
||||
_statusEffects.TryAddStatusEffect<ForcedSleepingComponent>(narcolepsy.Owner, StatusEffectKey,
|
||||
TimeSpan.FromSeconds(duration), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user