From 43ef5946771d6bb9be7b5925bd217c1aaf15f82f Mon Sep 17 00:00:00 2001 From: Dexler <69513582+DexlerXD@users.noreply.github.com> Date: Thu, 15 Feb 2024 03:43:28 +0300 Subject: [PATCH] Added sleeping on chairs (#735) --- .../AddSleepAction/AddSleepActionComponent.cs | 9 +++++ .../AddSleepAction/AddSleepActionSystem.cs | 34 +++++++++++++++++++ .../Entities/Structures/Furniture/chairs.yml | 1 + 3 files changed, 44 insertions(+) create mode 100644 Content.Server/SS220/AddSleepAction/AddSleepActionComponent.cs create mode 100644 Content.Server/SS220/AddSleepAction/AddSleepActionSystem.cs diff --git a/Content.Server/SS220/AddSleepAction/AddSleepActionComponent.cs b/Content.Server/SS220/AddSleepAction/AddSleepActionComponent.cs new file mode 100644 index 000000000000..fe0439cef4fb --- /dev/null +++ b/Content.Server/SS220/AddSleepAction/AddSleepActionComponent.cs @@ -0,0 +1,9 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt + +namespace Content.Server.SS220.AddSleepAction; + +[RegisterComponent] +public sealed partial class AddSleepActionComponent : Component +{ + [DataField("sleepAction")] public EntityUid? SleepAction; +} diff --git a/Content.Server/SS220/AddSleepAction/AddSleepActionSystem.cs b/Content.Server/SS220/AddSleepAction/AddSleepActionSystem.cs new file mode 100644 index 000000000000..c157d31f45a1 --- /dev/null +++ b/Content.Server/SS220/AddSleepAction/AddSleepActionSystem.cs @@ -0,0 +1,34 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt + +using Content.Server.Actions; +using Content.Server.Bed.Sleep; +using Content.Shared.Buckle.Components; + +namespace Content.Server.SS220.AddSleepAction; + +public sealed class AddSleepActionSystem : EntitySystem +{ + [Dependency] private readonly ActionsSystem _actionsSystem = default!; + [Dependency] private readonly SleepingSystem _sleepingSystem = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnBuckleChanged); + } + + private void OnBuckleChanged(EntityUid uid, AddSleepActionComponent component, BuckleChangeEvent args) + { + // Partially yoinked from BedSystem + + if (args.Buckling) + { + _actionsSystem.AddAction(args.BuckledEntity, ref component.SleepAction, SleepingSystem.SleepActionId, uid); + return; + } + + _actionsSystem.RemoveAction(args.BuckledEntity, component.SleepAction); + _sleepingSystem.TryWaking(args.BuckledEntity); + } +} diff --git a/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml b/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml index 047f03401361..a39a600a0090 100644 --- a/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml +++ b/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml @@ -48,6 +48,7 @@ collection: MetalBreak - type: StaticPrice price: 10 + - type: AddSleepAction #SS220-chair-sleep - type: entity name: chair