Files
crystall-punk-14/Content.Shared/Bed/Sleep/SharedSleepingSystem.cs

72 lines
2.3 KiB
C#
Raw Normal View History

2022-07-27 00:46:24 -04:00
using Content.Shared.Speech;
using Content.Shared.Actions;
using Content.Shared.Bed.Sleep;
using Content.Shared.Eye.Blinding.Systems;
2022-07-27 00:46:24 -04:00
namespace Content.Server.Bed.Sleep
{
2023-01-10 22:46:58 +11:00
public abstract class SharedSleepingSystem : EntitySystem
2022-07-27 00:46:24 -04:00
{
[Dependency] private readonly BlindableSystem _blindableSystem = default!;
2023-01-10 22:46:58 +11:00
2022-07-27 00:46:24 -04:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SleepingComponent, ComponentStartup>(OnStartup);
2022-07-27 00:46:24 -04:00
SubscribeLocalEvent<SleepingComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<SleepingComponent, SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<SleepingComponent, CanSeeAttemptEvent>(OnSeeAttempt);
2023-01-10 22:46:58 +11:00
SubscribeLocalEvent<SleepingComponent, EntityUnpausedEvent>(OnSleepUnpaused);
}
private void OnSleepUnpaused(EntityUid uid, SleepingComponent component, ref EntityUnpausedEvent args)
{
component.CoolDownEnd += args.PausedTime;
Dirty(component);
2022-07-27 00:46:24 -04:00
}
private void OnStartup(EntityUid uid, SleepingComponent component, ComponentStartup args)
2022-07-27 00:46:24 -04:00
{
var ev = new SleepStateChangedEvent(true);
RaiseLocalEvent(uid, ev);
_blindableSystem.UpdateIsBlind(uid);
2022-07-27 00:46:24 -04:00
}
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
{
var ev = new SleepStateChangedEvent(false);
RaiseLocalEvent(uid, ev);
_blindableSystem.UpdateIsBlind(uid);
2022-07-27 00:46:24 -04:00
}
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
{
args.Cancel();
}
private void OnSeeAttempt(EntityUid uid, SleepingComponent component, CanSeeAttemptEvent args)
{
if (component.LifeStage <= ComponentLifeStage.Running)
args.Cancel();
}
2022-07-27 00:46:24 -04:00
}
}
public sealed class SleepActionEvent : InstantActionEvent {}
public sealed class WakeActionEvent : InstantActionEvent {}
/// <summary>
/// Raised on an entity when they fall asleep or wake up.
/// </summary>
public sealed class SleepStateChangedEvent : EntityEventArgs
{
public bool FellAsleep = false;
public SleepStateChangedEvent(bool fellAsleep)
{
FellAsleep = fellAsleep;
}
}