Files
OldThink/Content.Server/Drowsiness/DrowsinessSystem.cs
ThereDrD0 bc57436166 Новые растения в ботанику (#416)
* add haloperidol, potassium iodide

* review fixes

* review and tuning

* add: translation

* new mutations

* translation string fix

* holymelons are holy now

* add: translation

* rename holymelon

* Tomato killers don't kill the server anymore. (#28173)

* tomato killer auto death

* fix

* Update miscellaneous.yml

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
2024-07-03 01:03:39 +03:00

50 lines
1.8 KiB
C#

using Content.Shared.Drowsiness;
using Content.Shared.Bed.Sleep;
using Content.Shared.StatusEffect;
using Robust.Shared.Random;
namespace Content.Server.Drowsiness;
public sealed class DrowsinessSystem : SharedDrowsinessSystem
{
[ValidatePrototypeId<StatusEffectPrototype>]
private const string SleepKey = "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<DrowsinessComponent, ComponentStartup>(SetupDrowsiness);
}
private void SetupDrowsiness(EntityUid uid, DrowsinessComponent component, ComponentStartup args)
{
component.NextIncidentTime = _random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<DrowsinessComponent>();
while (query.MoveNext(out var uid, out var component))
{
component.NextIncidentTime -= frameTime;
if (component.NextIncidentTime >= 0)
continue;
// Set the new time.
component.NextIncidentTime += _random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y);
var duration = _random.NextFloat(component.DurationOfIncident.X, component.DurationOfIncident.Y);
// Make sure the sleep time doesn't cut into the time to next incident.
component.NextIncidentTime += duration;
_statusEffects.TryAddStatusEffect<ForcedSleepingComponent>(uid, SleepKey, TimeSpan.FromSeconds(duration), false);
}
}
}