From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:16:19 +0000 (+0100) Subject: Make all implants unable to be implanted more than once (#26250) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=771390bb6741074935e5f24c0aa9c87bc7b5ad09;p=space-station-14.git Make all implants unable to be implanted more than once (#26250) * 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 --- diff --git a/Content.Server/Implants/ImplanterSystem.cs b/Content.Server/Implants/ImplanterSystem.cs index 56d0bd3bbd..e441574213 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 @@ 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(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 32a3636163..80330aa7e6 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 22db4460af..2f6ab9e4e2 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