Fix Mjollnir throw while on delay (#39018)
* init * fuck dirty * yippee
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user