2023-06-18 11:33:19 -07:00
|
|
|
using Content.Server.Mind;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Mind.Components;
|
2021-02-02 11:21:16 +00:00
|
|
|
using Content.Server.Players;
|
|
|
|
|
using Content.Shared.Administration;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-02 13:41:21 +01:00
|
|
|
using Robust.Shared.Console;
|
2021-02-02 11:21:16 +00:00
|
|
|
|
|
|
|
|
namespace Content.Server.Administration.Commands
|
|
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class SetMindCommand : IConsoleCommand
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2023-08-07 19:18:39 +12:00
|
|
|
|
2021-02-02 11:21:16 +00:00
|
|
|
public string Command => "setmind";
|
|
|
|
|
|
2023-06-18 11:33:19 -07:00
|
|
|
public string Description => Loc.GetString("set-mind-command-description", ("requiredComponent", nameof(MindContainerComponent)));
|
2021-02-02 11:21:16 +00:00
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
public string Help => Loc.GetString("set-mind-command-help-text", ("command", Command));
|
2021-02-02 11:21:16 +00:00
|
|
|
|
2021-02-02 13:41:21 +01:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2023-08-07 19:18:39 +12:00
|
|
|
if (args.Length < 2)
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-wrong-arguments-number"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(args[0], out var entityUid))
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 19:18:39 +12:00
|
|
|
bool ghostOverride = true;
|
|
|
|
|
if (args.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
ghostOverride = bool.Parse(args[2]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 11:21:16 +00:00
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
var eUid = new EntityUid(entityUid);
|
|
|
|
|
|
|
|
|
|
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 11:33:19 -07:00
|
|
|
if (!entityManager.HasComponent<MindContainerComponent>(eUid))
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-mind-message"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[1], out var session))
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hm, does player have a mind? if not we may need to give them one
|
|
|
|
|
var playerCData = session.ContentData();
|
|
|
|
|
if (playerCData == null)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-content-data-message"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 11:33:19 -07:00
|
|
|
var mindSystem = entityManager.System<MindSystem>();
|
2023-08-07 19:18:39 +12:00
|
|
|
|
2021-02-02 11:21:16 +00:00
|
|
|
var mind = playerCData.Mind;
|
|
|
|
|
if (mind == null)
|
|
|
|
|
{
|
2023-06-18 11:33:19 -07:00
|
|
|
mind = mindSystem.CreateMind(session.UserId);
|
|
|
|
|
mind.CharacterName = entityManager.GetComponent<MetaDataComponent>(eUid).EntityName;
|
2021-02-02 11:21:16 +00:00
|
|
|
}
|
2023-06-18 11:33:19 -07:00
|
|
|
|
2023-08-07 19:18:39 +12:00
|
|
|
mindSystem.TransferTo(mind, eUid, ghostOverride);
|
2021-02-02 11:21:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|