From 542428df32e5485ed48e6d0db13eadb5a62965cc Mon Sep 17 00:00:00 2001 From: moneyl <8206401+Moneyl@users.noreply.github.com> Date: Fri, 29 Nov 2019 11:04:36 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20the=20player=20being=20able=20to=20use?= =?UTF-8?q?=20the=20chem=20dispenser=20when=20they'=E2=80=A6=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes the player being able to use the chem dispenser when they're dead Adds a check to `ReagentDispenserComponent.OnUiReceiveMessage()` that checks if the players `SpeciesComponent` has a damage state that prevents them from interacting with the chem dispenser. * Switch to use ActionBlockSystem instead of checking SpeciesComponent directly --- .../Chemistry/ReagentDispenserComponent.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index b044a3d9e1..85caf70269 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -11,6 +11,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; @@ -101,6 +102,9 @@ namespace Content.Server.GameObjects.Components.Chemistry /// A user interface message from the client. private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) { + if(!PlayerCanUseDispenser(obj.Session.AttachedEntity)) + return; + var msg = (UiButtonPressedMessage) obj.Message; switch (msg.Button) { @@ -142,6 +146,23 @@ namespace Content.Server.GameObjects.Components.Chemistry ClickSound(); } + /// + /// Checks whether the player entity is able to use the chem dispenser. + /// + /// The player entity. + /// Returns true if the entity can use the dispenser, and false if it cannot. + private bool PlayerCanUseDispenser(IEntity playerEntity) + { + //Need player entity to check if they are still able to use the dispenser + if (playerEntity == null) + return false; + //Check if player can interact in their current state + if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity)) + return false; + + return true; + } + /// /// Gets component data to be used to update the user interface client-side. ///