Fixes the player being able to use the chem dispenser when they'… (#480)

* 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
This commit is contained in:
moneyl
2019-11-29 11:04:36 -05:00
committed by Pieter-Jan Briers
parent adaf0ade52
commit 542428df32

View File

@@ -11,6 +11,7 @@ using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -101,6 +102,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// <param name="obj">A user interface message from the client.</param> /// <param name="obj">A user interface message from the client.</param>
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{ {
if(!PlayerCanUseDispenser(obj.Session.AttachedEntity))
return;
var msg = (UiButtonPressedMessage) obj.Message; var msg = (UiButtonPressedMessage) obj.Message;
switch (msg.Button) switch (msg.Button)
{ {
@@ -142,6 +146,23 @@ namespace Content.Server.GameObjects.Components.Chemistry
ClickSound(); ClickSound();
} }
/// <summary>
/// Checks whether the player entity is able to use the chem dispenser.
/// </summary>
/// <param name="playerEntity">The player entity.</param>
/// <returns>Returns true if the entity can use the dispenser, and false if it cannot.</returns>
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;
}
/// <summary> /// <summary>
/// Gets component data to be used to update the user interface client-side. /// Gets component data to be used to update the user interface client-side.
/// </summary> /// </summary>