Limit hydraulic clamps to one DoAfter at a time (#23982)

Limit Ripleys to one DoAfter at a time
This commit is contained in:
themias
2024-01-12 15:33:47 -05:00
committed by GitHub
parent f5c40c3623
commit f8f5524fd5
2 changed files with 13 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
using System.Numerics; using System.Numerics;
using System.Threading; using System.Threading;
using Content.Shared.DoAfter;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -47,4 +48,7 @@ public sealed partial class MechGrabberComponent : Component
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public Container ItemContainer = default!; public Container ItemContainer = default!;
[DataField, ViewVariables(VVAccess.ReadOnly)]
public DoAfterId? DoAfter;
} }

View File

@@ -128,6 +128,9 @@ public sealed class MechGrabberSystem : EntitySystem
if (args.Handled || args.Target is not {} target) if (args.Handled || args.Target is not {} target)
return; return;
if (args.Target == args.User || component.DoAfter != null)
return;
if (TryComp<PhysicsComponent>(target, out var physics) && physics.BodyType == BodyType.Static || if (TryComp<PhysicsComponent>(target, out var physics) && physics.BodyType == BodyType.Static ||
HasComp<WallMountComponent>(target) || HasComp<WallMountComponent>(target) ||
HasComp<MobStateComponent>(target)) HasComp<MobStateComponent>(target))
@@ -152,15 +155,19 @@ public sealed class MechGrabberSystem : EntitySystem
args.Handled = true; args.Handled = true;
component.AudioStream = _audio.PlayPvs(component.GrabSound, uid).Value.Entity; component.AudioStream = _audio.PlayPvs(component.GrabSound, uid).Value.Entity;
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.GrabDelay, new GrabberDoAfterEvent(), uid, target: target, used: uid) var doAfterArgs = new DoAfterArgs(EntityManager, args.User, component.GrabDelay, new GrabberDoAfterEvent(), uid, target: target, used: uid)
{ {
BreakOnTargetMove = true, BreakOnTargetMove = true,
BreakOnUserMove = true BreakOnUserMove = true
}); };
_doAfter.TryStartDoAfter(doAfterArgs, out component.DoAfter);
} }
private void OnMechGrab(EntityUid uid, MechGrabberComponent component, DoAfterEvent args) private void OnMechGrab(EntityUid uid, MechGrabberComponent component, DoAfterEvent args)
{ {
component.DoAfter = null;
if (args.Cancelled) if (args.Cancelled)
{ {
component.AudioStream = _audio.Stop(component.AudioStream); component.AudioStream = _audio.Stop(component.AudioStream);