]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make throwable star damage stamina (#23527)
authorDakamakat <52600490+dakamakat@users.noreply.github.com>
Sun, 14 Jan 2024 09:10:50 +0000 (12:10 +0300)
committerGitHub <noreply@github.com>
Sun, 14 Jan 2024 09:10:50 +0000 (20:10 +1100)
* feat(star.yml): make throwable star damage stamina

* feat(Components): add new StaminaTresholdDamageOnEmbedComponent

* feat(SharedProjectileSystem): update system with new events to change
stamins treshold on embeed projectile remove / add

* feat(StaminaSystem): update system with new subscriptions

* feat(throwing_stars): update yml with new component

* feat(StaminaDamageOnEmbed): add stamina damage on embeed

* cleanup unused / ajust numbers

* fix(StaminaSystem / OnEmbedComponent ) apply requested changes

* Rest of the review

* another warning

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Shared/Damage/Components/StaminaDamageOnEmbedComponent.cs [new file with mode: 0644]
Content.Shared/Damage/Systems/StaminaSystem.cs
Content.Shared/Projectiles/EmbedEvent.cs [new file with mode: 0644]
Content.Shared/Projectiles/ProjectileEmbedEvent.cs
Content.Shared/Projectiles/SharedProjectileSystem.cs
Resources/Prototypes/Entities/Objects/Weapons/Throwable/throwing_stars.yml

diff --git a/Content.Shared/Damage/Components/StaminaDamageOnEmbedComponent.cs b/Content.Shared/Damage/Components/StaminaDamageOnEmbedComponent.cs
new file mode 100644 (file)
index 0000000..4ad4906
--- /dev/null
@@ -0,0 +1,17 @@
+using Content.Shared.Damage.Systems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Damage.Components;
+
+/// <summary>
+/// Applies stamina damage when embeds in an entity.
+/// </summary>
+[RegisterComponent]
+[NetworkedComponent]
+[AutoGenerateComponentState]
+[Access(typeof(StaminaSystem))]
+public sealed partial class StaminaDamageOnEmbedComponent : Component
+{
+    [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
+    public float Damage = 10f;
+}
index 33f1b0375bc7d807e9fdcc5f1d840db0a92e127c..2587d4e05f0e5b3da3ae4c79916313d944d7064c 100644 (file)
@@ -55,8 +55,11 @@ public sealed partial class StaminaSystem : EntitySystem
         SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed);
         SubscribeLocalEvent<StaminaComponent, RejuvenateEvent>(OnRejuvenate);
 
+        SubscribeLocalEvent<StaminaDamageOnEmbedComponent, EmbedEvent>(OnProjectileEmbed);
+
         SubscribeLocalEvent<StaminaDamageOnCollideComponent, ProjectileHitEvent>(OnProjectileHit);
         SubscribeLocalEvent<StaminaDamageOnCollideComponent, ThrowDoHitEvent>(OnThrowHit);
+
         SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnMeleeHit);
     }
 
@@ -114,7 +117,7 @@ public sealed partial class StaminaSystem : EntitySystem
         component.StaminaDamage = 0;
         RemComp<ActiveStaminaComponent>(uid);
         SetStaminaAlert(uid, component);
-        Dirty(component);
+        Dirty(uid, component);
     }
 
     private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args)
@@ -192,6 +195,14 @@ public sealed partial class StaminaSystem : EntitySystem
         OnCollide(uid, component, args.Target);
     }
 
+    private void OnProjectileEmbed(EntityUid uid, StaminaDamageOnEmbedComponent component, ref EmbedEvent args)
+    {
+        if (!TryComp<StaminaComponent>(args.Embedded, out var stamina))
+            return;
+
+        TakeStaminaDamage(args.Embedded, component.Damage, stamina, source: uid);
+    }
+
     private void OnThrowHit(EntityUid uid, StaminaDamageOnCollideComponent component, ThrowDoHitEvent args)
     {
         OnCollide(uid, component, args.Target);
diff --git a/Content.Shared/Projectiles/EmbedEvent.cs b/Content.Shared/Projectiles/EmbedEvent.cs
new file mode 100644 (file)
index 0000000..521a691
--- /dev/null
@@ -0,0 +1,15 @@
+namespace Content.Shared.Projectiles;
+
+/// <summary>
+/// Raised directed on an entity when it embeds in another entity.
+/// </summary>
+[ByRefEvent]
+public readonly record struct EmbedEvent(EntityUid? Shooter, EntityUid Embedded)
+{
+    public readonly EntityUid? Shooter = Shooter;
+
+    /// <summary>
+    /// Entity that is embedded in.
+    /// </summary>
+    public readonly EntityUid Embedded = Embedded;
+}
index 4dc9b9841cd945dbec19d2cffd38f03916f0f6b9..e7dd6df8e2962eeeeb9cfe5751ce74199a62a27f 100644 (file)
@@ -4,4 +4,4 @@ namespace Content.Shared.Projectiles;
 /// Raised directed on an entity when it embeds into something.
 /// </summary>
 [ByRefEvent]
-public readonly record struct ProjectileEmbedEvent(EntityUid Shooter, EntityUid Weapon, EntityUid Embedded);
+public readonly record struct ProjectileEmbedEvent(EntityUid? Shooter, EntityUid Weapon, EntityUid Embedded);
index e003764f92212c98f815df95376120f909e220ed..2db497f94c9edf55c7ec46e66ae46ee0c3f1af6e 100644 (file)
@@ -96,22 +96,22 @@ public abstract partial class SharedProjectileSystem : EntitySystem
         if (!component.EmbedOnThrow)
             return;
 
-        Embed(uid, args.Target, component);
+        Embed(uid, args.Target, null, component);
     }
 
     private void OnEmbedProjectileHit(EntityUid uid, EmbeddableProjectileComponent component, ref ProjectileHitEvent args)
     {
-        Embed(uid, args.Target, component);
+        Embed(uid, args.Target, args.Shooter, component);
 
         // Raise a specific event for projectiles.
-        if (TryComp<ProjectileComponent>(uid, out var projectile))
+        if (TryComp(uid, out ProjectileComponent? projectile))
         {
             var ev = new ProjectileEmbedEvent(projectile.Shooter!.Value, projectile.Weapon!.Value, args.Target);
             RaiseLocalEvent(uid, ref ev);
         }
     }
 
-    private void Embed(EntityUid uid, EntityUid target, EmbeddableProjectileComponent component)
+    private void Embed(EntityUid uid, EntityUid target, EntityUid? user, EmbeddableProjectileComponent component)
     {
         TryComp<PhysicsComponent>(uid, out var physics);
         _physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
@@ -121,13 +121,13 @@ public abstract partial class SharedProjectileSystem : EntitySystem
 
         if (component.Offset != Vector2.Zero)
         {
-            _transform.SetLocalPosition(xform, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset));
+            _transform.SetLocalPosition(uid, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset),
+                xform);
         }
 
-        if (component.Sound != null)
-        {
-            _audio.PlayPredicted(component.Sound, uid, null);
-        }
+        _audio.PlayPredicted(component.Sound, uid, null);
+        var ev = new EmbedEvent(user, target);
+        RaiseLocalEvent(uid, ref ev);
     }
 
     private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
index 48138452b238ae52222f6fc7c46aedae4c8c699a..c68feff0b5c86f744881ddf96fd0eb37f979ebb3 100644 (file)
       types:
         Slash: 8
         Piercing: 10
+  - type: StaminaDamageOnCollide
+    damage: 45
+  - type: StaminaDamageOnEmbed
+    damage: 10
 
 - type: entity
   parent: ThrowingStar