Add prevent suicide to minds and add tag control commands (#13307)
This commit is contained in:
113
Content.Server/Administration/Commands/TagCommands.cs
Normal file
113
Content.Server/Administration/Commands/TagCommands.cs
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Tag;
|
||||||
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
|
namespace Content.Server.Administration.Commands
|
||||||
|
{
|
||||||
|
[AdminCommand(AdminFlags.Debug)]
|
||||||
|
public sealed class AddTagCommand : LocalizedCommands
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
|
||||||
|
public override string Command => "addtag";
|
||||||
|
public override string Description => Loc.GetString("addtag-command-description");
|
||||||
|
public override string Help => Loc.GetString("addtag-command-help");
|
||||||
|
|
||||||
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length != 2)
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EntityUid.TryParse(args[0], out var entityUid))
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
|
||||||
|
return;
|
||||||
|
_entityManager.EnsureComponent<TagComponent>(entityUid);
|
||||||
|
|
||||||
|
if (tagSystem.TryAddTag(entityUid, args[1]))
|
||||||
|
{
|
||||||
|
shell.WriteLine(Loc.GetString("addtag-command-success", ("tag", args[1]), ("target", entityUid)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("addtag-command-fail", ("tag", args[1]), ("target", entityUid)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Length == 2)
|
||||||
|
{
|
||||||
|
return CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs<TagPrototype>(),
|
||||||
|
Loc.GetString("tag-command-arg-tag"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return CompletionResult.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AdminCommand(AdminFlags.Debug)]
|
||||||
|
public sealed class RemoveTagCommand : LocalizedCommands
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
|
||||||
|
public override string Command => "removetag";
|
||||||
|
public override string Description => Loc.GetString("removetag-command-description");
|
||||||
|
public override string Help => Loc.GetString("removetag-command-help");
|
||||||
|
|
||||||
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length != 2)
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EntityUid.TryParse(args[0], out var entityUid))
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tagSystem.RemoveTag(entityUid, args[1]))
|
||||||
|
{
|
||||||
|
shell.WriteLine(Loc.GetString("removetag-command-success", ("tag", args[1]), ("target", entityUid)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell.WriteError(Loc.GetString("removetag-command-fail", ("tag", args[1]), ("target", entityUid)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Length == 2&& EntityUid.TryParse(args[0], out var entityUid) && _entityManager.TryGetComponent(entityUid, out TagComponent? tagComponent))
|
||||||
|
{
|
||||||
|
return CompletionResult.FromHintOptions(tagComponent.Tags,
|
||||||
|
Loc.GetString("tag-command-arg-tag"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return CompletionResult.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,6 +122,13 @@ namespace Content.Server.Mind
|
|||||||
[DataField("preventGhosting")]
|
[DataField("preventGhosting")]
|
||||||
public bool PreventGhosting { get; set; }
|
public bool PreventGhosting { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevents user from suiciding
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("preventSuicide")]
|
||||||
|
public bool PreventSuicide { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The session of the player owning this mind.
|
/// The session of the player owning this mind.
|
||||||
/// Can be null, in which case the player is currently not logged in.
|
/// Can be null, in which case the player is currently not logged in.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Server.Mind.Components;
|
|||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Mobs.Components;
|
||||||
using Content.Shared.Mobs.Systems;
|
using Content.Shared.Mobs.Systems;
|
||||||
|
using Content.Shared.Interaction.Events;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ public sealed class MindSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<MindComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<MindComponent, ComponentShutdown>(OnShutdown);
|
||||||
SubscribeLocalEvent<MindComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<MindComponent, ExaminedEvent>(OnExamined);
|
||||||
|
SubscribeLocalEvent<MindComponent, SuicideEvent>(OnSuicide);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetGhostOnShutdown(EntityUid uid, bool value, MindComponent? mind = null)
|
public void SetGhostOnShutdown(EntityUid uid, bool value, MindComponent? mind = null)
|
||||||
@@ -157,4 +159,15 @@ public sealed class MindSystem : EntitySystem
|
|||||||
args.PushMarkup($"[color=yellow]{Loc.GetString("comp-mind-examined-ssd", ("ent", uid))}[/color]");
|
args.PushMarkup($"[color=yellow]{Loc.GetString("comp-mind-examined-ssd", ("ent", uid))}[/color]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSuicide(EntityUid uid, MindComponent component, SuicideEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (component.HasMind && component.Mind!.PreventSuicide)
|
||||||
|
{
|
||||||
|
args.BlockSuicideAttempt(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
addtag-command-description = Adds a tag to a given entity
|
||||||
|
addtag-command-help = Usage: addtag <entity uid> <tag>
|
||||||
|
|
||||||
|
addtag-command-success = Added {$tag} to {$target}.
|
||||||
|
addtag-command-fail = Could not add {$tag} to {$target}.
|
||||||
|
|
||||||
|
removetag-command-description = Removes a tag from a given entity
|
||||||
|
removetag-command-help = Usage: removetag <entity uid> <tag>
|
||||||
|
|
||||||
|
removetag-command-success = Removed {$tag} from {$target}.
|
||||||
|
removetag-command-fail = Could not remove {$tag} from {$target}.
|
||||||
|
|
||||||
|
tag-command-arg-tag = Tag
|
||||||
@@ -19,6 +19,8 @@ shell-argument-must-be-boolean = Argument must be a boolean.
|
|||||||
shell-wrong-arguments-number = Wrong number of arguments.
|
shell-wrong-arguments-number = Wrong number of arguments.
|
||||||
shell-need-between-arguments = Need {$lower} to {$upper} arguments!
|
shell-need-between-arguments = Need {$lower} to {$upper} arguments!
|
||||||
|
|
||||||
|
shell-argument-uid = EntityUid
|
||||||
|
|
||||||
## Guards
|
## Guards
|
||||||
|
|
||||||
shell-entity-is-not-mob = Target entity is not a mob!
|
shell-entity-is-not-mob = Target entity is not a mob!
|
||||||
|
|||||||
Reference in New Issue
Block a user