]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
TriggerOnIngested (#41875)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Tue, 16 Dec 2025 23:45:34 +0000 (00:45 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Dec 2025 23:45:34 +0000 (23:45 +0000)
* init

* nobody will ever know i copy paste

* i hate these names

* comment

---------

Co-authored-by: iaada <iaada@users.noreply.github.com>
Content.Shared/Trigger/Components/Triggers/TriggerOnIngestedComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/TriggerOnIngestedSystem.cs [new file with mode: 0644]

diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnIngestedComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnIngestedComponent.cs
new file mode 100644 (file)
index 0000000..e8bd920
--- /dev/null
@@ -0,0 +1,17 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Triggers;
+
+/// <summary>
+/// Triggers when the owner of this component is ingested, like a pill or food.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class TriggerOnIngestedComponent : BaseTriggerOnXComponent
+{
+    /// <summary>
+    /// Whether the fed entity is the user.
+    /// If false, the entity feeding will be the user.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool EatingIsUser = true;
+}
diff --git a/Content.Shared/Trigger/Systems/TriggerOnIngestedSystem.cs b/Content.Shared/Trigger/Systems/TriggerOnIngestedSystem.cs
new file mode 100644 (file)
index 0000000..1e199e8
--- /dev/null
@@ -0,0 +1,23 @@
+using Content.Shared.Nutrition;
+using Content.Shared.Trigger.Components.Triggers;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed partial class TriggerOnIngestedSystem : TriggerOnXSystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<TriggerOnIngestedComponent, IngestedEvent>(OnIngested);
+    }
+
+    private void OnIngested(Entity<TriggerOnIngestedComponent> ent, ref IngestedEvent args)
+    {
+        // args.Target is the entity being fed, while args.User is the entity doing the feeding.
+        // Since they are not always equal (feeding someone by force, for example) we use a bool to decide which one is the trigger user.
+        var user = ent.Comp.EatingIsUser ? args.Target : args.User;
+
+        Trigger.Trigger(ent.Owner, user, ent.Comp.KeyOut);
+    }
+}