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
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
public string Command => "setmind";
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
public string Description => Loc.GetString("set-mind-command-description", ("requiredComponent", nameof(MindComponent)));
|
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
|
|
|
{
|
|
|
|
|
if (args.Length != 2)
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (!entityManager.HasComponent<MindComponent>(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mind = playerCData.Mind;
|
|
|
|
|
if (mind == null)
|
|
|
|
|
{
|
2021-06-09 22:19:39 +02:00
|
|
|
mind = new Mind.Mind(session.UserId)
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
CharacterName = entityManager.GetComponent<MetaDataComponent>(eUid).EntityName
|
2021-02-02 11:21:16 +00:00
|
|
|
};
|
2021-11-15 18:14:34 +00:00
|
|
|
mind.ChangeOwningPlayer(session.UserId);
|
2021-02-02 11:21:16 +00:00
|
|
|
}
|
2021-12-05 18:09:01 +01:00
|
|
|
mind.TransferTo(eUid);
|
2021-02-02 11:21:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|