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

View File

@@ -104,6 +104,8 @@ namespace Content.Shared.Eye.Blinding
}
blindable.Sources = Math.Max(blindable.Sources, 0);
Dirty(blindable);
}
public void AdjustEyeDamage(EntityUid uid, bool add, BlindableComponent? blindable = null)

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Traits.Assorted;
/// <summary>
/// This is used for making something blind forever.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class PermanentBlindnessComponent : Component
{
}

View File

@@ -0,0 +1,41 @@
using Content.Shared.Examine;
using Content.Shared.Eye.Blinding;
using Content.Shared.IdentityManagement;
using Robust.Shared.Network;
namespace Content.Shared.Traits.Assorted;
/// <summary>
/// This handles permanent blindness, both the examine and the actual effect.
/// </summary>
public sealed class PermanentBlindnessSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedBlindingSystem _blinding = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<PermanentBlindnessComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<PermanentBlindnessComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<PermanentBlindnessComponent, ExaminedEvent>(OnExamined);
}
private void OnExamined(EntityUid uid, PermanentBlindnessComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange && !_net.IsClient)
{
args.PushMarkup(Loc.GetString("permanent-blindness-trait-examined", ("target", Identity.Entity(uid, EntityManager))));
}
}
private void OnShutdown(EntityUid uid, PermanentBlindnessComponent component, ComponentShutdown args)
{
_blinding.AdjustBlindSources(uid, false);
}
private void OnStartup(EntityUid uid, PermanentBlindnessComponent component, ComponentStartup args)
{
_blinding.AdjustBlindSources(uid, true);
}
}

View File

@@ -0,0 +1 @@
permanent-blindness-trait-examined = [color=lightblue]{CAPITALIZE(POSS-ADJ($target))} eyes are glassy and unfocused. It doesn't seem like {SUBJECT($target)} can see you.[/color]

View File

@@ -0,0 +1,19 @@
- type: trait
id: Blindness
name: Blindness
components:
- type: PermanentBlindness
- type: trait
id: Narcolepsy
name: Narcolepsy
components:
- type: Narcolepsy
timeBetweenIncidents: 300, 600
durationOfIncident: 10, 30
- type: trait
id: Pacifist
name: Pacifist
components:
- type: Pacifist

View File

@@ -0,0 +1,10 @@
- type: trait
id: UncontrollableSneezing
name: Runny nose
components:
- type: UncontrollableSnough
snoughSound:
collection: Sneezes
params:
variation: 0.2
timeBetweenIncidents: 0.3, 300