fish-station/Content.Server/Traits/Assorted/NarcolepsySystem.cs
Lgibb18 95da9625e8
Разумная болезнь опять (#157)
* disease

* eula

* disease 2

* why

* fix

* фикс рси и локализаций

* update

* Revert "update"

This reverts commit ac33a3a1124175a87b82a72ed49f228e8c6c8aa6.

* фикс работоспособности, опять

* никакого лигуба, только санрайз

* санрайзотизация прототипов, спавн болезни

* ещё всякая хрень

* фуу статистика в конце раунда

---------

Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
2024-08-14 22:17:14 +03:00

86 lines
3 KiB
C#

using System.Numerics;
using Content.Shared.Bed.Sleep;
using Content.Shared.StatusEffect;
using Robust.Shared.Random;
using System.Numerics;
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
{
[ValidatePrototypeId<StatusEffectPrototype>]
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 void AdjustNarcolepsyTimer(EntityUid uid, int TimerReset, NarcolepsyComponent? narcolepsy = null)
{
if (!Resolve(uid, ref narcolepsy, false))
return;
narcolepsy.NextIncidentTime = TimerReset;
}
public void SetNarcolepsy(EntityUid uid, Vector2 timeBetweenIncidents, Vector2 durationOfIncident, NarcolepsyComponent? narcolepsy = null)
{
if (!Resolve(uid, ref narcolepsy, false))
return;
narcolepsy.DurationOfIncident = durationOfIncident;
narcolepsy.TimeBetweenIncidents = timeBetweenIncidents;
}
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<ForcedSleepingComponent>(uid, StatusEffectKey,
TimeSpan.FromSeconds(duration), false);
}
}
// Sunrise-Start
public void SetTime(EntityUid uid, Vector2 timeBetween, Vector2 duration, NarcolepsyComponent? component = null)
{
if (!Resolve(uid, ref component))
{
return;
}
component.TimeBetweenIncidents = timeBetween;
component.DurationOfIncident = duration;
Dirty(uid, component);
}
// Sunrise-End
}