diff --git a/Content.Server/Xenoarchaeology/Artifact/UnlockNodeCommand.cs b/Content.Server/Xenoarchaeology/Artifact/UnlockNodeCommand.cs new file mode 100644 index 0000000000..ea86186782 --- /dev/null +++ b/Content.Server/Xenoarchaeology/Artifact/UnlockNodeCommand.cs @@ -0,0 +1,68 @@ +using Content.Server.Administration; +using Content.Shared.Administration; +using Content.Shared.Xenoarchaeology.Artifact.Components; +using Robust.Shared.Console; + +namespace Content.Server.Xenoarchaeology.Artifact; + +/// Command for unlocking a specific node of a xeno artifact. +[AdminCommand(AdminFlags.Debug)] +public sealed class UnlockNodeCommand : LocalizedEntityCommands +{ + [Dependency] private readonly XenoArtifactSystem _artiSystem = default!; + + public override string Command => "unlocknode"; + + public override void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 2) + { + shell.WriteError(Loc.GetString("shell-wrong-arguments-number")); + return; + } + + if (!NetEntity.TryParse(args[1], out var netNode) || !EntityManager.TryGetEntity(netNode, out var entityUid)) + { + shell.WriteError(Loc.GetString("shell-could-not-find-entity-with-uid", ("uid", args[1]))); + return; + } + + _artiSystem.SetNodeUnlocked(entityUid.Value); + } + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + switch (args.Length) + { + case 1: + { + var query = EntityManager.EntityQueryEnumerator(); + var completionOptions = new List(); + while (query.MoveNext(out var uid, out _)) + { + completionOptions.Add(new CompletionOption(uid.ToString())); + } + + return CompletionResult.FromHintOptions(completionOptions, Loc.GetString("cmd-unlocknode-artifact-hint")); + } + case 2 when + NetEntity.TryParse(args[0], out var netEnt) && + EntityManager.TryGetEntity(netEnt, out var artifactUid) && + EntityManager.TryGetComponent(artifactUid, out var comp): + { + var result = new List(); + foreach (var node in _artiSystem.GetAllNodes((artifactUid.Value, comp))) + { + var metaData = EntityManager.MetaQuery.Comp(artifactUid.Value); + var entityUidStr = EntityManager.GetNetEntity(node).ToString(); + var completionOption = new CompletionOption(entityUidStr, metaData.EntityName); + result.Add(completionOption); + } + + return CompletionResult.FromHintOptions(result, Loc.GetString("cmd-unlocknode-node-hint")); + } + default: + return CompletionResult.Empty; + } + } +} diff --git a/Content.Server/Xenoarchaeology/Artifact/XenoArtifactUnlockNodeCommand.cs b/Content.Server/Xenoarchaeology/Artifact/XenoArtifactUnlockNodeCommand.cs deleted file mode 100644 index 1782619780..0000000000 --- a/Content.Server/Xenoarchaeology/Artifact/XenoArtifactUnlockNodeCommand.cs +++ /dev/null @@ -1,84 +0,0 @@ -using Content.Server.Administration; -using Content.Shared.Administration; -using Content.Shared.Xenoarchaeology.Artifact.Components; -using Robust.Shared.Console; - -namespace Content.Server.Xenoarchaeology.Artifact; - -/// Command for unlocking specific node of xeno artifact. -[AdminCommand(AdminFlags.Debug)] -public sealed class XenoArtifactUnlockNodeCommand : LocalizedCommands -{ - [Dependency] private readonly EntityManager _entities = default!; - - /// - public override string Command => "unlocknode"; - - /// - public override string Description => Loc.GetString("cmd-unlocknode-desc"); - - /// - public override string Help => Loc.GetString("cmd-unlocknode-help"); - - /// - public override void Execute(IConsoleShell shell, string argStr, string[] args) - { - if (args.Length != 2) - { - shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-arg-num")); - return; - } - - if (!NetEntity.TryParse(args[1], out var netNode)) - { - shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-invalid-entity")); - return; - } - - if (!_entities.TryGetEntity(netNode, out var entityUid)) - { - shell.WriteError(Loc.GetString("cmd-parse-failure-unlocknode-invalid-entity")); - return; - } - _entities.System() - .SetNodeUnlocked(entityUid.Value); - } - - /// - public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) - { - if (args.Length == 1) - { - var query = _entities.EntityQueryEnumerator(); - var completionOptions = new List(); - while (query.MoveNext(out var uid, out _)) - { - completionOptions.Add(new CompletionOption(uid.ToString())); - } - - return CompletionResult.FromHintOptions(completionOptions, ""); - } - - if (args.Length == 2 && - NetEntity.TryParse(args[0], out var netEnt) && - _entities.TryGetEntity(netEnt, out var artifactUid) && - _entities.TryGetComponent(artifactUid, out var comp)) - { - var artifactSystem = _entities.System(); - - var result = new List(); - foreach (var node in artifactSystem.GetAllNodes((artifactUid.Value, comp))) - { - var metaData = _entities.MetaQuery.Comp(artifactUid.Value); - var entityUidStr = _entities.GetNetEntity(node) - .ToString(); - var completionOption = new CompletionOption(entityUidStr, metaData.EntityName); - result.Add(completionOption); - } - - return CompletionResult.FromHintOptions(result, ""); - } - - return CompletionResult.Empty; - } -} diff --git a/Resources/Locale/en-US/commands/unlocknode-command.ftl b/Resources/Locale/en-US/commands/unlocknode-command.ftl new file mode 100644 index 0000000000..5a3b8259dd --- /dev/null +++ b/Resources/Locale/en-US/commands/unlocknode-command.ftl @@ -0,0 +1,4 @@ +cmd-unlocknode-desc = Unlocks a node on a given artifact +cmd-unlocknode-help = unlocknode +cmd-unlocknode-artifact-hint = +cmd-unlocknode-node-hint = diff --git a/Resources/Locale/en-US/xenoarchaeology/artifact-component.ftl b/Resources/Locale/en-US/xenoarchaeology/artifact-component.ftl index 50fa136928..90029b282c 100644 --- a/Resources/Locale/en-US/xenoarchaeology/artifact-component.ftl +++ b/Resources/Locale/en-US/xenoarchaeology/artifact-component.ftl @@ -1,10 +1,4 @@ -### Commands -cmd-unlocknode-desc = Unlocks a node on a given artifact -cmd-unlocknode-help = unlocknode -cmd-parse-failure-unlocknode-arg-num = Incorrect number of args -cmd-parse-failure-unlocknode-invalid-entity = Provided netEntity is not valid node - -### Verbs +### Verbs artifact-verb-make-always-active = Make artifact always active artifact-verb-activate = Activate artifact