make mindshields removable (#1631)

* make mindshields removable

* use new logic stolen from upstream pr

* a

* remove unused mafia trollage

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas 2024-08-18 10:47:55 +00:00 committed by GitHub
parent 40c9187592
commit 8ba57f61e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 12 deletions

View File

@ -28,19 +28,26 @@ public sealed class MindShieldSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SubdermalImplantComponent, ImplantImplantedEvent>(ImplantCheck);
SubscribeLocalEvent<SubdermalImplantComponent, ImplantImplantedEvent>(OnImplanted); // DeltaV: separate handlers for implanting and removal
SubscribeLocalEvent<SubdermalImplantComponent, ImplantRemovedEvent>(OnRemoved); // DeltaV
}
/// <summary>
/// Checks if the implant was a mindshield or not
/// DeltaV: Adds components when implantedChecks if the implant was a mindshield or not
/// </summary>
public void ImplantCheck(EntityUid uid, SubdermalImplantComponent comp, ref ImplantImplantedEvent ev)
public void OnImplanted(EntityUid uid, SubdermalImplantComponent comp, ref ImplantImplantedEvent ev)
{
if (_tag.HasTag(ev.Implant, MindShieldTag) && ev.Implanted != null)
{
EnsureComp<MindShieldComponent>(ev.Implanted.Value);
MindShieldRemovalCheck(ev.Implanted.Value, ev.Implant);
}
if (comp.AddedComponents is {} components && ev.Implanted is {} user)
EntityManager.AddComponents(user, components);
}
/// <summary>
/// DeltaV: Removes components when implanted.
/// </summary>
private void OnRemoved(Entity<SubdermalImplantComponent> ent, ref ImplantRemovedEvent args)
{
if (ent.Comp.AddedComponents is {} components && args.Implanted is {} user)
EntityManager.RemoveComponents(user, components);
}
/// <summary>

View File

@ -49,6 +49,13 @@ public sealed partial class SubdermalImplantComponent : Component
/// </summary>
[DataField]
public EntityWhitelist? Blacklist;
/// <summary>
/// DeltaV: Used to replace mindshield tag logic
/// Components to add to and remove from the user when implanted and removed.
/// </summary>
[DataField]
public ComponentRegistry? AddedComponents;
}
/// <summary>

View File

@ -72,6 +72,9 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
if (component.ImplantAction != null)
_actionsSystem.RemoveProvidedActions(component.ImplantedEntity.Value, uid);
var ev = new ImplantRemovedEvent(uid, component.ImplantedEntity.Value); // DeltaV
RaiseLocalEvent(uid, ref ev); // DeltaV
if (!_container.TryGetContainer(uid, BaseStorageId, out var storageImplant))
return;
@ -205,3 +208,19 @@ public readonly struct ImplantImplantedEvent
Implanted = implanted;
}
}
/// <summary>
/// DeltaV: Event that is raised whenever someone gets an implant removed from them.
/// </summary>
[ByRefEvent]
public readonly struct ImplantRemovedEvent
{
public readonly EntityUid Implant;
public readonly EntityUid? Implanted;
public ImplantRemovedEvent(EntityUid implant, EntityUid? implanted)
{
Implant = implant;
Implanted = implanted;
}
}

View File

@ -321,7 +321,6 @@
categories: [ HideSpawnMenu ]
components:
- type: SubdermalImplant
permanent: true
- type: Tag
tags:
- MindShield
permanent: false # DeltaV - let peaceful revs etc remove mindshields
addedComponents: # DeltaV - replaces mindshield tag logic
- type: MindShield