2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Server.Administration;
|
2023-08-28 16:53:24 -07:00
|
|
|
|
using Content.Server.Roles.Jobs;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Shared.Administration;
|
2023-08-30 21:46:11 -07:00
|
|
|
|
using Content.Shared.Players;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Shared.Roles;
|
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.Roles
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2022-09-14 17:02:38 -07:00
|
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2025-06-17 14:01:28 -04:00
|
|
|
|
public sealed class AddRoleCommand : LocalizedEntityCommands
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
[Dependency] private readonly JobSystem _jobSystem = default!;
|
2023-08-28 16:53:24 -07:00
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
public override string Command => "addrole";
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (args.Length != 2)
|
|
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"shell-wrong-arguments-number-need-specific",
|
|
|
|
|
|
("properAmount", 2),
|
|
|
|
|
|
("currentAmount", args.Length)));
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
if (!_playerManager.TryGetPlayerDataByUsername(args[0], out var data))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"cmd-addrole-mind-not-found"));
|
2021-03-16 15:50:20 +01:00
|
|
|
|
return;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
2021-03-16 15:50:20 +01:00
|
|
|
|
|
|
|
|
|
|
var mind = data.ContentData()?.Mind;
|
|
|
|
|
|
if (mind == null)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"cmd-addrole-mind-not-found"));
|
2021-03-16 15:50:20 +01:00
|
|
|
|
return;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
2021-03-16 15:50:20 +01:00
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
if (!_prototypeManager.TryIndex<JobPrototype>(args[1], out var jobPrototype))
|
2021-11-26 22:43:54 -08:00
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"cmd-addrole-role-not-found"));
|
2021-11-26 22:43:54 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
if (_jobSystem.MindHasJobWithId(mind, jobPrototype.Name))
|
2021-11-26 22:43:54 -08:00
|
|
|
|
{
|
2025-06-17 14:01:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"cmd-addrole-mind-already-has-role"));
|
2021-11-26 22:43:54 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 14:01:28 -04:00
|
|
|
|
_jobSystem.MindAddJob(mind.Value, args[1]);
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-16 15:50:20 +01:00
|
|
|
|
}
|