Sleeping (#9793)
This commit is contained in:
11
Content.Shared/Bed/Sleep/ForcedSleepingComponent.cs
Normal file
11
Content.Shared/Bed/Sleep/ForcedSleepingComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Bed.Sleep
|
||||
{
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
/// <summary>
|
||||
/// Prevents waking up. Use as a status effect.
|
||||
/// </summary>
|
||||
public sealed class ForcedSleepingComponent : Component
|
||||
{}
|
||||
}
|
||||
56
Content.Shared/Bed/Sleep/SharedSleepingSystem.cs
Normal file
56
Content.Shared/Bed/Sleep/SharedSleepingSystem.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.Speech;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
|
||||
namespace Content.Server.Bed.Sleep
|
||||
{
|
||||
public sealed class SharedSleepingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedBlindingSystem _blindingSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SleepingComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<SleepingComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<SleepingComponent, SpeakAttemptEvent>(OnSpeakAttempt);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, SleepingComponent component, ComponentInit args)
|
||||
{
|
||||
var ev = new SleepStateChangedEvent(true);
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
_blindingSystem.AdjustBlindSources(uid, true);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
|
||||
{
|
||||
var ev = new SleepStateChangedEvent(false);
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
_blindingSystem.AdjustBlindSources(uid, false);
|
||||
}
|
||||
|
||||
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
14
Content.Shared/Bed/Sleep/SleepingComponent.cs
Normal file
14
Content.Shared/Bed/Sleep/SleepingComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Bed.Sleep;
|
||||
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
/// <summary>
|
||||
/// Added to entities when they go to sleep.
|
||||
/// </summary>
|
||||
public sealed class SleepingComponent : Component
|
||||
{
|
||||
// How much damage of any type it takes to wake this entity.
|
||||
[DataField("wakeThreshold")]
|
||||
public float WakeThreshold = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user