Re-organize all projects (#4166)
This commit is contained in:
28
Content.Server/Damage/Commands/AddDamageFlagCommand.cs
Normal file
28
Content.Server/Damage/Commands/AddDamageFlagCommand.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Damage.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class AddDamageFlagCommand : DamageFlagCommand
|
||||
{
|
||||
public override string Command => "adddamageflag";
|
||||
public override string Description => "Adds a damage flag to your entity or another.";
|
||||
public override string Help => $"Usage: {Command} <flag> / {Command} <entityUid> <flag>";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (!TryGetEntity(shell, player, args, true, out var entity, out var flag, out var damageable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
damageable.AddFlag(flag);
|
||||
shell.WriteLine($"Added damage flag {flag} to entity {entity.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Content.Server/Damage/Commands/DamageFlagCommand.cs
Normal file
116
Content.Server/Damage/Commands/DamageFlagCommand.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Damage.Commands
|
||||
{
|
||||
public abstract class DamageFlagCommand : IConsoleCommand
|
||||
{
|
||||
public abstract string Command { get; }
|
||||
public abstract string Description { get; }
|
||||
public abstract string Help { get; }
|
||||
|
||||
public abstract void Execute(IConsoleShell shell, string argStr, string[] args);
|
||||
|
||||
public bool TryGetEntity(
|
||||
IConsoleShell shell,
|
||||
IPlayerSession? player,
|
||||
string[] args,
|
||||
bool adding,
|
||||
[NotNullWhen(true)] out IEntity? entity,
|
||||
out DamageFlag flag,
|
||||
[NotNullWhen(true)] out IDamageableComponent? damageable)
|
||||
{
|
||||
entity = null;
|
||||
flag = DamageFlag.None;
|
||||
damageable = null;
|
||||
|
||||
IEntity? parsedEntity;
|
||||
DamageFlag parsedFlag;
|
||||
IDamageableComponent? parsedDamageable;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
shell.WriteLine("An entity needs to be specified when the command isn't used by a player.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.AttachedEntity == null)
|
||||
{
|
||||
shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(args[0], true, out parsedFlag))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid damage flag.");
|
||||
return false;
|
||||
}
|
||||
|
||||
parsedEntity = player.AttachedEntity;
|
||||
flag = parsedFlag;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (!EntityUid.TryParse(args[0], out var id))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} isn't a valid entity id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetEntity(id, out parsedEntity))
|
||||
{
|
||||
shell.WriteLine($"No entity found with id {id}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(args[1], true, out parsedFlag))
|
||||
{
|
||||
shell.WriteLine($"{args[1]} is not a valid damage flag.");
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parsedEntity.TryGetComponent(out parsedDamageable))
|
||||
{
|
||||
shell.WriteLine($"Entity {parsedEntity.Name} doesn't have a {nameof(IDamageableComponent)}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parsedDamageable.HasFlag(parsedFlag) && adding)
|
||||
{
|
||||
shell.WriteLine($"Entity {parsedEntity.Name} already has damage flag {parsedFlag}.");
|
||||
return false;
|
||||
}
|
||||
else if (!parsedDamageable.HasFlag(parsedFlag) && !adding)
|
||||
{
|
||||
shell.WriteLine($"Entity {parsedEntity.Name} doesn't have damage flag {parsedFlag}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
entity = parsedEntity;
|
||||
flag = parsedFlag;
|
||||
damageable = parsedDamageable;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Content.Server/Damage/Commands/GodModeCommand.cs
Normal file
69
Content.Server/Damage/Commands/GodModeCommand.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Damage.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class GodModeCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "godmode";
|
||||
public string Description => "Makes your entity or another invulnerable to almost anything. May have irreversible changes.";
|
||||
public string Help => $"Usage: {Command} / {Command} <entityUid>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
IEntity entity;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
if (player == null)
|
||||
{
|
||||
shell.WriteLine("An entity needs to be specified when the command isn't used by a player.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.AttachedEntity == null)
|
||||
{
|
||||
shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
entity = player.AttachedEntity;
|
||||
break;
|
||||
case 1:
|
||||
if (!EntityUid.TryParse(args[0], out var id))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} isn't a valid entity id.");
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entityManager.TryGetEntity(id, out var parsedEntity))
|
||||
{
|
||||
shell.WriteLine($"No entity found with id {id}.");
|
||||
return;
|
||||
}
|
||||
|
||||
entity = parsedEntity;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var godmodeSystem = EntitySystem.Get<GodmodeSystem>();
|
||||
var enabled = godmodeSystem.ToggleGodmode(entity);
|
||||
|
||||
shell.WriteLine(enabled
|
||||
? $"Enabled godmode for entity {entity.Name} with id {entity.Uid}"
|
||||
: $"Disabled godmode for entity {entity.Name} with id {entity.Uid}");
|
||||
}
|
||||
}
|
||||
}
|
||||
224
Content.Server/Damage/Commands/HurtCommand.cs
Normal file
224
Content.Server/Damage/Commands/HurtCommand.cs
Normal file
@@ -0,0 +1,224 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Damage.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
class HurtCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "hurt";
|
||||
public string Description => "Ouch";
|
||||
public string Help => $"Usage: {Command} <type/?> <amount> (<entity uid/_>) (<ignoreResistances>)";
|
||||
|
||||
private string DamageTypes()
|
||||
{
|
||||
var msg = new StringBuilder();
|
||||
foreach (var dClass in Enum.GetNames(typeof(DamageClass)))
|
||||
{
|
||||
msg.Append($"\n{dClass}");
|
||||
|
||||
var types = Enum.Parse<DamageClass>(dClass).ToTypes();
|
||||
|
||||
if (types.Count > 0)
|
||||
{
|
||||
msg.Append(": ");
|
||||
msg.AppendJoin('|', types);
|
||||
}
|
||||
}
|
||||
|
||||
return $"Damage Types:{msg}";
|
||||
}
|
||||
|
||||
private delegate void Damage(IDamageableComponent damageable, bool ignoreResistances);
|
||||
|
||||
private bool TryParseEntity(IConsoleShell shell, IPlayerSession? player, string arg,
|
||||
[NotNullWhen(true)] out IEntity? entity)
|
||||
{
|
||||
entity = null;
|
||||
|
||||
if (arg == "_")
|
||||
{
|
||||
var playerEntity = player?.AttachedEntity;
|
||||
|
||||
if (playerEntity == null)
|
||||
{
|
||||
shell.WriteLine($"You must have a player entity to use this command without specifying an entity.\n{Help}");
|
||||
return false;
|
||||
}
|
||||
|
||||
entity = playerEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EntityUid.TryParse(arg, out var entityUid))
|
||||
{
|
||||
shell.WriteLine($"{arg} is not a valid entity uid.\n{Help}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!entityManager.TryGetEntity(entityUid, out var parsedEntity))
|
||||
{
|
||||
shell.WriteLine($"No entity found with uid {entityUid}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
entity = parsedEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryParseDamageArgs(
|
||||
IConsoleShell shell,
|
||||
IPlayerSession? player,
|
||||
string[] args,
|
||||
[NotNullWhen(true)] out Damage? func)
|
||||
{
|
||||
if (!int.TryParse(args[1], out var amount))
|
||||
{
|
||||
shell.WriteLine($"{args[1]} is not a valid damage integer.");
|
||||
|
||||
func = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Enum.TryParse<DamageClass>(args[0], true, out var damageClass))
|
||||
{
|
||||
func = (damageable, ignoreResistances) =>
|
||||
{
|
||||
if (!damageable.DamageClasses.ContainsKey(damageClass))
|
||||
{
|
||||
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage class {damageClass}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!damageable.ChangeDamage(damageClass, amount, ignoreResistances))
|
||||
{
|
||||
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} received no damage.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Damaged entity {damageable.Owner.Name} with id {damageable.Owner.Uid} for {amount} {damageClass} damage{(ignoreResistances ? ", ignoring resistances." : ".")}");
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
// Fall back to DamageType
|
||||
else if (Enum.TryParse<DamageType>(args[0], true, out var damageType))
|
||||
{
|
||||
func = (damageable, ignoreResistances) =>
|
||||
{
|
||||
if (!damageable.DamageTypes.ContainsKey(damageType))
|
||||
{
|
||||
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} can not be damaged with damage class {damageType}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!damageable.ChangeDamage(damageType, amount, ignoreResistances))
|
||||
{
|
||||
shell.WriteLine($"Entity {damageable.Owner.Name} with id {damageable.Owner.Uid} received no damage.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Damaged entity {damageable.Owner.Name} with id {damageable.Owner.Uid} for {amount} {damageType} damage{(ignoreResistances ? ", ignoring resistances." : ".")}");
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid damage class or type.");
|
||||
|
||||
var types = DamageTypes();
|
||||
shell.WriteLine(types);
|
||||
|
||||
func = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
bool ignoreResistances;
|
||||
IEntity entity;
|
||||
Damage? damageFunc;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
// Check if we have enough for the dmg types to show
|
||||
case var n when n > 0 && (args[0] == "?" || args[0] == "¿"):
|
||||
var types = DamageTypes();
|
||||
|
||||
if (args[0] == "¿")
|
||||
{
|
||||
types = types.Replace('e', 'é');
|
||||
}
|
||||
|
||||
shell.WriteLine(types);
|
||||
|
||||
return;
|
||||
// Not enough args
|
||||
case var n when n < 2:
|
||||
shell.WriteLine($"Invalid number of arguments ({args.Length}).\n{Help}");
|
||||
return;
|
||||
case var n when n >= 2 && n <= 4:
|
||||
if (!TryParseDamageArgs(shell, player, args, out damageFunc))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var entityUid = n == 2 ? "_" : args[2];
|
||||
|
||||
if (!TryParseEntity(shell, player, entityUid, out var parsedEntity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
entity = parsedEntity;
|
||||
|
||||
if (n == 4)
|
||||
{
|
||||
if (!bool.TryParse(args[3], out ignoreResistances))
|
||||
{
|
||||
shell.WriteLine($"{args[3]} is not a valid boolean value for ignoreResistances.\n{Help}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ignoreResistances = false;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine($"Invalid amount of arguments ({args.Length}).\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out IDamageableComponent? damageable))
|
||||
{
|
||||
shell.WriteLine($"Entity {entity.Name} with id {entity.Uid} does not have a {nameof(IDamageableComponent)}.");
|
||||
return;
|
||||
}
|
||||
|
||||
damageFunc(damageable, ignoreResistances);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Server/Damage/Commands/RemoveDamageFlagCommand.cs
Normal file
28
Content.Server/Damage/Commands/RemoveDamageFlagCommand.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Damage.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class RemoveDamageFlagCommand : DamageFlagCommand
|
||||
{
|
||||
public override string Command => "removedamageflag";
|
||||
public override string Description => "Removes a damage flag from your entity or another.";
|
||||
public override string Help => $"Usage: {Command} <flag> / {Command} <entityUid> <flag>";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (!TryGetEntity(shell, player, args, false, out var entity, out var flag, out var damageable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
damageable.RemoveFlag(flag);
|
||||
shell.WriteLine($"Removed damage flag {flag} from entity {entity.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user