From 45d93d8faa45ac2dc8b0fbe9cdd070e6cd566db1 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Thu, 18 Mar 2021 02:48:17 -0700 Subject: [PATCH] Fix chairs not unbuckling entities when deconstructed or destroyed (#3696) --- .../Construction/Completions/DestroyEntity.cs | 23 +++++++++++++++++++ .../Components/Strap/StrapComponent.cs | 15 ++++++++++-- .../Recipes/Construction/Graphs/seats.yml | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 Content.Server/Construction/Completions/DestroyEntity.cs diff --git a/Content.Server/Construction/Completions/DestroyEntity.cs b/Content.Server/Construction/Completions/DestroyEntity.cs new file mode 100644 index 0000000000..ec19d58574 --- /dev/null +++ b/Content.Server/Construction/Completions/DestroyEntity.cs @@ -0,0 +1,23 @@ +#nullable enable +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.Construction; +using JetBrains.Annotations; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using System.Threading.Tasks; + +namespace Content.Server.Construction.Completions +{ + [UsedImplicitly] + [DataDefinition] + public class DestroyEntity : IGraphAction + { + public async Task PerformAction(IEntity entity, IEntity? user) + { + if (entity.Deleted) return; + + var destructibleSystem = EntitySystem.Get(); + destructibleSystem.ActSystem.HandleDestruction(entity); + } + } +} diff --git a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs index b4402c438c..7909f81a21 100644 --- a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs +++ b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs @@ -1,9 +1,10 @@ -#nullable enable +#nullable enable using System.Collections.Generic; using System.Linq; using Content.Server.GameObjects.Components.Buckle; using Content.Shared.Alert; using Content.Shared.GameObjects.Components.Strap; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Content.Shared.GameObjects.Verbs; using Content.Shared.Interfaces.GameObjects.Components; @@ -20,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Strap { [RegisterComponent] [ComponentReference(typeof(SharedStrapComponent))] - public class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks + public class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks, IDestroyAct { [ComponentDependency] public readonly SpriteComponent? SpriteComponent = null; @@ -134,6 +135,16 @@ namespace Content.Server.GameObjects.Components.Strap { base.OnRemove(); + RemoveAll(); + } + + void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs) + { + RemoveAll(); + } + + private void RemoveAll() + { foreach (var entity in _buckledEntities.ToArray()) { if (entity.TryGetComponent(out var buckle)) diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/seats.yml b/Resources/Prototypes/Recipes/Construction/Graphs/seats.yml index c7cfb34048..3652262ecd 100644 --- a/Resources/Prototypes/Recipes/Construction/Graphs/seats.yml +++ b/Resources/Prototypes/Recipes/Construction/Graphs/seats.yml @@ -4,7 +4,7 @@ graph: - node: start actions: - - !type:DeleteEntity {} + - !type:DestroyEntity {} edges: - to: chair steps: