]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
AddTagOnTrigger, RemoveTagOnTrigger, SwapPositionOnTrigger, JitterOnTrigger (#41476)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Wed, 19 Nov 2025 01:58:50 +0000 (02:58 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Nov 2025 01:58:50 +0000 (01:58 +0000)
* more triggers

* comment

---------

Co-authored-by: iaada <iaada@users.noreply.github.com>
Content.Shared/Trigger/Components/Effects/AddTagsOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Components/Effects/JitterOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Components/Effects/RemoveTagsOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Components/Effects/SwapLocationOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/JitterOnTriggerSystem.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/SwapLocationOnTriggerSystem.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/TagOnTriggerSystem.cs [new file with mode: 0644]

diff --git a/Content.Shared/Trigger/Components/Effects/AddTagsOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/AddTagsOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..9e73a60
--- /dev/null
@@ -0,0 +1,20 @@
+using Content.Shared.Tag;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Adds the given tags when triggered.
+/// If TargetUser is true the tags will be added to the user instead.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class AddTagsOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// The tags to add.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public List<ProtoId<TagPrototype>> Tags = new();
+}
+
diff --git a/Content.Shared/Trigger/Components/Effects/JitterOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/JitterOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..340ad6c
--- /dev/null
@@ -0,0 +1,47 @@
+using Content.Shared.StatusEffect;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Makes the entity play a jitter animation when triggered.
+/// If TargetUser is true the user will jitter instead.
+/// </summary>
+/// <summary>
+/// The target requires <see cref="StatusEffectsComponent"/>.
+/// TODO: Convert jitter to the new status effects system.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class JitterOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// Jitteriness of the animation.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float Amplitude = 10.0f;
+
+    /// <summary>
+    /// Frequency for jittering.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float Frequency = 4.0f;
+
+    /// <summary>
+    /// For how much time to apply the effect.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public TimeSpan Time = TimeSpan.FromSeconds(2);
+
+    /// <summary>
+    /// The status effect cooldown should be refreshed (true) or accumulated (false).
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool Refresh;
+
+    /// <summary>
+    /// Whether to change any existing jitter value even if they're greater than the ones we're setting.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool ForceValueChange;
+}
+
diff --git a/Content.Shared/Trigger/Components/Effects/RemoveTagsOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/RemoveTagsOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..8e4d0e4
--- /dev/null
@@ -0,0 +1,20 @@
+using Content.Shared.Tag;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Remove the given tags when triggered.
+/// If TargetUser is true the tags will be added to the user instead.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class RemoveTagsOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// The tags to remove.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public List<ProtoId<TagPrototype>> Tags = new();
+}
+
diff --git a/Content.Shared/Trigger/Components/Effects/SwapLocationOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/SwapLocationOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..33cec1d
--- /dev/null
@@ -0,0 +1,10 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Swaps the location of the target and the user of the trigger when triggered.
+/// <see cref="BaseXOnTriggerComponent.TargetUser"/> is ignored.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class SwapLocationOnTriggerComponent : BaseXOnTriggerComponent;
diff --git a/Content.Shared/Trigger/Systems/JitterOnTriggerSystem.cs b/Content.Shared/Trigger/Systems/JitterOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..5a9e046
--- /dev/null
@@ -0,0 +1,20 @@
+using Content.Shared.Jittering;
+using Content.Shared.Trigger.Components.Effects;
+using Robust.Shared.Network;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class JitterOnTriggerSystem : XOnTriggerSystem<JitterOnTriggerComponent>
+{
+    [Dependency] private readonly SharedJitteringSystem _jittering = default!;
+    [Dependency] private readonly INetManager _net = default!;
+
+    protected override void OnTrigger(Entity<JitterOnTriggerComponent> ent, EntityUid target, ref TriggerEvent args)
+    {
+        // DoJitter mispredicts at the moment.
+        // TODO: Fix this and remove the IsServer check.
+        if (_net.IsServer)
+            _jittering.DoJitter(target, ent.Comp.Time, ent.Comp.Refresh, ent.Comp.Amplitude, ent.Comp.Frequency, ent.Comp.ForceValueChange);
+        args.Handled = true;
+    }
+}
diff --git a/Content.Shared/Trigger/Systems/SwapLocationOnTriggerSystem.cs b/Content.Shared/Trigger/Systems/SwapLocationOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..7b3004a
--- /dev/null
@@ -0,0 +1,30 @@
+using Content.Shared.Trigger.Components.Effects;
+using Robust.Shared.Network;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class SwapLocationOnTriggerSystem : EntitySystem
+{
+    [Dependency] private readonly SharedTransformSystem _transform = default!;
+    [Dependency] private readonly INetManager _net = default!;
+
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<SwapLocationOnTriggerComponent, TriggerEvent>(OnTrigger);
+    }
+
+    private void OnTrigger(Entity<SwapLocationOnTriggerComponent> ent, ref TriggerEvent args)
+    {
+        if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
+            return;
+
+        if (args.User == null)
+            return;
+
+        // SwapPositions mispredicts at the moment.
+        // TODO: Fix this and remove the IsServer check.
+        if (_net.IsServer)
+            _transform.SwapPositions(ent.Owner, args.User.Value);
+        args.Handled = true;
+    }
+}
diff --git a/Content.Shared/Trigger/Systems/TagOnTriggerSystem.cs b/Content.Shared/Trigger/Systems/TagOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..d636593
--- /dev/null
@@ -0,0 +1,26 @@
+using Content.Shared.Tag;
+using Content.Shared.Trigger.Components.Effects;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class AddTagsOnTriggerSystem : XOnTriggerSystem<AddTagsOnTriggerComponent>
+{
+    [Dependency] private readonly TagSystem _tag = default!;
+
+    protected override void OnTrigger(Entity<AddTagsOnTriggerComponent> ent, EntityUid target, ref TriggerEvent args)
+    {
+        _tag.AddTags(target, ent.Comp.Tags);
+        args.Handled = true;
+    }
+}
+
+public sealed class RemoveTagsOnTriggerSystem : XOnTriggerSystem<RemoveTagsOnTriggerComponent>
+{
+    [Dependency] private readonly TagSystem _tag = default!;
+
+    protected override void OnTrigger(Entity<RemoveTagsOnTriggerComponent> ent, EntityUid target, ref TriggerEvent args)
+    {
+        _tag.RemoveTags(target, ent.Comp.Tags);
+        args.Handled = true;
+    }
+}