2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Server.Administration;
|
|
|
|
|
|
using Content.Server.Players;
|
|
|
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
|
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.IoC;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-11-26 22:43:54 -08:00
|
|
|
|
using System.Linq;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Roles
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
[AdminCommand(AdminFlags.Fun)]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class AddRoleCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
public string Command => "addrole";
|
|
|
|
|
|
|
|
|
|
|
|
public string Description => "Adds a role to a player's mind.";
|
|
|
|
|
|
|
2021-11-26 22:43:54 -08:00
|
|
|
|
public string Help => "addrole <session ID> <role>";
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
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>();
|
2021-03-16 15:50:20 +01:00
|
|
|
|
if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
|
shell.WriteLine("Can't find that mind");
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Can't find that mind");
|
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
|
|
|
|
|
2021-11-26 22:43:54 -08:00
|
|
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
|
|
|
|
|
if (!prototypeManager.TryIndex<JobPrototype>(args[1], out var jobPrototype))
|
|
|
|
|
|
{
|
|
|
|
|
|
shell.WriteLine("Can't find that role");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mind.AllRoles.Any(r => r.Name == jobPrototype.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
shell.WriteLine("Mind already has that role");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var role = new Job(mind, jobPrototype!);
|
2021-03-16 15:50:20 +01:00
|
|
|
|
mind.AddRole(role);
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-16 15:50:20 +01:00
|
|
|
|
}
|