New status effect system (#37238)
* 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 commit bca02b82bae18ae131af593d7eb86e6de2745157. * Revert "Update TemporaryStealthComponent.cs" This reverts commit 4a5be8c4b704a0d1ff9544b2e245d8b2701ec580. * Revert "Update TemporaryStealthComponent.cs" This reverts commit a4875bcb41347638854bd723d96a51c3e6d38034. * Revert "added into liquid anomaly" This reverts commit df5086b14bb35f1467158a36807c0f2163a16d99. * Revert "documentation" This reverts commit 3629b9466758cbdfa4dd5e67ece122fa2f181138. * Revert "spectra" This reverts commit 2d03d88c16d16ad6831c19a7921b84600daeb284. * 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>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Server.StatusEffectNew;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Drowsiness;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.StatusEffectNew;
|
||||
using Content.Shared.StatusEffectNew.Components;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -8,9 +10,6 @@ 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 IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
|
||||
@@ -18,33 +17,37 @@ public sealed class DrowsinessSystem : SharedDrowsinessSystem
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<DrowsinessComponent, ComponentStartup>(OnInit);
|
||||
SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectAppliedEvent>(OnEffectApplied);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, DrowsinessComponent component, ComponentStartup args)
|
||||
private void OnEffectApplied(Entity<DrowsinessStatusEffectComponent> ent, ref StatusEffectAppliedEvent args)
|
||||
{
|
||||
component.NextIncidentTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y));
|
||||
ent.Comp.NextIncidentTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(ent.Comp.TimeBetweenIncidents.X, ent.Comp.TimeBetweenIncidents.Y));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<DrowsinessComponent>();
|
||||
while (query.MoveNext(out var uid, out var component))
|
||||
var query = EntityQueryEnumerator<DrowsinessStatusEffectComponent, StatusEffectComponent>();
|
||||
while (query.MoveNext(out var uid, out var drowsiness, out var statusEffect))
|
||||
{
|
||||
if (_timing.CurTime < component.NextIncidentTime)
|
||||
if (_timing.CurTime < drowsiness.NextIncidentTime)
|
||||
continue;
|
||||
|
||||
if (statusEffect.AppliedTo is null)
|
||||
continue;
|
||||
|
||||
// Set the new time.
|
||||
component.NextIncidentTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(component.TimeBetweenIncidents.X, component.TimeBetweenIncidents.Y));
|
||||
drowsiness.NextIncidentTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(drowsiness.TimeBetweenIncidents.X, drowsiness.TimeBetweenIncidents.Y));
|
||||
|
||||
// sleep duration
|
||||
var duration = TimeSpan.FromSeconds(_random.NextFloat(component.DurationOfIncident.X, component.DurationOfIncident.Y));
|
||||
var duration = TimeSpan.FromSeconds(_random.NextFloat(drowsiness.DurationOfIncident.X, drowsiness.DurationOfIncident.Y));
|
||||
|
||||
// Make sure the sleep time doesn't cut into the time to next incident.
|
||||
component.NextIncidentTime += duration;
|
||||
drowsiness.NextIncidentTime += duration;
|
||||
|
||||
_statusEffects.TryAddStatusEffect<ForcedSleepingComponent>(uid, SleepKey, duration, false);
|
||||
_statusEffects.TryAddStatusEffect(statusEffect.AppliedTo.Value, SleepingSystem.StatusEffectForcedSleeping, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user