From 1579c8a42488e9e392c453376c99aaf139b7b529 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Fri, 2 Aug 2024 00:05:12 -0700 Subject: [PATCH] Deploy foldable (#30000) * Deploy foldable * Add NetworkedComponent and access to the component * Add handled to afterinteract * Use drop target location instead of setcoordinates * Put back in hand after failed deploy This prevents dropping the bed when clicking while inside a locker. * Created BaseDeployFoldable for folding chairs, body bags, and rollerbeds --- .../Foldable/DeployFoldableComponent.cs | 7 ++++ .../Foldable/DeployFoldableSystem.cs | 39 +++++++++++++++++++ .../Objects/Specific/Medical/morgue.yml | 2 +- .../Entities/Structures/Furniture/chairs.yml | 2 +- .../Structures/Furniture/rollerbeds.yml | 2 +- Resources/Prototypes/Entities/foldable.yml | 8 ++++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 Content.Shared/Foldable/DeployFoldableComponent.cs create mode 100644 Content.Shared/Foldable/DeployFoldableSystem.cs diff --git a/Content.Shared/Foldable/DeployFoldableComponent.cs b/Content.Shared/Foldable/DeployFoldableComponent.cs new file mode 100644 index 0000000000..4ccca6b742 --- /dev/null +++ b/Content.Shared/Foldable/DeployFoldableComponent.cs @@ -0,0 +1,7 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Foldable; + +[RegisterComponent, NetworkedComponent] +[Access(typeof(DeployFoldableSystem))] +public sealed partial class DeployFoldableComponent : Component; diff --git a/Content.Shared/Foldable/DeployFoldableSystem.cs b/Content.Shared/Foldable/DeployFoldableSystem.cs new file mode 100644 index 0000000000..fa2e3f8789 --- /dev/null +++ b/Content.Shared/Foldable/DeployFoldableSystem.cs @@ -0,0 +1,39 @@ +using Content.Shared.Hands.Components; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Interaction; + +namespace Content.Shared.Foldable; + +public sealed class DeployFoldableSystem : EntitySystem +{ + [Dependency] private readonly SharedHandsSystem _hands = default!; + [Dependency] private readonly FoldableSystem _foldable = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAfterInteract); + } + + private void OnAfterInteract(Entity ent, ref AfterInteractEvent args) + { + if (args.Handled || !args.CanReach) + return; + + if (!TryComp(ent, out var foldable)) + return; + + if (!TryComp(args.User, out HandsComponent? hands) + || !_hands.TryDrop(args.User, args.Used, targetDropLocation: args.ClickLocation, handsComp: hands)) + return; + + if (!_foldable.TrySetFolded(ent, foldable, false)) + { + _hands.TryPickup(args.User, args.Used, handsComp: hands); + return; + } + + args.Handled = true; + } +} diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/morgue.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/morgue.yml index 0656621465..578e071587 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Medical/morgue.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/morgue.yml @@ -1,6 +1,6 @@ - type: entity id: BodyBag - parent: BaseFoldable + parent: BaseDeployFoldable name: body bag description: A plastic bag designed for the storage and transportation of cadavers to stop body decomposition. components: diff --git a/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml b/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml index ac5ec1e83e..c1d767905c 100644 --- a/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml +++ b/Resources/Prototypes/Entities/Structures/Furniture/chairs.yml @@ -323,7 +323,7 @@ node: chair - type: entity - parent: [SeatBase, BaseFoldable] + parent: [SeatBase, BaseDeployFoldable] id: ChairFolding name: folding chair description: If you carry six of these you become the coolest kid at church. diff --git a/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml b/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml index b3cfe6ade3..f7b1be8ecd 100644 --- a/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml +++ b/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml @@ -1,6 +1,6 @@ - type: entity id: RollerBed - parent: [BaseItem, BaseFoldable] + parent: [BaseItem, BaseDeployFoldable] name: rollerbed description: Used to carry patients around without damaging them. components: diff --git a/Resources/Prototypes/Entities/foldable.yml b/Resources/Prototypes/Entities/foldable.yml index a0843cd125..260cda799b 100644 --- a/Resources/Prototypes/Entities/foldable.yml +++ b/Resources/Prototypes/Entities/foldable.yml @@ -13,3 +13,11 @@ unfoldedLayer: True: {visible: false} False: {visible: true} + +- type: entity + abstract: true + parent: BaseFoldable + id: BaseDeployFoldable + name: "deploy foldable" + components: + - type: DeployFoldable