From: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Date: Wed, 16 Jul 2025 20:27:21 +0000 (+0200)
Subject: Fix Mjollnir throw while on delay (#39018)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=975ebac202deb696d1cfb9e6903e1eed62485786;p=space-station-14.git
Fix Mjollnir throw while on delay (#39018)
* init
* fuck dirty
* yippee
---
diff --git a/Content.Shared/Weapons/Melee/Components/MeleeThrowOnHitComponent.cs b/Content.Shared/Weapons/Melee/Components/MeleeThrowOnHitComponent.cs
index 84e75129b1..42b72efede 100644
--- a/Content.Shared/Weapons/Melee/Components/MeleeThrowOnHitComponent.cs
+++ b/Content.Shared/Weapons/Melee/Components/MeleeThrowOnHitComponent.cs
@@ -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.
///
-[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
///
[DataField, AutoNetworkedField]
public bool ActivateOnThrown;
+
+ ///
+ /// Whether the entity can apply knockback this instance of being thrown.
+ /// If true, the entity cannot apply knockback.
+ ///
+ [DataField, AutoNetworkedField]
+ [ViewVariables(VVAccess.ReadOnly)]
+ public bool ThrowOnCooldown;
+
+ ///
+ /// Whether this item has hit anyone while it was thrown.
+ ///
+ [DataField, AutoNetworkedField]
+ [ViewVariables(VVAccess.ReadOnly)]
+ public bool HitWhileThrown;
}
///
diff --git a/Content.Shared/Weapons/Melee/MeleeThrowOnHitSystem.cs b/Content.Shared/Weapons/Melee/MeleeThrowOnHitSystem.cs
index 035432ef85..eaaf336e96 100644
--- a/Content.Shared/Weapons/Melee/MeleeThrowOnHitSystem.cs
+++ b/Content.Shared/Weapons/Melee/MeleeThrowOnHitSystem.cs
@@ -22,6 +22,29 @@ public sealed class MeleeThrowOnHitSystem : EntitySystem
{
SubscribeLocalEvent(OnMeleeHit);
SubscribeLocalEvent(OnThrowHit);
+ SubscribeLocalEvent(OnThrow);
+ SubscribeLocalEvent(OnLand);
+ }
+
+ private void OnThrow(Entity 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 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 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(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);
}