]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
uncloak ninja after attacking (#20892)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Wed, 11 Oct 2023 02:55:53 +0000 (03:55 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 02:55:53 +0000 (22:55 -0400)
* raise MeleeAttackEvent on the user after swinging

* add disable bool to RevealNinja

* uncloak ninja after attacking

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs
Content.Shared/Ninja/Systems/SharedSpaceNinjaSystem.cs
Content.Shared/Weapons/Melee/Events/MeleeAttackEvent.cs [new file with mode: 0644]
Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs

index 6bcd3432a91c3a4b36ee5d5ce446ee9392e7bd2c..473e29cc943df87449cdfc67b20cd922fbbce78a 100644 (file)
@@ -96,7 +96,7 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
     /// <summary>
     /// Force uncloaks the user and disables suit abilities.
     /// </summary>
-    public void RevealNinja(EntityUid uid, EntityUid user, NinjaSuitComponent? comp = null, StealthClothingComponent? stealthClothing = null)
+    public void RevealNinja(EntityUid uid, EntityUid user, bool disable = true, NinjaSuitComponent? comp = null, StealthClothingComponent? stealthClothing = null)
     {
         if (!Resolve(uid, ref comp, ref stealthClothing))
             return;
@@ -104,6 +104,9 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
         if (!StealthClothing.SetEnabled(uid, user, false, stealthClothing))
             return;
 
+        if (!disable)
+            return;
+
         // previously cloaked, disable abilities for a short time
         _audio.PlayPredicted(comp.RevealSound, uid, user);
         // all abilities check for a usedelay on the ninja
index fbcb4efe484825a9b2fdbce8134b040d682bc394..522f29fe420f71f0303b80a3161222114a444eb5 100644 (file)
@@ -19,6 +19,7 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<SpaceNinjaComponent, AttackedEvent>(OnNinjaAttacked);
+        SubscribeLocalEvent<SpaceNinjaComponent, MeleeAttackEvent>(OnNinjaAttack);
         SubscribeLocalEvent<SpaceNinjaComponent, ShotAttemptedEvent>(OnShotAttempted);
     }
 
@@ -74,7 +75,19 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem
     {
         if (comp.Suit != null && TryComp<StealthClothingComponent>(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
         {
-            Suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing);
+            Suit.RevealNinja(comp.Suit.Value, uid, true, null, stealthClothing);
+        }
+    }
+
+    /// <summary>
+    /// Handle revealing ninja if cloaked when attacking.
+    /// Only reveals, there is no cooldown.
+    /// </summary>
+    private void OnNinjaAttack(EntityUid uid, SpaceNinjaComponent comp, ref MeleeAttackEvent args)
+    {
+        if (comp.Suit != null && TryComp<StealthClothingComponent>(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
+        {
+            Suit.RevealNinja(comp.Suit.Value, uid, false, null, stealthClothing);
         }
     }
 
diff --git a/Content.Shared/Weapons/Melee/Events/MeleeAttackEvent.cs b/Content.Shared/Weapons/Melee/Events/MeleeAttackEvent.cs
new file mode 100644 (file)
index 0000000..9530b0e
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Shared.Weapons.Melee.Events;
+
+/// <summary>
+/// Event raised on the user after attacking with a melee weapon, regardless of whether it hit anything.
+/// </summary>
+[ByRefEvent]
+public record struct MeleeAttackEvent(EntityUid Weapon);
index ebe1a21e679ca3fe09ed82b1dc58c19d585a1226..4259706ba867b593894e6e6f3120c5434f6726c5 100644 (file)
@@ -426,6 +426,9 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
             DoLungeAnimation(user, weapon.Angle, GetCoordinates(attack.Coordinates).ToMap(EntityManager, TransformSystem), weapon.Range, animation);
         }
 
+        var attackEv = new MeleeAttackEvent(weaponUid);
+        RaiseLocalEvent(user, ref attackEv);
+
         weapon.Attacking = true;
         return true;
     }