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:
Moony
2022-09-29 18:23:12 -05:00
committed by GitHub
parent 36583b89af
commit 0c46f99004
12 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
namespace Content.Server.Traits.Assorted;
/// <summary>
/// This is used for the narcolepsy trait.
/// </summary>
[RegisterComponent, Access(typeof(NarcolepsySystem))]
public sealed class NarcolepsyComponent : Component
{
/// <summary>
/// The random time between incidents, (min, max).
/// </summary>
[DataField("timeBetweenIncidents", required: true)]
public Vector2 TimeBetweenIncidents { get; }
/// <summary>
/// The duration of incidents, (min, max).
/// </summary>
[DataField("durationOfIncident", required: true)]
public Vector2 DurationOfIncident { get; }
public float NextIncidentTime;
}

View 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);
}
}
}

View File

@@ -0,0 +1,10 @@
namespace Content.Server.Traits.Assorted;
/// <summary>
/// This is used for enforcing pacifism.
/// </summary>
[RegisterComponent]
public sealed class PacifistComponent : Component
{
}

View File

@@ -0,0 +1,17 @@
using Content.Shared.CombatMode.Pacification;
namespace Content.Server.Traits.Assorted;
/// <summary>
/// This handles enforced pacifism.
/// </summary>
public sealed class PacifistSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var comp in EntityQuery<PacifistComponent>())
{
EnsureComp<PacifiedComponent>(comp.Owner); // It's a status effect so just enforce it.
}
}
}

View File

@@ -0,0 +1,28 @@
using Robust.Shared.Audio;
namespace Content.Server.Traits.Assorted;
/// <summary>
/// This is used for the occasional sneeze or cough.
/// </summary>
[RegisterComponent]
public sealed class UncontrollableSnoughComponent : Component
{
/// <summary>
/// Message to play when snoughing.
/// </summary>
[DataField("snoughMessage")] public string SnoughMessage = "disease-sneeze";
/// <summary>
/// Sound to play when snoughing.
/// </summary>
[DataField("snoughSound")] public SoundSpecifier? SnoughSound;
/// <summary>
/// The random time between incidents, (min, max).
/// </summary>
[DataField("timeBetweenIncidents", required: true)]
public Vector2 TimeBetweenIncidents { get; }
public float NextIncidentTime;
}

View File

@@ -0,0 +1,52 @@
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);
}
}
}