]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
AddReagentOnTrigger (#39875)
authorГолубь <124601871+Golubgik@users.noreply.github.com>
Sat, 18 Oct 2025 18:26:31 +0000 (01:26 +0700)
committerGitHub <noreply@github.com>
Sat, 18 Oct 2025 18:26:31 +0000 (18:26 +0000)
* Trigger

* Unnecessary(?) Checks

* request

* Update

Co-Authored-By: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
* cleanup

* standard name

* don't use name alias

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: iaada <iaada@users.noreply.github.com>
Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/SolutionTriggerSystem.cs [new file with mode: 0644]

diff --git a/Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..76b4527
--- /dev/null
@@ -0,0 +1,24 @@
+using Robust.Shared.GameStates;
+using Content.Shared.Chemistry.Components;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Adds reagents to the specified solution when the trigger is activated.
+/// If TargetUser is true the user will have the solution added instead.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class AddSolutionOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// The name of the solution to add to.
+    /// </summary>
+    [DataField(required: true), AutoNetworkedField]
+    public string Solution = string.Empty;
+
+    /// <summary>
+    /// The reagent(s) to be added in the solution.
+    /// </summary>
+    [DataField(required: true), AutoNetworkedField]
+    public Solution AddedSolution = default!;
+}
diff --git a/Content.Shared/Trigger/Systems/SolutionTriggerSystem.cs b/Content.Shared/Trigger/Systems/SolutionTriggerSystem.cs
new file mode 100644 (file)
index 0000000..54a1869
--- /dev/null
@@ -0,0 +1,35 @@
+using Content.Shared.Trigger.Components.Effects;
+using Robust.Shared.Containers;
+using Content.Shared.Chemistry.EntitySystems;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class SolutionTriggerSystem : EntitySystem
+{
+    [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<AddSolutionOnTriggerComponent, TriggerEvent>(OnTriggered);
+    }
+
+    private void OnTriggered(Entity<AddSolutionOnTriggerComponent> ent, ref TriggerEvent args)
+    {
+        if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
+            return;
+
+        var target = ent.Comp.TargetUser ? args.User : ent.Owner;
+
+        if (target == null)
+            return;
+
+        if (!_solutionContainer.TryGetSolution(target.Value, ent.Comp.Solution, out var solutionRef, out _))
+            return;
+
+        _solutionContainer.AddSolution(solutionRef.Value, ent.Comp.AddedSolution);
+
+        args.Handled = true;
+    }
+}