using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Mind;
+using Content.Shared.Objectives.Systems;
using Robust.Server.Player;
using Robust.Shared.Console;
namespace Content.Server.Objectives.Commands
{
[AdminCommand(AdminFlags.Admin)]
- public sealed class RemoveObjectiveCommand : IConsoleCommand
+ public sealed class RemoveObjectiveCommand : LocalizedEntityCommands
{
- [Dependency] private readonly IEntityManager _entityManager = default!;
+ [Dependency] private readonly IPlayerManager _players = default!;
+ [Dependency] private readonly SharedMindSystem _mind = default!;
+ [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
- public string Command => "rmobjective";
- public string Description => "Removes an objective from the player's mind.";
- public string Help => "rmobjective <username> <index>";
- public void Execute(IConsoleShell shell, string argStr, string[] args)
+ public override string Command => "rmobjective";
+ public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
- shell.WriteLine("Expected exactly 2 arguments.");
+ shell.WriteError(Loc.GetString(Loc.GetString("cmd-rmobjective-invalid-args")));
return;
}
- var mgr = IoCManager.Resolve<IPlayerManager>();
- var minds = _entityManager.System<SharedMindSystem>();
- if (!mgr.TryGetSessionByUsername(args[0], out var session))
+ if (!_players.TryGetSessionByUsername(args[0], out var session))
{
- shell.WriteLine("Can't find the playerdata.");
+ shell.WriteError(Loc.GetString("cmd-rmojective-player-not-found"));
return;
}
- if (!minds.TryGetMind(session, out var mindId, out var mind))
+ if (!_mind.TryGetMind(session, out var mindId, out var mind))
{
- shell.WriteLine("Can't find the mind.");
+ shell.WriteError(Loc.GetString("cmd-rmojective-mind-not-found"));
return;
}
if (int.TryParse(args[1], out var i))
{
- var mindSystem = _entityManager.System<SharedMindSystem>();
- shell.WriteLine(mindSystem.TryRemoveObjective(mindId, mind, i)
- ? "Objective successfully removed!"
- : "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
+ shell.WriteLine(Loc.GetString(_mind.TryRemoveObjective(mindId, mind, i)
+ ? "cmd-rmobjective-success"
+ : "cmd-rmobjective-failed"));
}
else
{
- shell.WriteLine($"Invalid index {args[1]}!");
+ shell.WriteError(Loc.GetString("cmd-rmobjective-invalid-index", ("index", args[1])));
}
}
+
+ public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+ {
+ if (args.Length == 1)
+ {
+ return CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), LocalizationManager.GetString("shell-argument-username-hint"));
+ }
+ if (args.Length == 2)
+ {
+ if (!_players.TryGetSessionByUsername(args[0], out var session))
+ return CompletionResult.Empty;
+
+ if (!_mind.TryGetMind(session, out var mindId, out var mind))
+ return CompletionResult.Empty;
+
+ if (mind.Objectives.Count == 0)
+ return CompletionResult.Empty;
+
+ var options = new List<CompletionOption>();
+ for (int i = 0; i < mind.Objectives.Count; i++)
+ {
+ var info = _objectives.GetInfo(mind.Objectives[i], mindId, mind);
+ var hint = info == null ? Loc.GetString("cmd-rmobjective-invalid-objective-info") : $"{mind.Objectives[i]} ({info.Value.Title})";
+ options.Add(new CompletionOption(i.ToString(), hint));
+ }
+
+ return CompletionResult.FromOptions(options);
+ }
+
+ return CompletionResult.Empty;
+ }
}
}