From 219aeda2353caed8e37eea7ee943190dad06e66b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=93=D0=BE=D0=BB=D1=83=D0=B1=D1=8C?= <124601871+Golubgik@users.noreply.github.com> Date: Sun, 19 Oct 2025 01:26:31 +0700 Subject: [PATCH] AddReagentOnTrigger (#39875) * 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 --- .../Effects/AddSolutionOnTriggerComponent.cs | 24 +++++++++++++ .../Trigger/Systems/SolutionTriggerSystem.cs | 35 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs create mode 100644 Content.Shared/Trigger/Systems/SolutionTriggerSystem.cs diff --git a/Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs new file mode 100644 index 0000000000..76b45278a7 --- /dev/null +++ b/Content.Shared/Trigger/Components/Effects/AddSolutionOnTriggerComponent.cs @@ -0,0 +1,24 @@ +using Robust.Shared.GameStates; +using Content.Shared.Chemistry.Components; + +namespace Content.Shared.Trigger.Components.Effects; + +/// +/// Adds reagents to the specified solution when the trigger is activated. +/// If TargetUser is true the user will have the solution added instead. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class AddSolutionOnTriggerComponent : BaseXOnTriggerComponent +{ + /// + /// The name of the solution to add to. + /// + [DataField(required: true), AutoNetworkedField] + public string Solution = string.Empty; + + /// + /// The reagent(s) to be added in the solution. + /// + [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 index 0000000000..54a1869217 --- /dev/null +++ b/Content.Shared/Trigger/Systems/SolutionTriggerSystem.cs @@ -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(OnTriggered); + } + + private void OnTriggered(Entity 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; + } +} -- 2.51.2