using Content.Shared.StatusEffectNew;
using Robust.Client.Graphics;
using Robust.Client.Player;
+using Robust.Shared.Player;
namespace Content.Client.Drowsiness;
SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectAppliedEvent>(OnDrowsinessApply);
SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectRemovedEvent>(OnDrowsinessShutdown);
- SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectPlayerAttachedEvent>(OnStatusEffectPlayerAttached);
- SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectPlayerDetachedEvent>(OnStatusEffectPlayerDetached);
+ SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectRelayedEvent<LocalPlayerAttachedEvent>>(OnStatusEffectPlayerAttached);
+ SubscribeLocalEvent<DrowsinessStatusEffectComponent, StatusEffectRelayedEvent<LocalPlayerDetachedEvent>>(OnStatusEffectPlayerDetached);
_overlay = new();
}
}
}
- private void OnStatusEffectPlayerAttached(Entity<DrowsinessStatusEffectComponent> ent, ref StatusEffectPlayerAttachedEvent args)
+ private void OnStatusEffectPlayerAttached(Entity<DrowsinessStatusEffectComponent> ent, ref StatusEffectRelayedEvent<LocalPlayerAttachedEvent> args)
{
- if (_player.LocalEntity != args.Target)
- return;
-
_overlayMan.AddOverlay(_overlay);
}
- private void OnStatusEffectPlayerDetached(Entity<DrowsinessStatusEffectComponent> ent, ref StatusEffectPlayerDetachedEvent args)
+ private void OnStatusEffectPlayerDetached(Entity<DrowsinessStatusEffectComponent> ent, ref StatusEffectRelayedEvent<LocalPlayerDetachedEvent> args)
{
- if (_player.LocalEntity != args.Target)
+ if (_player.LocalEntity is null)
return;
if (!_statusEffects.HasEffectComp<DrowsinessStatusEffectComponent>(_player.LocalEntity.Value))
/// </summary>
[DataField, AutoPausedField, Access(typeof(SSDIndicatorSystem))]
public TimeSpan FallAsleepTime = TimeSpan.Zero;
-
- /// <summary>
- /// Required to don't remove forced sleep from other sources
- /// </summary>
- [ViewVariables(VVAccess.ReadWrite)]
- [AutoNetworkedField]
- public bool ForcedSleepAdded = false;
}
-using Content.Shared.Bed.Sleep;
using Content.Shared.CCVar;
using Content.Shared.StatusEffectNew;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
+using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.SSDIndicator;
/// </summary>
public sealed class SSDIndicatorSystem : EntitySystem
{
+ public static readonly EntProtoId StatusEffectSSDSleeping = "StatusEffectSSDSleeping";
+
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedStatusEffectsSystem _statusEffects = default!;
if (_icSsdSleep)
{
component.FallAsleepTime = TimeSpan.Zero;
- if (component.ForcedSleepAdded) // Remove component only if it has been added by this system
- {
- _statusEffects.TryRemoveStatusEffect(uid, SleepingSystem.StatusEffectForcedSleeping);
- component.ForcedSleepAdded = false;
- }
+ _statusEffects.TryRemoveStatusEffect(uid, StatusEffectSSDSleeping);
}
Dirty(uid, component);
ssd.FallAsleepTime <= _timing.CurTime &&
!TerminatingOrDeleted(uid))
{
- _statusEffects.TryAddStatusEffect(uid, SleepingSystem.StatusEffectForcedSleeping);
- ssd.ForcedSleepAdded = true;
+ _statusEffects.TryAddStatusEffect(uid, StatusEffectSSDSleeping);
}
}
}
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
-using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
{
base.Initialize();
+ InitializeRelay();
+
SubscribeLocalEvent<StatusEffectComponent, StatusEffectAppliedEvent>(OnStatusEffectApplied);
SubscribeLocalEvent<StatusEffectComponent, StatusEffectRemovedEvent>(OnStatusEffectRemoved);
- SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerAttachedEvent>(OnStatusEffectContainerAttached);
- SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerDetachedEvent>(OnStatusEffectContainerDetached);
SubscribeLocalEvent<StatusEffectContainerComponent, ComponentGetState>(OnGetState);
_containerQuery = GetEntityQuery<StatusEffectContainerComponent>();
args.State = new StatusEffectContainerComponentState(GetNetEntitySet(ent.Comp.ActiveStatusEffects));
}
- private void OnStatusEffectContainerAttached(Entity<StatusEffectContainerComponent> ent, ref LocalPlayerAttachedEvent args)
- {
- foreach (var effect in ent.Comp.ActiveStatusEffects)
- {
- var ev = new StatusEffectPlayerAttachedEvent(ent);
- RaiseLocalEvent(effect, ref ev);
- }
- }
-
- private void OnStatusEffectContainerDetached(Entity<StatusEffectContainerComponent> ent, ref LocalPlayerDetachedEvent args)
- {
- foreach (var effect in ent.Comp.ActiveStatusEffects)
- {
- var ev = new StatusEffectPlayerDetachedEvent(ent);
- RaiseLocalEvent(effect, ref ev);
- }
- }
-
public override void Update(float frameTime)
{
base.Update(frameTime);
[ByRefEvent]
public readonly record struct StatusEffectRemovedEvent(EntityUid Target);
-/// <summary>
-/// Called on a status effect entity inside <see cref="StatusEffectContainerComponent"/>
-/// after a player has been <see cref="LocalPlayerAttachedEvent"/> to this container entity.
-/// </summary>
-[ByRefEvent]
-public readonly record struct StatusEffectPlayerAttachedEvent(EntityUid Target);
-
-/// <summary>
-/// Called on a status effect entity inside <see cref="StatusEffectContainerComponent"/>
-/// after a player has been <see cref="LocalPlayerDetachedEvent"/> to this container entity.
-/// </summary>
-[ByRefEvent]
-public readonly record struct StatusEffectPlayerDetachedEvent(EntityUid Target);
-
/// <summary>
/// Raised on an entity before a status effect is added to determine if adding it should be cancelled.
/// </summary>
--- /dev/null
+using Content.Shared.StatusEffectNew.Components;
+using Robust.Shared.Player;
+
+namespace Content.Shared.StatusEffectNew;
+
+public abstract partial class SharedStatusEffectsSystem
+{
+ protected void InitializeRelay()
+ {
+ SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerAttachedEvent>(RelayStatusEffectEvent);
+ SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerDetachedEvent>(RelayStatusEffectEvent);
+ }
+
+ protected void RefRelayStatusEffectEvent<T>(EntityUid uid, StatusEffectContainerComponent component, ref T args) where T : struct
+ {
+ RelayEvent((uid, component), ref args);
+ }
+
+ protected void RelayStatusEffectEvent<T>(EntityUid uid, StatusEffectContainerComponent component, T args) where T : class
+ {
+ RelayEvent((uid, component), args);
+ }
+
+ public void RelayEvent<T>(Entity<StatusEffectContainerComponent> statusEffect, ref T args) where T : struct
+ {
+ // this copies the by-ref event if it is a struct
+ var ev = new StatusEffectRelayedEvent<T>(args);
+ foreach (var activeEffect in statusEffect.Comp.ActiveStatusEffects)
+ {
+ RaiseLocalEvent(activeEffect, ref ev);
+ }
+ // and now we copy it back
+ args = ev.Args;
+ }
+
+ public void RelayEvent<T>(Entity<StatusEffectContainerComponent> statusEffect, T args) where T : class
+ {
+ // this copies the by-ref event if it is a struct
+ var ev = new StatusEffectRelayedEvent<T>(args);
+ foreach (var activeEffect in statusEffect.Comp.ActiveStatusEffects)
+ {
+ RaiseLocalEvent(activeEffect, ref ev);
+ }
+ }
+}
+
+/// <summary>
+/// Event wrapper for relayed events.
+/// </summary>
+[ByRefEvent]
+public record struct StatusEffectRelayedEvent<TEvent>(TEvent Args);
components:
- type: ForcedSleepingStatusEffect
+# This creature is asleep because it's disconnected from the game.
+- type: entity
+ parent: MobStatusEffectBase
+ id: StatusEffectSSDSleeping
+ name: forced sleep
+ components:
+ - type: ForcedSleepingStatusEffect
+
# Blurs your vision and makes you randomly fall asleep
- type: entity
parent: MobStatusEffectBase