Add bluespace lockers (#12954)

* add bluespace lockers

* add command linkbluespacelocker

* add command clearbluespacelockerlinks

* fix unwelding method

* move bluespace locker functionality to own component

* add options to disable transporting certain things

* remove unused imports

* unlock target lockers when opening + minor optimization to unwelding
This commit is contained in:
Chief-Engineer
2022-12-19 21:47:37 -06:00
committed by GitHub
parent 9a7654791a
commit 067932712a
7 changed files with 247 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
using Content.Server.Storage.Components;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Admin)]
public sealed class ClearBluespaceLockerLinks : IConsoleCommand
{
public string Command => "clearbluespacelockerlinks";
public string Description => "Removes the bluespace links of the given uid. Does not remove links this uid is the target of.";
public string Help => "Usage: clearbluespacelockerlinks <storage uid>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var entityUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (entityManager.TryGetComponent<EntityStorageComponent>(entityUid, out var originComponent))
entityManager.RemoveComponent(entityUid, originComponent);
}
}

View File

@@ -0,0 +1,62 @@
using Content.Server.Storage.Components;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Admin)]
public sealed class LinkBluespaceLocker : IConsoleCommand
{
public string Command => "linkbluespacelocker";
public string Description => "Links an entity, the target, to another as a bluespace locker target.";
public string Help => "Usage: linkbluespacelocker <two-way link> <origin storage uid> <target storage uid>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 3)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!Boolean.TryParse(args[0], out var bidirectional))
{
shell.WriteError(Loc.GetString("shell-invalid-bool"));
return;
}
if (!EntityUid.TryParse(args[1], out var originUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!EntityUid.TryParse(args[2], out var targetUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetComponent<EntityStorageComponent>(originUid, out var originComponent))
{
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", originUid), ("componentName", nameof(EntityStorageComponent))));
return;
}
if (!entityManager.TryGetComponent<EntityStorageComponent>(targetUid, out var targetComponent))
{
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", targetUid), ("componentName", nameof(EntityStorageComponent))));
return;
}
entityManager.EnsureComponent<BluespaceLockerComponent>(originUid, out var originBluespaceComponent);
originBluespaceComponent.BluespaceLinks.Add(targetComponent);
if (bidirectional)
{
entityManager.EnsureComponent<BluespaceLockerComponent>(targetUid, out var targetBluespaceComponent);
targetBluespaceComponent.BluespaceLinks.Add(originComponent);
}
}
}