From c3784a3005cea9cf04baab53587da5009b4986cf Mon Sep 17 00:00:00 2001
From: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Date: Mon, 24 Feb 2025 17:21:17 +0100
Subject: [PATCH] GettingUsedAttemptEvent (#35450)
* init
* review
* doc
* Update Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs
---------
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
---
Content.Shared/ActionBlocker/ActionBlockerSystem.cs | 12 +++++++++---
.../Interaction/Events/GettingUsedAttemptEvent.cs | 10 ++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
create mode 100644 Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs
diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs
index 6152699ccb..08eac657c0 100644
--- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs
+++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs
@@ -109,10 +109,16 @@ namespace Content.Shared.ActionBlocker
///
public bool CanUseHeldEntity(EntityUid user, EntityUid used)
{
- var ev = new UseAttemptEvent(user, used);
- RaiseLocalEvent(user, ev);
+ var useEv = new UseAttemptEvent(user, used);
+ RaiseLocalEvent(user, useEv);
- return !ev.Cancelled;
+ if (useEv.Cancelled)
+ return false;
+
+ var usedEv = new GettingUsedAttemptEvent(user);
+ RaiseLocalEvent(used, usedEv);
+
+ return !usedEv.Cancelled;
}
diff --git a/Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs b/Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs
new file mode 100644
index 0000000000..cd5f029346
--- /dev/null
+++ b/Content.Shared/Interaction/Events/GettingUsedAttemptEvent.cs
@@ -0,0 +1,10 @@
+namespace Content.Shared.Interaction.Events;
+
+///
+/// Event raised on an item when attempting to use it in your hands. Cancelling it stops the interaction.
+///
+/// The user of said item
+public sealed class GettingUsedAttemptEvent(EntityUid user) : CancellableEntityEventArgs
+{
+ public EntityUid User = user;
+}
--
2.51.2