mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
* spectra * documentation * added into liquid anomaly * Update TemporaryStealthComponent.cs * Update TemporaryStealthComponent.cs * integrated * new system * mark old status effect system as obsolete * ForcedSleeping new status effect * work with reagents * networking??? * Revert "integrated" This reverts commitbca02b82ba. * Revert "Update TemporaryStealthComponent.cs" This reverts commit4a5be8c4b7. * Revert "Update TemporaryStealthComponent.cs" This reverts commita4875bcb41. * Revert "added into liquid anomaly" This reverts commitdf5086b14b. * Revert "documentation" This reverts commit3629b94667. * Revert "spectra" This reverts commit2d03d88c16. * drowsiness status effect remove * reagents work * polish, remove test changes * first Fildrance review part * Update misc.yml * more fildrance review * final part * fix trailing spaces * sleeping status effect * drowsiness status effect * Create ModifyStatusEffect.cs * some tweak * Yay!!! Manual networking * minor nitpick * oopsie * refactor: xml-docs, notnullwhen attributes, whitespaces * fildrance and emo review * refactor: simplify check in SharedStatusEffectsSystem by using pattern matching, TryEffectsWithComp now returns set of Entity<T, StatusEffectComponent> --------- Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using Content.Server.StatusEffectNew;
|
|
using Content.Shared.Bed.Sleep;
|
|
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
|
|
{
|
|
[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 void AdjustNarcolepsyTimer(EntityUid uid, int TimerReset, NarcolepsyComponent? narcolepsy = null)
|
|
{
|
|
if (!Resolve(uid, ref narcolepsy, false))
|
|
return;
|
|
|
|
narcolepsy.NextIncidentTime = TimerReset;
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<NarcolepsyComponent>();
|
|
while (query.MoveNext(out var uid, out var narcolepsy))
|
|
{
|
|
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(uid, SleepingSystem.StatusEffectForcedSleeping, TimeSpan.FromSeconds(duration));
|
|
}
|
|
}
|
|
}
|