]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add prevent suicide to minds and add tag control commands (#13307)
authorChief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
Fri, 17 Feb 2023 00:36:10 +0000 (18:36 -0600)
committerGitHub <noreply@github.com>
Fri, 17 Feb 2023 00:36:10 +0000 (01:36 +0100)
Content.Server/Administration/Commands/TagCommands.cs [new file with mode: 0644]
Content.Server/Mind/Mind.cs
Content.Server/Mind/MindSystem.cs
Resources/Locale/en-US/administration/commands/tag-commands.ftl [new file with mode: 0644]
Resources/Locale/en-US/shell.ftl

diff --git a/Content.Server/Administration/Commands/TagCommands.cs b/Content.Server/Administration/Commands/TagCommands.cs
new file mode 100644 (file)
index 0000000..790768b
--- /dev/null
@@ -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;
+        }
+    }
+}
index ffdafe6d69a701022a491c6494b40cb26ca34d0a..c022300b89123290bfcecc294eed49cf70921874 100644 (file)
@@ -122,6 +122,13 @@ namespace Content.Server.Mind
         [DataField("preventGhosting")]
         public bool PreventGhosting { get; set; }
 
+        /// <summary>
+        ///     Prevents user from suiciding
+        /// </summary>
+        [ViewVariables(VVAccess.ReadWrite)]
+        [DataField("preventSuicide")]
+        public bool PreventSuicide { get; set; }
+
         /// <summary>
         ///     The session of the player owning this mind.
         ///     Can be null, in which case the player is currently not logged in.
index 549f85e1088bf58a8b07ecb11e06d6ed7594a336..f9101234ced325eb16cdfcb8e406504328df8cb4 100644 (file)
@@ -5,6 +5,7 @@ using Content.Server.Mind.Components;
 using Content.Shared.Examine;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Mobs.Systems;
+using Content.Shared.Interaction.Events;
 using Robust.Shared.Map;
 using Robust.Shared.Timing;
 
@@ -23,6 +24,7 @@ public sealed class MindSystem : EntitySystem
 
         SubscribeLocalEvent<MindComponent, ComponentShutdown>(OnShutdown);
         SubscribeLocalEvent<MindComponent, ExaminedEvent>(OnExamined);
+        SubscribeLocalEvent<MindComponent, SuicideEvent>(OnSuicide);
     }
 
     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]");
         }
     }
+
+    private void OnSuicide(EntityUid uid, MindComponent component, SuicideEvent args)
+    {
+        if (args.Handled)
+            return;
+
+        if (component.HasMind && component.Mind!.PreventSuicide)
+        {
+            args.BlockSuicideAttempt(true);
+        }
+    }
 }
diff --git a/Resources/Locale/en-US/administration/commands/tag-commands.ftl b/Resources/Locale/en-US/administration/commands/tag-commands.ftl
new file mode 100644 (file)
index 0000000..898b6f0
--- /dev/null
@@ -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
index bb91ffb18ebe1fe768a81823c9c4fa292b79182f..aa76563d54a2a46edfb744230763efc733d0ae38 100644 (file)
@@ -19,6 +19,8 @@ shell-argument-must-be-boolean = Argument must be a boolean.
 shell-wrong-arguments-number = Wrong number of arguments.
 shell-need-between-arguments = Need {$lower} to {$upper} arguments!
 
+shell-argument-uid = EntityUid
+
 ## Guards
 
 shell-entity-is-not-mob = Target entity is not a mob!