]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
StaminaDamageOnTriggerComponent (#39607)
authorHannah Giovanna Dawson <karakkaraz@gmail.com>
Wed, 13 Aug 2025 16:50:34 +0000 (17:50 +0100)
committerGitHub <noreply@github.com>
Wed, 13 Aug 2025 16:50:34 +0000 (18:50 +0200)
* InflictStaminaOnTriggerSystem

Surprised this wasn't done alongside the damage one.

* Correct docstring

* Moar docstring changes!!!

* Resolve PR comment

* a

* Update Content.Shared/Trigger/Systems/StaminaDamageOnTriggerSystem.cs

---------

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

diff --git a/Content.Shared/Trigger/Components/Effects/StaminaDamageOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/StaminaDamageOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..dd8136f
--- /dev/null
@@ -0,0 +1,25 @@
+using Content.Shared.Trigger.Systems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Will inflict stamina to an entity when triggered.
+/// If TargetUser is true it the user will have stamina inflicted instead.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class StaminaDamageOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// Should the inflicted stamina ignore resistances?
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool IgnoreResistances;
+
+    /// <summary>
+    /// The stamina amount that is inflicted to the target.
+    /// May be further modified by <see cref="BeforeStaminaDamageOnTriggerEvent"/> subscriptions.
+    /// </summary>
+    [DataField(required: true), AutoNetworkedField]
+    public float Stamina;
+}
diff --git a/Content.Shared/Trigger/Systems/StaminaDamageOnTriggerSystem.cs b/Content.Shared/Trigger/Systems/StaminaDamageOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..0efa437
--- /dev/null
@@ -0,0 +1,42 @@
+using Content.Shared.Damage;
+using Content.Shared.Damage.Systems;
+using Content.Shared.Trigger.Components.Effects;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class StaminaDamageOnTriggerSystem : EntitySystem
+{
+    [Dependency] private readonly SharedStaminaSystem _stamina = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<StaminaDamageOnTriggerComponent, TriggerEvent>(OnTrigger);
+    }
+
+    private void OnTrigger(Entity<StaminaDamageOnTriggerComponent> 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;
+
+        var ev = new BeforeStaminaDamageOnTriggerEvent(ent.Comp.Stamina, target.Value);
+        RaiseLocalEvent(ent.Owner, ref ev);
+
+        _stamina.TakeStaminaDamage(target.Value, ev.Stamina, source: args.User, with: ent.Owner, ignoreResist: ent.Comp.IgnoreResistances);
+
+        args.Handled = true;
+    }
+}
+
+/// <summary>
+/// Raised on an entity before it inflicts stamina due to StaminaDamageOnTriggerComponent.
+/// Used to modify the stamina that will be inflicted.
+/// </summary>
+[ByRefEvent]
+public record struct BeforeStaminaDamageOnTriggerEvent(float Stamina, EntityUid Tripper);