2021-07-17 02:37:09 +02:00
|
|
|
|
using Content.Server.Administration;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Shared.Administration;
|
2023-08-30 21:46:11 -07:00
|
|
|
|
using Content.Shared.Mind;
|
2023-09-16 07:18:10 +01:00
|
|
|
|
using Content.Shared.Objectives.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Objectives.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class AddObjectiveCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2023-06-18 11:33:19 -07:00
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
2023-08-28 16:53:24 -07:00
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
|
public string Command => "addobjective";
|
|
|
|
|
|
public string Description => "Adds an objective to the player's mind.";
|
|
|
|
|
|
public string Help => "addobjective <username> <objectiveID>";
|
2021-02-01 16:49:43 -08:00
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (args.Length != 2)
|
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Expected exactly 2 arguments.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var mgr = IoCManager.Resolve<IPlayerManager>();
|
2023-08-28 16:53:24 -07:00
|
|
|
|
if (!mgr.TryGetSessionByUsername(args[0], out var data))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Can't find the playerdata.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-30 21:46:11 -07:00
|
|
|
|
var minds = _entityManager.System<SharedMindSystem>();
|
2023-08-28 16:53:24 -07:00
|
|
|
|
if (!minds.TryGetMind(data, out var mindId, out var mind))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Can't find the mind.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!IoCManager.Resolve<IPrototypeManager>()
|
2023-09-16 07:18:10 +01:00
|
|
|
|
.TryIndex<EntityPrototype>(args[1], out var proto) ||
|
|
|
|
|
|
!proto.TryGetComponent<ObjectiveComponent>(out _))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2023-09-16 07:18:10 +01:00
|
|
|
|
shell.WriteLine($"Can't find matching objective prototype {args[1]}");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-16 07:18:10 +01:00
|
|
|
|
if (!minds.TryAddObjective(mindId, mind, args[1]))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2023-09-16 07:18:10 +01:00
|
|
|
|
// can fail for other reasons so dont pretend to be right
|
|
|
|
|
|
shell.WriteLine("Failed to add the objective. Maybe requirements dont allow that objective to be added.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|