forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathShowHealthBarsCommand.cs
57 lines (47 loc) · 1.96 KB
/
ShowHealthBarsCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Content.Shared.Damage.Prototypes;
using Content.Shared.Overlays;
using Robust.Client.Player;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Client.Commands;
public sealed class ShowHealthBarsCommand : LocalizedCommands
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Command => "showhealthbars";
public override string Help => LocalizationManager.GetString($"cmd-{Command}-help", ("command", Command));
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = _playerManager.LocalSession;
if (player == null)
{
shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error-not-player"));
return;
}
var playerEntity = player?.AttachedEntity;
if (!playerEntity.HasValue)
{
shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error-no-entity"));
return;
}
if (!_entityManager.HasComponent<ShowHealthBarsComponent>(playerEntity))
{
var showHealthBarsComponent = new ShowHealthBarsComponent
{
DamageContainers = args.Select(arg => new ProtoId<DamageContainerPrototype>(arg)).ToList(),
HealthStatusIcon = null,
NetSyncEnabled = false
};
_entityManager.AddComponent(playerEntity.Value, showHealthBarsComponent, true);
shell.WriteLine(LocalizationManager.GetString($"cmd-{Command}-notify-enabled", ("args", string.Join(", ", args))));
return;
}
else
{
_entityManager.RemoveComponentDeferred<ShowHealthBarsComponent>(playerEntity.Value);
shell.WriteLine(LocalizationManager.GetString($"cmd-{Command}-notify-disabled"));
}
return;
}
}