]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make all implants unable to be implanted more than once (#26250)
authorSimon <63975668+Simyon264@users.noreply.github.com>
Tue, 26 Mar 2024 00:16:19 +0000 (01:16 +0100)
committerGitHub <noreply@github.com>
Tue, 26 Mar 2024 00:16:19 +0000 (01:16 +0100)
* Make mind shield implants unable to be implanted more than once

* Default AllowMultipleImplants to false and update implanters.yml

* Use TryComp instead of TryGetComponent

* Deny multiple implants for fun implants too.

* Make comment more precise

Content.Server/Implants/ImplanterSystem.cs
Content.Shared/Implants/Components/ImplanterComponent.cs
Resources/Locale/en-US/implant/implant.ftl

index 56d0bd3bbd0d0611a9024937649d3ce37e52fd95..e441574213e93451e6856700dc5e9e14ad4ac8ac 100644 (file)
@@ -1,3 +1,4 @@
+using System.Linq;
 using Content.Server.Popups;
 using Content.Shared.DoAfter;
 using Content.Shared.IdentityManagement;
@@ -57,6 +58,17 @@ public sealed partial class ImplanterSystem : SharedImplanterSystem
                 return;
             }
 
+            // Check if we are trying to implant a implant which is already implanted
+            if (implant.HasValue && !component.AllowMultipleImplants && CheckSameImplant(target, implant.Value))
+            {
+                var name = Identity.Name(target, EntityManager, args.User);
+                var msg = Loc.GetString("implanter-component-implant-already", ("implant", implant), ("target", name));
+                _popup.PopupEntity(msg, target, args.User);
+                args.Handled = true;
+                return;
+            }
+
+
             //Implant self instantly, otherwise try to inject the target.
             if (args.User == target)
                 Implant(target, target, uid, component);
@@ -67,6 +79,15 @@ public sealed partial class ImplanterSystem : SharedImplanterSystem
         args.Handled = true;
     }
 
+    public bool CheckSameImplant(EntityUid target, EntityUid implant)
+    {
+        if (!TryComp<ImplantedComponent>(target, out var implanted))
+            return false;
+
+        var implantPrototype = Prototype(implant);
+        return implanted.ImplantContainer.ContainedEntities.Any(entity => Prototype(entity) == implantPrototype);
+    }
+
     /// <summary>
     /// Attempt to implant someone else.
     /// </summary>
index 32a3636163346e90cc05d2969427d58a2556e296..80330aa7e66d717f4477959f06343b0344d1376b 100644 (file)
@@ -70,6 +70,12 @@ public sealed partial class ImplanterComponent : Component
     [DataField]
     public (string, string) ImplantData;
 
+    /// <summary>
+    /// Determines if the same type of implant can be implanted into an entity multiple times.
+    /// </summary>
+    [DataField]
+    public bool AllowMultipleImplants = false;
+
     /// <summary>
     /// The <see cref="ItemSlot"/> for this implanter
     /// </summary>
index 22db4460affda87aedb64019a456c162ba805728..2f6ab9e4e2f3bef99a50bea339684e8be65dd8c0 100644 (file)
@@ -4,6 +4,7 @@ implanter-component-implanting-target = {$user} is trying to implant you with so
 implanter-component-implant-failed = The {$implant} cannot be given to {$target}!
 implanter-draw-failed-permanent = The {$implant} in {$target} is fused with them and cannot be removed!
 implanter-draw-failed = You tried to remove an implant but found nothing.
+implanter-component-implant-already = {$target} already has the {$implant}!
 
 ## UI
 implanter-draw-text = Draw