From a27c1d9bd92c8ba7453c8deea1b4f4c9bb6acdd5 Mon Sep 17 00:00:00 2001 From: moonheart08 Date: Mon, 1 Nov 2021 23:32:58 -0500 Subject: [PATCH] funny container commands (#5113) --- .../Commands/AddBodyPartCommand.cs | 60 +++++++++++++++++++ .../Commands/AddEntityStorageCommand.cs | 51 ++++++++++++++++ .../Commands/AddMechanismCommand.cs | 60 +++++++++++++++++++ .../Commands/RemoveBodyPartCommand.cs | 50 ++++++++++++++++ .../Commands/RemoveEntityStorageCommand.cs | 49 +++++++++++++++ .../Commands/RemoveMechanismCommand.cs | 50 ++++++++++++++++ 6 files changed, 320 insertions(+) create mode 100644 Content.Server/Administration/Commands/AddBodyPartCommand.cs create mode 100644 Content.Server/Administration/Commands/AddEntityStorageCommand.cs create mode 100644 Content.Server/Administration/Commands/AddMechanismCommand.cs create mode 100644 Content.Server/Administration/Commands/RemoveBodyPartCommand.cs create mode 100644 Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs create mode 100644 Content.Server/Administration/Commands/RemoveMechanismCommand.cs diff --git a/Content.Server/Administration/Commands/AddBodyPartCommand.cs b/Content.Server/Administration/Commands/AddBodyPartCommand.cs new file mode 100644 index 0000000000..ecf4a41594 --- /dev/null +++ b/Content.Server/Administration/Commands/AddBodyPartCommand.cs @@ -0,0 +1,60 @@ +using Content.Server.Body; +using Content.Server.Body.Mechanism; +using Content.Server.Body.Part; +using Content.Server.Storage.Components; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class AddBodyPartCommand : IConsoleCommand + { + public string Command => "addbodypart"; + public string Description => "Adds a given entity to a containing body."; + public string Help => "Usage: addbodypart "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 3) + { + 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; + } + + if (!EntityUid.TryParse(args[1], out var storageUid)) + { + shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); + return; + } + + var entityManager = IoCManager.Resolve(); + + if (entityManager.TryGetComponent(storageUid, out var storage) + && entityManager.TryGetComponent(entityUid, out var bodyPart)) + { + if (storage.TryAddPart(args[3], bodyPart)) + { + shell.WriteLine($@"Added {entityUid} to {storageUid}."); + } + else + { + shell.WriteError($@"Could not add {entityUid} to {storageUid}."); + } + } + else + { + shell.WriteError("Could not insert."); + } + } + } +} diff --git a/Content.Server/Administration/Commands/AddEntityStorageCommand.cs b/Content.Server/Administration/Commands/AddEntityStorageCommand.cs new file mode 100644 index 0000000000..8a4cd999eb --- /dev/null +++ b/Content.Server/Administration/Commands/AddEntityStorageCommand.cs @@ -0,0 +1,51 @@ +using Content.Server.Body.Mechanism; +using Content.Server.Body.Part; +using Content.Server.Storage.Components; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class AddEntityStorageCommand : IConsoleCommand + { + public string Command => "addstorage"; + public string Description => "Adds a given entity to a containing storage."; + public string Help => "Usage: addstorage "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 2) + { + 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; + } + + if (!EntityUid.TryParse(args[1], out var storageUid)) + { + shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); + return; + } + + var entityManager = IoCManager.Resolve(); + + if (entityManager.TryGetComponent(storageUid, out var storage)) + { + storage.Insert(entityManager.GetEntity(entityUid)); + } + else + { + shell.WriteError("Could not insert into non-storage."); + } + } + } +} diff --git a/Content.Server/Administration/Commands/AddMechanismCommand.cs b/Content.Server/Administration/Commands/AddMechanismCommand.cs new file mode 100644 index 0000000000..de2154da0f --- /dev/null +++ b/Content.Server/Administration/Commands/AddMechanismCommand.cs @@ -0,0 +1,60 @@ +using Content.Server.Body; +using Content.Server.Body.Mechanism; +using Content.Server.Body.Part; +using Content.Server.Storage.Components; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class AddMechanismCommand : IConsoleCommand + { + public string Command => "addmechanism"; + public string Description => "Adds a given entity to a containing body."; + public string Help => "Usage: addmechanism "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 2) + { + 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; + } + + if (!EntityUid.TryParse(args[1], out var storageUid)) + { + shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number")); + return; + } + + var entityManager = IoCManager.Resolve(); + + if (entityManager.TryGetComponent(storageUid, out var storage) + && entityManager.TryGetComponent(entityUid, out var bodyPart)) + { + if (storage.TryAddMechanism(bodyPart)) + { + shell.WriteLine($@"Added {entityUid} to {storageUid}."); + } + else + { + shell.WriteError($@"Could not add {entityUid} to {storageUid}."); + } + } + else + { + shell.WriteError("Could not insert."); + } + } + } +} diff --git a/Content.Server/Administration/Commands/RemoveBodyPartCommand.cs b/Content.Server/Administration/Commands/RemoveBodyPartCommand.cs new file mode 100644 index 0000000000..e6c7cbb38a --- /dev/null +++ b/Content.Server/Administration/Commands/RemoveBodyPartCommand.cs @@ -0,0 +1,50 @@ +using Content.Server.Body; +using Content.Server.Body.Part; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class RemoveBodyPartCommand : IConsoleCommand + { + public string Command => "rmbodypart"; + public string Description => "Removes a given entity from it's containing body, if any."; + public string Help => "Usage: rmbodypart "; + + 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(); + + if (!entityManager.TryGetComponent(entityUid, out var transform)) return; + + var parent = transform.ParentUid; + + if (entityManager.TryGetComponent(parent, out var body) && + entityManager.TryGetComponent(entityUid, out var part)) + { + body.RemovePart(part); + + } + else + { + shell.WriteError("Was not a body part, or did not have a parent."); + } + } + } +} diff --git a/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs b/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs new file mode 100644 index 0000000000..982d8e6087 --- /dev/null +++ b/Content.Server/Administration/Commands/RemoveEntityStorageCommand.cs @@ -0,0 +1,49 @@ +using Content.Server.Body.Mechanism; +using Content.Server.Body.Part; +using Content.Server.Storage.Components; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class RemoveEntityStorageCommand : IConsoleCommand + { + public string Command => "rmstorage"; + public string Description => "Removes a given entity from it's containing storage, if any."; + public string Help => "Usage: rmstorage "; + + 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(); + + if (!entityManager.TryGetComponent(entityUid, out var transform)) return; + + var parent = transform.ParentUid; + + if (entityManager.TryGetComponent(parent, out var storage)) + { + storage.Remove(entityManager.GetEntity(entityUid)); + } + else + { + shell.WriteError("Could not remove from storage."); + } + } + } +} diff --git a/Content.Server/Administration/Commands/RemoveMechanismCommand.cs b/Content.Server/Administration/Commands/RemoveMechanismCommand.cs new file mode 100644 index 0000000000..49c4f2bd8c --- /dev/null +++ b/Content.Server/Administration/Commands/RemoveMechanismCommand.cs @@ -0,0 +1,50 @@ +using Content.Server.Body; +using Content.Server.Body.Mechanism; +using Content.Server.Body.Part; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public class RemoveMechanismCommand : IConsoleCommand + { + public string Command => "rmmechanism"; + public string Description => "Removes a given entity from it's containing bodypart, if any."; + public string Help => "Usage: rmmechanism "; + + 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(); + + if (!entityManager.TryGetComponent(entityUid, out var transform)) return; + + var parent = transform.ParentUid; + + if (entityManager.TryGetComponent(parent, out var body) && + entityManager.TryGetComponent(entityUid, out var part)) + { + body.RemoveMechanism(part); + } + else + { + shell.WriteError("Was not a mechanism, or did not have a parent."); + } + } + } +}