diff --git a/Content.Server/Implants/ImplanterSystem.cs b/Content.Server/Implants/ImplanterSystem.cs index 0d46241f414..3cfa3a9f5f8 100644 --- a/Content.Server/Implants/ImplanterSystem.cs +++ b/Content.Server/Implants/ImplanterSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Server.Popups; using Content.Shared.DoAfter; using Content.Shared.IdentityManagement; @@ -57,6 +58,17 @@ private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent componen 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 @@ private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent componen args.Handled = true; } + public bool CheckSameImplant(EntityUid target, EntityUid implant) + { + if (!TryComp(target, out var implanted)) + return false; + + var implantPrototype = Prototype(implant); + return implanted.ImplantContainer.ContainedEntities.Any(entity => Prototype(entity) == implantPrototype); + } + /// /// Attempt to implant someone else. /// diff --git a/Content.Shared/Implants/Components/ImplanterComponent.cs b/Content.Shared/Implants/Components/ImplanterComponent.cs index 32a36361633..80330aa7e66 100644 --- a/Content.Shared/Implants/Components/ImplanterComponent.cs +++ b/Content.Shared/Implants/Components/ImplanterComponent.cs @@ -70,6 +70,12 @@ public sealed partial class ImplanterComponent : Component [DataField] public (string, string) ImplantData; + /// + /// Determines if the same type of implant can be implanted into an entity multiple times. + /// + [DataField] + public bool AllowMultipleImplants = false; + /// /// The for this implanter /// diff --git a/Resources/Locale/en-US/implant/implant.ftl b/Resources/Locale/en-US/implant/implant.ftl index 22db4460aff..2f6ab9e4e2f 100644 --- a/Resources/Locale/en-US/implant/implant.ftl +++ b/Resources/Locale/en-US/implant/implant.ftl @@ -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