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
This commit is contained in:
Simon
2024-03-26 01:16:19 +01:00
committed by GitHub
parent bf98a6a8bb
commit 771390bb67
3 changed files with 28 additions and 0 deletions

View 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>