Improve hurt command feedback and usability (#2559)
* Improve hurt command feedback and usability * Move hurt command to its own separate class away from body commands * NuLlAbLe * NuLlAbLe part 2 * Change hurt command to use a string builder * Char overload * Give back the number of arguments when unexpected * RemieMoment
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
@@ -246,90 +247,4 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
shell.SendText(player, $"No mechanism was found with name {mechanismName}.");
|
||||
}
|
||||
}
|
||||
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
class HurtCommand : IClientCommand
|
||||
{
|
||||
public string Command => "hurt";
|
||||
public string Description => "Ouch";
|
||||
public string Help => $"Usage: {Command} <type> <amount> (<entity uid/_>) (<ignoreResistance>)";
|
||||
|
||||
private void SendDamageTypes(IConsoleShell shell, IPlayerSession? player)
|
||||
{
|
||||
var msg = "";
|
||||
foreach (var dClass in Enum.GetNames(typeof(DamageClass)))
|
||||
{
|
||||
msg += $"\n{dClass}";
|
||||
var types = Enum.Parse<DamageClass>(dClass).ToTypes();
|
||||
foreach (var dType in types)
|
||||
{
|
||||
msg += $"\n - {dType}";
|
||||
}
|
||||
}
|
||||
shell.SendText(player, $"Damage Types:{msg}");
|
||||
}
|
||||
|
||||
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
// Check if we have enough for the dmg types to show
|
||||
if (args.Length > 0 && args[0] == "?")
|
||||
{
|
||||
SendDamageTypes(shell, player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Not enough args
|
||||
if (args.Length < 2)
|
||||
{
|
||||
shell.SendText(player, Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var ignoreResistance = false;
|
||||
var entityUid = player != null && player.AttachedEntityUid.HasValue ? player.AttachedEntityUid.Value : EntityUid.Invalid;
|
||||
if (!int.TryParse(args[1], out var amount) ||
|
||||
args.Length >= 3 && args[2] != "_" && !EntityUid.TryParse(args[2], out entityUid) ||
|
||||
args.Length >= 4 && !bool.TryParse(args[3], out ignoreResistance))
|
||||
{
|
||||
shell.SendText(player, Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entityUid == EntityUid.Invalid)
|
||||
{
|
||||
shell.SendText(player, "Not a valid entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetEntity(entityUid, out var ent))
|
||||
{
|
||||
shell.SendText(player, "Entity couldn't be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ent.TryGetComponent(out IDamageableComponent? damageable))
|
||||
{
|
||||
shell.SendText(player, "Entity can't be damaged.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Enum.TryParse<DamageClass>(args[0], true, out var dmgClass))
|
||||
{
|
||||
if (!damageable.ChangeDamage(dmgClass, amount, ignoreResistance))
|
||||
shell.SendText(player, "Something went wrong!");
|
||||
return;
|
||||
}
|
||||
// Fall back to DamageType
|
||||
else if (Enum.TryParse<DamageType>(args[0], true, out var dmgType))
|
||||
{
|
||||
if (!damageable.ChangeDamage(dmgType, amount, ignoreResistance))
|
||||
shell.SendText(player, "Something went wrong!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
SendDamageTypes(shell, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user