Fix the add role command (#5532)

This commit is contained in:
wrexbe
2021-11-26 22:43:54 -08:00
committed by GitHub
parent 1a39807ce5
commit a354741b4b

View File

@@ -6,19 +6,18 @@ using Robust.Server.Player;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Server.Roles namespace Content.Server.Roles
{ {
[AdminCommand(AdminFlags.Fun)] [AdminCommand(AdminFlags.Fun)]
public class AddRoleCommand : IConsoleCommand public class AddRoleCommand : IConsoleCommand
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public string Command => "addrole"; public string Command => "addrole";
public string Description => "Adds a role to a player's mind."; public string Description => "Adds a role to a player's mind.";
public string Help => "addrole <session ID> <Role Type>\nThat role type is the actual C# type name."; public string Help => "addrole <session ID> <role>";
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
@@ -42,7 +41,20 @@ namespace Content.Server.Roles
return; return;
} }
var role = new Job(mind, _prototypeManager.Index<JobPrototype>(args[1])); 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!);
mind.AddRole(role); mind.AddRole(role);
} }
} }