From c0ba54bbe7dc9edf8ea72038ef3ca2f738843849 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:41:49 +0100 Subject: [PATCH 1/5] Make mind shield implants unable to be implanted more than once --- Content.Server/Implants/ImplanterSystem.cs | 21 +++++++++++++++++++ .../Implants/Components/ImplanterComponent.cs | 6 ++++++ Resources/Locale/en-US/implant/implant.ftl | 1 + .../Entities/Objects/Misc/implanters.yml | 1 + 4 files changed, 29 insertions(+) diff --git a/Content.Server/Implants/ImplanterSystem.cs b/Content.Server/Implants/ImplanterSystem.cs index 0d46241f4146..c5c73c18684a 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 (!EntityManager.TryGetComponent(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 32a363616334..cb360b0239d2 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; + /// + /// If the is already implanted, should it be allowed to be implanted again? + /// + [DataField] + public bool AllowMultipleImplants = true; + /// /// The for this implanter /// diff --git a/Resources/Locale/en-US/implant/implant.ftl b/Resources/Locale/en-US/implant/implant.ftl index 22db4460affd..2f6ab9e4e2f3 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 diff --git a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml index c09deb130717..3b4a44ed6463 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml @@ -251,3 +251,4 @@ components: - type: Implanter implant: MindShieldImplant + allowMultipleImplants: false # Only one mindshield implant allowed From a5f73039e96fa81fd1ed5c7e49b1cbe575aeef0b Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:38:52 +0100 Subject: [PATCH 2/5] Default AllowMultipleImplants to false and update implanters.yml --- Content.Shared/Implants/Components/ImplanterComponent.cs | 2 +- Resources/Prototypes/Entities/Objects/Misc/implanters.yml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Implants/Components/ImplanterComponent.cs b/Content.Shared/Implants/Components/ImplanterComponent.cs index cb360b0239d2..00388474e19a 100644 --- a/Content.Shared/Implants/Components/ImplanterComponent.cs +++ b/Content.Shared/Implants/Components/ImplanterComponent.cs @@ -74,7 +74,7 @@ public sealed partial class ImplanterComponent : Component /// If the is already implanted, should it be allowed to be implanted again? /// [DataField] - public bool AllowMultipleImplants = true; + public bool AllowMultipleImplants = false; /// /// The for this implanter diff --git a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml index 3b4a44ed6463..d73d98f5ab90 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml @@ -131,6 +131,7 @@ components: - type: Implanter implant: SadTromboneImplant + allowMultipleImplants: true # WOMP WOMP - type: entity id: LightImplanter @@ -139,6 +140,7 @@ components: - type: Implanter implant: LightImplant + allowMultipleImplants: true # ok this might be a bad idea. How to win against your enemies? Crash their game with 50 lights! - type: entity id: BikeHornImplanter @@ -147,6 +149,7 @@ components: - type: Implanter implant: BikeHornImplant + allowMultipleImplants: true # This implant can be implanted multiple times HONK HONK #Security implanters @@ -251,4 +254,3 @@ components: - type: Implanter implant: MindShieldImplant - allowMultipleImplants: false # Only one mindshield implant allowed From 8b1a92d25892ca3e916b9a53689b1e449b47c938 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:40:52 +0100 Subject: [PATCH 3/5] Use TryComp instead of TryGetComponent --- Content.Server/Implants/ImplanterSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Implants/ImplanterSystem.cs b/Content.Server/Implants/ImplanterSystem.cs index c5c73c18684a..3cfa3a9f5f8f 100644 --- a/Content.Server/Implants/ImplanterSystem.cs +++ b/Content.Server/Implants/ImplanterSystem.cs @@ -81,7 +81,7 @@ private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent componen public bool CheckSameImplant(EntityUid target, EntityUid implant) { - if (!EntityManager.TryGetComponent(target, out var implanted)) + if (!TryComp(target, out var implanted)) return false; var implantPrototype = Prototype(implant); From 184d695441486bcdcea85c45e1d56be8e7743258 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:31:31 +0100 Subject: [PATCH 4/5] Deny multiple implants for fun implants too. --- Resources/Prototypes/Entities/Objects/Misc/implanters.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml index d73d98f5ab90..c09deb130717 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/implanters.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/implanters.yml @@ -131,7 +131,6 @@ components: - type: Implanter implant: SadTromboneImplant - allowMultipleImplants: true # WOMP WOMP - type: entity id: LightImplanter @@ -140,7 +139,6 @@ components: - type: Implanter implant: LightImplant - allowMultipleImplants: true # ok this might be a bad idea. How to win against your enemies? Crash their game with 50 lights! - type: entity id: BikeHornImplanter @@ -149,7 +147,6 @@ components: - type: Implanter implant: BikeHornImplant - allowMultipleImplants: true # This implant can be implanted multiple times HONK HONK #Security implanters From b5459aa84ed36efd81f559742c36b5c647fca808 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:33:36 +0100 Subject: [PATCH 5/5] Make comment more precise --- Content.Shared/Implants/Components/ImplanterComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Implants/Components/ImplanterComponent.cs b/Content.Shared/Implants/Components/ImplanterComponent.cs index 00388474e19a..80330aa7e66d 100644 --- a/Content.Shared/Implants/Components/ImplanterComponent.cs +++ b/Content.Shared/Implants/Components/ImplanterComponent.cs @@ -71,7 +71,7 @@ public sealed partial class ImplanterComponent : Component public (string, string) ImplantData; /// - /// If the is already implanted, should it be allowed to be implanted again? + /// Determines if the same type of implant can be implanted into an entity multiple times. /// [DataField] public bool AllowMultipleImplants = false;