Implant whitelist/blacklisting (#20678)

* add whitelist and blacklist to implant and implanter components

* handle whitelist and blacklist in systems

* move hardcoded whitelist/blacklist to base implanter + add admeme implanter

* give implants sensible whitelists

* cleaner CheckTarget and fix

* remove unused imports

* network lists

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-10-27 03:34:02 +01:00
committed by GitHub
parent b4da282341
commit bb65818bf3
7 changed files with 100 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -15,6 +16,19 @@ public sealed partial class ImplanterComponent : Component
public const string ImplanterSlotId = "implanter_slot";
public const string ImplantSlotId = "implant";
/// <summary>
/// Whitelist to check entities against before implanting.
/// Implants get their own whitelist which is checked afterwards.
/// </summary>
[DataField, AutoNetworkedField]
public EntityWhitelist? Whitelist;
/// <summary>
/// Blacklist to check entities against before implanting.
/// </summary>
[DataField, AutoNetworkedField]
public EntityWhitelist? Blacklist;
/// <summary>
/// Used for implanters that start with specific implants
/// </summary>

View File

@@ -1,4 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
@@ -34,6 +35,20 @@ public sealed partial class SubdermalImplantComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("permanent"), AutoNetworkedField]
public bool Permanent = false;
/// <summary>
/// Target whitelist for this implant specifically.
/// Only checked if the implanter allows implanting on the target to begin with.
/// </summary>
[DataField]
public EntityWhitelist? Whitelist;
/// <summary>
/// Target blacklist for this implant specifically.
/// Only checked if the implanter allows implanting on the target to begin with.
/// </summary>
[DataField]
public EntityWhitelist? Blacklist;
}
/// <summary>

View File

@@ -6,6 +6,7 @@ using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Implants.Components;
using Content.Shared.Popups;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.Serialization;
@@ -85,11 +86,23 @@ public abstract class SharedImplanterSystem : EntitySystem
if (!TryComp(implant, out implantComp))
return false;
if (!CheckTarget(target, component.Whitelist, component.Blacklist) ||
!CheckTarget(target, implantComp.Whitelist, implantComp.Blacklist))
{
return false;
}
var ev = new AddImplantAttemptEvent(user, target, implant.Value, implanter);
RaiseLocalEvent(target, ev);
return !ev.Cancelled;
}
protected bool CheckTarget(EntityUid target, EntityWhitelist? whitelist, EntityWhitelist? blacklist)
{
return whitelist?.IsValid(target, EntityManager) != false &&
blacklist?.IsValid(target, EntityManager) != true;
}
//Draw the implant out of the target
//TODO: Rework when surgery is in so implant cases can be a thing
public void Draw(EntityUid implanter, EntityUid user, EntityUid target, ImplanterComponent component)