2022-07-27 00:46:24 -04:00
|
|
|
using Content.Shared.Actions;
|
|
|
|
|
using Content.Shared.Bed.Sleep;
|
2023-09-28 18:05:36 -07:00
|
|
|
using Content.Shared.Damage.ForceSay;
|
2023-04-29 17:32:14 +12:00
|
|
|
using Content.Shared.Eye.Blinding.Systems;
|
2024-02-03 03:09:20 -05:00
|
|
|
using Content.Shared.Pointing;
|
2023-09-08 18:16:05 -07:00
|
|
|
using Content.Shared.Speech;
|
2023-09-09 16:14:17 -07:00
|
|
|
using Robust.Shared.Network;
|
2023-09-08 18:16:05 -07:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Timing;
|
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
|
|
|
{
|
2023-09-08 18:16:05 -07:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
2023-04-29 17:32:14 +12:00
|
|
|
[Dependency] private readonly BlindableSystem _blindableSystem = default!;
|
2023-01-10 22:46:58 +11:00
|
|
|
|
2023-09-08 18:16:05 -07:00
|
|
|
[ValidatePrototypeId<EntityPrototype>] private const string WakeActionId = "ActionWake";
|
|
|
|
|
|
2022-07-27 00:46:24 -04:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2023-09-23 04:49:39 -04:00
|
|
|
SubscribeLocalEvent<SleepingComponent, MapInitEvent>(OnMapInit);
|
2022-07-27 00:46:24 -04:00
|
|
|
SubscribeLocalEvent<SleepingComponent, ComponentShutdown>(OnShutdown);
|
|
|
|
|
SubscribeLocalEvent<SleepingComponent, SpeakAttemptEvent>(OnSpeakAttempt);
|
2023-04-29 17:32:14 +12:00
|
|
|
SubscribeLocalEvent<SleepingComponent, CanSeeAttemptEvent>(OnSeeAttempt);
|
2024-02-03 03:09:20 -05:00
|
|
|
SubscribeLocalEvent<SleepingComponent, PointAttemptEvent>(OnPointAttempt);
|
2023-01-10 22:46:58 +11:00
|
|
|
}
|
|
|
|
|
|
2022-07-27 00:46:24 -04:00
|
|
|
|
2023-09-23 04:49:39 -04:00
|
|
|
private void OnMapInit(EntityUid uid, SleepingComponent component, MapInitEvent args)
|
2022-07-27 00:46:24 -04:00
|
|
|
{
|
|
|
|
|
var ev = new SleepStateChangedEvent(true);
|
2022-11-07 21:32:36 -05:00
|
|
|
RaiseLocalEvent(uid, ev);
|
2023-04-29 17:32:14 +12:00
|
|
|
_blindableSystem.UpdateIsBlind(uid);
|
2023-09-23 04:49:39 -04:00
|
|
|
_actionsSystem.AddAction(uid, ref component.WakeAction, WakeActionId, uid);
|
2022-07-27 00:46:24 -04:00
|
|
|
|
2023-09-23 04:49:39 -04:00
|
|
|
// TODO remove hardcoded time.
|
2024-03-30 09:52:27 +03:00
|
|
|
_actionsSystem.SetCooldown(component.WakeAction, _gameTiming.CurTime, _gameTiming.CurTime + TimeSpan.FromSeconds(2f));
|
2023-09-08 18:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-27 00:46:24 -04:00
|
|
|
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
|
|
|
|
|
{
|
2023-09-08 18:16:05 -07:00
|
|
|
_actionsSystem.RemoveAction(uid, component.WakeAction);
|
2022-07-27 00:46:24 -04:00
|
|
|
var ev = new SleepStateChangedEvent(false);
|
2022-11-07 21:32:36 -05:00
|
|
|
RaiseLocalEvent(uid, ev);
|
2023-04-29 17:32:14 +12:00
|
|
|
_blindableSystem.UpdateIsBlind(uid);
|
2022-07-27 00:46:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
|
|
|
|
|
{
|
2023-09-28 18:05:36 -07:00
|
|
|
// TODO reduce duplication of this behavior with MobStateSystem somehow
|
|
|
|
|
if (HasComp<AllowNextCritSpeechComponent>(uid))
|
|
|
|
|
{
|
|
|
|
|
RemCompDeferred<AllowNextCritSpeechComponent>(uid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 00:46:24 -04:00
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2023-04-29 17:32:14 +12:00
|
|
|
|
|
|
|
|
private void OnSeeAttempt(EntityUid uid, SleepingComponent component, CanSeeAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.LifeStage <= ComponentLifeStage.Running)
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2024-02-03 03:09:20 -05:00
|
|
|
|
|
|
|
|
private void OnPointAttempt(EntityUid uid, SleepingComponent component, PointAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2022-07-27 00:46:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class SleepActionEvent : InstantActionEvent {}
|
2022-07-27 00:46:24 -04:00
|
|
|
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class WakeActionEvent : InstantActionEvent {}
|
2022-07-27 00:46:24 -04:00
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
}
|