Disable speaking while unconscious/dead (#362)

* Disable speaking while unconscious/dead

Fixes #359

* Add CanSpeak ActionBlocker

Matches the existing technique for other actions like CanUse() and CanThrow().
This commit is contained in:
moneyl
2019-09-24 03:55:38 -04:00
committed by Pieter-Jan Briers
parent 3e972b501a
commit 31487c1cf1
4 changed files with 39 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
using System.Linq;
using Content.Server.GameObjects;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Shared.Chat;
@@ -47,6 +49,11 @@ namespace Content.Server.Chat
public void EntitySay(IEntity source, string message)
{
if (!ActionBlockerSystem.CanSpeak(source))
{
return;
}
var pos = source.Transform.GridPosition;
var clients = _playerManager.GetPlayersInRange(pos, VoiceRange).Select(p => p.ConnectedClient);

View File

@@ -51,6 +51,11 @@ namespace Content.Server.GameObjects
{
return true;
}
bool IActionBlocker.CanSpeak()
{
return true;
}
}
/// <summary>
@@ -87,6 +92,11 @@ namespace Content.Server.GameObjects
{
return false;
}
bool IActionBlocker.CanSpeak()
{
return false;
}
}
/// <summary>
@@ -133,5 +143,10 @@ namespace Content.Server.GameObjects
{
return false;
}
bool IActionBlocker.CanSpeak()
{
return false;
}
}
}

View File

@@ -82,6 +82,11 @@ namespace Content.Server.GameObjects
return CurrentDamageState.CanThrow();
}
bool IActionBlocker.CanSpeak()
{
return CurrentDamageState.CanSpeak();
}
List<DamageThreshold> IOnDamageBehavior.GetAllDamageThresholds()
{
var thresholdlist = DamageTemplate.DamageThresholds;

View File

@@ -12,6 +12,8 @@ namespace Content.Server.GameObjects.EntitySystems
bool CanUse();
bool CanThrow();
bool CanSpeak();
}
public class ActionBlockerSystem : EntitySystem
@@ -55,5 +57,15 @@ namespace Content.Server.GameObjects.EntitySystems
}
return canthrow;
}
public static bool CanSpeak(IEntity entity)
{
bool canspeak = true;
foreach (var actionblockercomponents in entity.GetAllComponents<IActionBlocker>())
{
canspeak &= actionblockercomponents.CanSpeak();
}
return canspeak;
}
}
}