]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix Mjollnir throw while on delay (#39018)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Wed, 16 Jul 2025 20:27:21 +0000 (22:27 +0200)
committerGitHub <noreply@github.com>
Wed, 16 Jul 2025 20:27:21 +0000 (22:27 +0200)
* init

* fuck dirty

* yippee

Content.Shared/Weapons/Melee/Components/MeleeThrowOnHitComponent.cs
Content.Shared/Weapons/Melee/MeleeThrowOnHitSystem.cs

index 84e75129b141001c9fb7e86e70d8540d93421c49..42b72efede7b94b96e4bfb5f55b513f54c029255 100644 (file)
@@ -1,7 +1,4 @@
-using System.Numerics;
 using Robust.Shared.GameStates;
-using Robust.Shared.Physics.Components;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
 
 namespace Content.Shared.Weapons.Melee.Components;
 
@@ -9,7 +6,7 @@ namespace Content.Shared.Weapons.Melee.Components;
 /// This is used for a melee weapon that throws whatever gets hit by it in a line
 /// until it hits a wall or a time limit is exhausted.
 /// </summary>
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true)]
 [Access(typeof(MeleeThrowOnHitSystem))]
 public sealed partial class MeleeThrowOnHitComponent : Component
 {
@@ -42,6 +39,21 @@ public sealed partial class MeleeThrowOnHitComponent : Component
     /// </summary>
     [DataField, AutoNetworkedField]
     public bool ActivateOnThrown;
+
+    /// <summary>
+    /// Whether the entity can apply knockback this instance of being thrown.
+    /// If true, the entity cannot apply knockback.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    [ViewVariables(VVAccess.ReadOnly)]
+    public bool ThrowOnCooldown;
+
+    /// <summary>
+    /// Whether this item has hit anyone while it was thrown.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    [ViewVariables(VVAccess.ReadOnly)]
+    public bool HitWhileThrown;
 }
 
 /// <summary>
index 035432ef85c519f3ed600b31d06d547216cafacf..eaaf336e96bf3bfef4edc70ba162aa463073c590 100644 (file)
@@ -22,6 +22,29 @@ public sealed class MeleeThrowOnHitSystem : EntitySystem
     {
         SubscribeLocalEvent<MeleeThrowOnHitComponent, MeleeHitEvent>(OnMeleeHit);
         SubscribeLocalEvent<MeleeThrowOnHitComponent, ThrowDoHitEvent>(OnThrowHit);
+        SubscribeLocalEvent<MeleeThrowOnHitComponent, ThrownEvent>(OnThrow);
+        SubscribeLocalEvent<MeleeThrowOnHitComponent, LandEvent>(OnLand);
+    }
+
+    private void OnThrow(Entity<MeleeThrowOnHitComponent> ent, ref ThrownEvent args)
+    {
+        if (_delay.IsDelayed(ent.Owner))
+            return;
+
+        ent.Comp.HitWhileThrown = false;
+        ent.Comp.ThrowOnCooldown = false;
+
+        DirtyField(ent, ent.Comp, nameof(MeleeThrowOnHitComponent.HitWhileThrown));
+        DirtyField(ent, ent.Comp, nameof(MeleeThrowOnHitComponent.ThrowOnCooldown));
+    }
+
+    private void OnLand(Entity<MeleeThrowOnHitComponent> ent, ref LandEvent args)
+    {
+        if (ent.Comp.HitWhileThrown && !_delay.IsDelayed(ent.Owner))
+            _delay.TryResetDelay(ent.Owner);
+
+        ent.Comp.ThrowOnCooldown = true;
+        DirtyField(ent, ent.Comp, nameof(MeleeThrowOnHitComponent.ThrowOnCooldown));
     }
 
     private void OnMeleeHit(Entity<MeleeThrowOnHitComponent> weapon, ref MeleeHitEvent args)
@@ -50,9 +73,15 @@ public sealed class MeleeThrowOnHitSystem : EntitySystem
         if (!weapon.Comp.ActivateOnThrown)
             return;
 
+        if (weapon.Comp.ThrowOnCooldown)
+            return;
+
         if (!TryComp<PhysicsComponent>(args.Thrown, out var weaponPhysics))
             return;
 
+        weapon.Comp.HitWhileThrown = true;
+        DirtyField(weapon, weapon.Comp, nameof(MeleeThrowOnHitComponent.HitWhileThrown));
+
         ThrowOnHitHelper(weapon, args.Component.Thrower, args.Target, weaponPhysics.LinearVelocity);
     }