]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Trigger for OnInteractUsing (#39692)
authorViolentMonk <jimmy.toor.s@gmail.com>
Sat, 16 Aug 2025 21:57:16 +0000 (14:57 -0700)
committerGitHub <noreply@github.com>
Sat, 16 Aug 2025 21:57:16 +0000 (23:57 +0200)
* Add trigger for InteractOnUsing

* Add blacklist and targetUsed fields

* Update Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs

diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs
new file mode 100644 (file)
index 0000000..0a58443
--- /dev/null
@@ -0,0 +1,34 @@
+using Content.Shared.Interaction;
+using Content.Shared.Whitelist;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers when an entity is used to interact with another entity (<see cref="InteractUsingEvent"/>).
+/// The user is the player initiating the interaction or the item used, depending on the TargetUsed datafield.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnInteractUsingComponent : BaseTriggerOnXComponent
+{
+    /// <summary>
+    /// Whitelist of entities that can be used to trigger this component.
+    /// </summary>
+    /// <remarks>No whitelist check when null.</remarks>
+    [DataField, AutoNetworkedField]
+    public EntityWhitelist? Whitelist;
+
+    /// <summary>
+    /// Blacklist of entities that cannot be used to trigger this component.
+    /// </summary>
+    /// <remarks>No blacklist check when null.</remarks>
+    [DataField, AutoNetworkedField]
+    public EntityWhitelist? Blacklist;
+
+    /// <summary>
+    /// If false, the trigger user will be the user that initiated the interaction.
+    /// If true, the trigger user will the entity that was used to interact.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool TargetUsed = false;
+}
index 39ef4889de1c422f6b0df11b7541766e7749e18c..62f483e876392cc2684c26cc3ad32295b8dd5b6d 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Shared.Examine;
+using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Item.ItemToggle.Components;
@@ -16,6 +16,8 @@ public sealed partial class TriggerSystem
         SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
         SubscribeLocalEvent<TriggerOnUseComponent, UseInHandEvent>(OnUse);
         SubscribeLocalEvent<TriggerOnInteractHandComponent, InteractHandEvent>(OnInteractHand);
+        SubscribeLocalEvent<TriggerOnInteractUsingComponent, InteractUsingEvent>(OnInteractUsing);
+
         SubscribeLocalEvent<TriggerOnThrowComponent, ThrowEvent>(OnThrow);
         SubscribeLocalEvent<TriggerOnThrownComponent, ThrownEvent>(OnThrown);
 
@@ -59,6 +61,18 @@ public sealed partial class TriggerSystem
         args.Handled = true;
     }
 
+    private void OnInteractUsing(Entity<TriggerOnInteractUsingComponent> ent, ref InteractUsingEvent args)
+    {
+        if (args.Handled)
+            return;
+
+        if (!_whitelist.CheckBoth(args.Used, ent.Comp.Blacklist, ent.Comp.Whitelist))
+            return;
+
+        Trigger(ent.Owner, ent.Comp.TargetUsed ? args.Used : args.User, ent.Comp.KeyOut);
+        args.Handled = true;
+    }
+
     private void OnThrow(Entity<TriggerOnThrowComponent> ent, ref ThrowEvent args)
     {
         Trigger(ent.Owner, args.Thrown, ent.Comp.KeyOut);