]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Clone toolshed commands (#41261)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Mon, 3 Nov 2025 13:05:56 +0000 (14:05 +0100)
committerGitHub <noreply@github.com>
Mon, 3 Nov 2025 13:05:56 +0000 (13:05 +0000)
* init

* fuck this file its such a mess why wont anyone sort this holy shit

* review

Content.Server/Cloning/CloningSystem.cs
Content.Server/Toolshed/Commands/Misc/CloneCommand.cs [new file with mode: 0644]
Content.Shared/Cloning/SharedCloningSystem.cs
Resources/Locale/en-US/commands/toolshed-commands.ftl

index 6e0f38ad51e9e16558368afc29dcf48d4962b539..40f8a36dfaf45b0f37e89f795b14d968966575f4 100644 (file)
@@ -84,6 +84,14 @@ public sealed partial class CloningSystem : SharedCloningSystem
         return true;
     }
 
+    public override void CloneComponents(EntityUid original, EntityUid clone, ProtoId<CloningSettingsPrototype> settings)
+    {
+        if (!_prototype.Resolve(settings, out var proto))
+            return;
+
+        CloneComponents(original, clone, proto);
+    }
+
     public override void CloneComponents(EntityUid original, EntityUid clone, CloningSettingsPrototype settings)
     {
         var componentsToCopy = settings.Components;
diff --git a/Content.Server/Toolshed/Commands/Misc/CloneCommand.cs b/Content.Server/Toolshed/Commands/Misc/CloneCommand.cs
new file mode 100644 (file)
index 0000000..d7434c4
--- /dev/null
@@ -0,0 +1,82 @@
+using Content.Server.Administration;
+using Content.Server.Humanoid;
+using Content.Shared.Administration;
+using Content.Shared.Cloning;
+using Content.Shared.Inventory;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Toolshed;
+
+namespace Content.Server.Cloning.Commands;
+
+[ToolshedCommand, AdminCommand(AdminFlags.Fun)]
+public sealed class CloneCommand : ToolshedCommand
+{
+    private HumanoidAppearanceSystem? _appearance;
+    private CloningSystem? _cloning;
+    private MetaDataSystem? _metadata;
+
+    [CommandImplementation("humanoidappearance")]
+    public IEnumerable<EntityUid> HumanoidAppearance([PipedArgument] IEnumerable<EntityUid> targets, EntityUid source, bool rename)
+    {
+        _appearance ??= GetSys<HumanoidAppearanceSystem>();
+        _metadata ??= GetSys<MetaDataSystem>();
+
+        foreach (var ent in targets)
+        {
+            _appearance.CloneAppearance(source, ent);
+
+            if (rename)
+                _metadata.SetEntityName(ent, MetaData(source).EntityName, raiseEvents: true);
+
+            yield return ent;
+        }
+    }
+
+    [CommandImplementation("comps")]
+    public IEnumerable<EntityUid> Comps([PipedArgument] IEnumerable<EntityUid> targets, EntityUid source, ProtoId<CloningSettingsPrototype> settings)
+    {
+        _cloning ??= GetSys<CloningSystem>();
+
+        foreach (var ent in targets)
+        {
+            _cloning.CloneComponents(source, ent, settings);
+            yield return ent;
+        }
+    }
+
+    [CommandImplementation("equipment")]
+    public IEnumerable<EntityUid> Equipment([PipedArgument] IEnumerable<EntityUid> targets, EntityUid source, SlotFlags flags)
+    {
+        _cloning ??= GetSys<CloningSystem>();
+
+        foreach (var ent in targets)
+        {
+            _cloning.CopyEquipment(source, ent, flags);
+            yield return ent;
+        }
+    }
+
+    [CommandImplementation("implants")]
+    public IEnumerable<EntityUid> Implants([PipedArgument] IEnumerable<EntityUid> targets, EntityUid source, bool copyStorage)
+    {
+        _cloning ??= GetSys<CloningSystem>();
+
+        foreach (var ent in targets)
+        {
+            _cloning.CopyImplants(source, ent, copyStorage);
+            yield return ent;
+        }
+    }
+
+    [CommandImplementation("storage")]
+    public IEnumerable<EntityUid> InternalStorage([PipedArgument] IEnumerable<EntityUid> targets, EntityUid source)
+    {
+        _cloning ??= GetSys<CloningSystem>();
+
+        foreach (var ent in targets)
+        {
+            _cloning.CopyStorage(source, ent);
+            yield return ent;
+        }
+    }
+}
index d8ab8a2aa1905e7a5fc38ba398c23948251d547d..e44264fb41e0def1062beb56c23faafbaef27f9d 100644 (file)
@@ -1,3 +1,5 @@
+using Robust.Shared.Prototypes;
+
 namespace Content.Shared.Cloning;
 
 public abstract partial class SharedCloningSystem : EntitySystem
@@ -11,4 +13,14 @@ public abstract partial class SharedCloningSystem : EntitySystem
     public virtual void CloneComponents(EntityUid original, EntityUid clone, CloningSettingsPrototype settings)
     {
     }
+
+    /// <summary>
+    /// Copy components from one entity to another based on a CloningSettingsPrototype.
+    /// </summary>
+    /// <param name="original">The orignal Entity to clone components from.</param>
+    /// <param name="clone">The target Entity to clone components to.</param>
+    /// <param name="settings">The clone settings prototype id containing the list of components to clone.</param>
+    public virtual void CloneComponents(EntityUid original, EntityUid clone, ProtoId<CloningSettingsPrototype> settings)
+    {
+    }
 }
index 218235338cbcf7eeb3d0ea6641818e0befb859e1..85eae1ef3da2418ac18d9a2e3566646717c66218 100644 (file)
@@ -16,6 +16,16 @@ command-description-bank-set =
     Sets the money for the given bank account.
 command-description-bank-amount =
     Returns the money for the given bank account.
+command-description-clone-humanoidappearance =
+    Clones the humanoid appearance of provided entity to all input entities.
+command-description-clone-comps =
+    Clones all components from the provided entity to all input entities. Only works for supported components.
+command-description-clone-equipment =
+    Clones the equipment from the provided entity to all input entities. Uses base prototypes, meaning changes to equipment won't persist to the cloned versions.
+command-description-clone-implants =
+    Clones the implants from the provided entity to all input entities. Uses base prototypes, meaning changes to implants won't persist to the cloned versions.
+command-description-clone-storage =
+    Clones the storage from the provided entity to all input entities. Uses base prototypes, meaning changes to contents won't persist to the cloned versions.
 command-description-jobs-jobs =
     Returns all jobs on a station.
 command-description-jobs-job =