From 6e8260cf3fe0ac11a05ae212c0492ba430c8e30c Mon Sep 17 00:00:00 2001 From: ViolentMonk Date: Sat, 16 Aug 2025 14:57:16 -0700 Subject: [PATCH] Trigger for OnInteractUsing (#39692) * 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> --- .../TriggerOnInteractUsingComponent.cs | 34 +++++++++++++++++++ .../Systems/TriggerSystem.Interaction.cs | 16 ++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs new file mode 100644 index 0000000000..0a5844338e --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnInteractUsingComponent.cs @@ -0,0 +1,34 @@ +using Content.Shared.Interaction; +using Content.Shared.Whitelist; +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when an entity is used to interact with another entity (). +/// The user is the player initiating the interaction or the item used, depending on the TargetUsed datafield. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnInteractUsingComponent : BaseTriggerOnXComponent +{ + /// + /// Whitelist of entities that can be used to trigger this component. + /// + /// No whitelist check when null. + [DataField, AutoNetworkedField] + public EntityWhitelist? Whitelist; + + /// + /// Blacklist of entities that cannot be used to trigger this component. + /// + /// No blacklist check when null. + [DataField, AutoNetworkedField] + public EntityWhitelist? Blacklist; + + /// + /// 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. + /// + [DataField, AutoNetworkedField] + public bool TargetUsed = false; +} diff --git a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs index 39ef4889de..62f483e876 100644 --- a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs +++ b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs @@ -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(OnActivate); SubscribeLocalEvent(OnUse); SubscribeLocalEvent(OnInteractHand); + SubscribeLocalEvent(OnInteractUsing); + SubscribeLocalEvent(OnThrow); SubscribeLocalEvent(OnThrown); @@ -59,6 +61,18 @@ public sealed partial class TriggerSystem args.Handled = true; } + private void OnInteractUsing(Entity 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 ent, ref ThrowEvent args) { Trigger(ent.Owner, args.Thrown, ent.Comp.KeyOut);