ShowHealthBarsCommand to LEC. (#38588)
* mfw * Update Content.Client/Commands/ShowHealthBarsCommand.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -1,57 +1,46 @@
|
|||||||
using Content.Shared.Damage.Prototypes;
|
using Content.Shared.Damage.Prototypes;
|
||||||
using Content.Shared.Overlays;
|
using Content.Shared.Overlays;
|
||||||
using Robust.Client.Player;
|
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Content.Client.Commands;
|
namespace Content.Client.Commands;
|
||||||
|
|
||||||
public sealed class ShowHealthBarsCommand : LocalizedCommands
|
public sealed class ShowHealthBarsCommand : LocalizedEntityCommands
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
||||||
|
|
||||||
public override string Command => "showhealthbars";
|
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)
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
var player = _playerManager.LocalSession;
|
var player = shell.Player;
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error-not-player"));
|
shell.WriteError(Loc.GetString("shell-only-players-can-run-this-command"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerEntity = player?.AttachedEntity;
|
if (player.AttachedEntity is not { } playerEntity)
|
||||||
if (!playerEntity.HasValue)
|
|
||||||
{
|
{
|
||||||
shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error-no-entity"));
|
shell.WriteError(Loc.GetString("shell-must-be-attached-to-entity"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_entityManager.HasComponent<ShowHealthBarsComponent>(playerEntity))
|
if (!EntityManager.HasComponent<ShowHealthBarsComponent>(playerEntity))
|
||||||
{
|
{
|
||||||
var showHealthBarsComponent = new ShowHealthBarsComponent
|
var showHealthBarsComponent = new ShowHealthBarsComponent
|
||||||
{
|
{
|
||||||
DamageContainers = args.Select(arg => new ProtoId<DamageContainerPrototype>(arg)).ToList(),
|
DamageContainers = args.Select(arg => new ProtoId<DamageContainerPrototype>(arg)).ToList(),
|
||||||
HealthStatusIcon = null,
|
HealthStatusIcon = null,
|
||||||
NetSyncEnabled = false
|
NetSyncEnabled = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
_entityManager.AddComponent(playerEntity.Value, showHealthBarsComponent, true);
|
EntityManager.AddComponent(playerEntity, showHealthBarsComponent, true);
|
||||||
|
|
||||||
shell.WriteLine(LocalizationManager.GetString($"cmd-{Command}-notify-enabled", ("args", string.Join(", ", args))));
|
shell.WriteLine(Loc.GetString("cmd-showhealthbars-notify-enabled", ("args", string.Join(", ", args))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_entityManager.RemoveComponentDeferred<ShowHealthBarsComponent>(playerEntity.Value);
|
|
||||||
shell.WriteLine(LocalizationManager.GetString($"cmd-{Command}-notify-disabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
EntityManager.RemoveComponentDeferred<ShowHealthBarsComponent>(playerEntity);
|
||||||
|
shell.WriteLine(Loc.GetString("cmd-showhealthbars-notify-disabled"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
cmd-showhealthbars-desc = Toggles health bars above mobs.
|
cmd-showhealthbars-desc = Toggles health bars above mobs.
|
||||||
cmd-showhealthbars-help = Usage: {$command} [<DamageContainerId>]
|
cmd-showhealthbars-help = Usage: showhealthbars [<DamageContainerId>]
|
||||||
cmd-showhealthbars-error-not-player = You aren't a player.
|
|
||||||
cmd-showhealthbars-error-no-entity = You do not have an attached entity.
|
|
||||||
cmd-showhealthbars-notify-enabled = Enabled health overlay for DamageContainers: {$args}.
|
cmd-showhealthbars-notify-enabled = Enabled health overlay for DamageContainers: {$args}.
|
||||||
cmd-showhealthbars-notify-disabled = Disabled health overlay.
|
cmd-showhealthbars-notify-disabled = Disabled health overlay.
|
||||||
Reference in New Issue
Block a user