using System.Numerics;
using Content.Shared.Alert;
using Content.Shared.Buckle.Components;
+using Content.Shared.Cuffs.Components;
using Content.Shared.Database;
+using Content.Shared.DoAfter;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Movement.Events;
SubscribeLocalEvent<BuckleComponent, ThrowPushbackAttemptEvent>(OnBuckleThrowPushbackAttempt);
SubscribeLocalEvent<BuckleComponent, UpdateCanMoveEvent>(OnBuckleUpdateCanMove);
+ SubscribeLocalEvent<BuckleComponent, BuckleDoAfterEvent>(OnBuckleDoafter);
+ SubscribeLocalEvent<BuckleComponent, DoAfterAttemptEvent<BuckleDoAfterEvent>>((uid, comp, ev) =>
+ {
+ BuckleDoafterEarly((uid, comp), ev.Event, ev);
+ });
+
SubscribeLocalEvent<BuckleComponent, ComponentGetState>(OnGetState);
}
RaiseLocalEvent(strap, ref unstrapAttempt);
return !unstrapAttempt.Cancelled;
}
+
+ /// <summary>
+ /// Once the do-after is complete, try to buckle target to chair/bed
+ /// </summary>
+ /// <param name="args.Target"> The person being put in the chair/bed</param>
+ /// <param name="args.User"> The person putting a person in a chair/bed</param>
+ /// <param name="args.Used"> The chair/bed </param>
+
+ private void OnBuckleDoafter(Entity<BuckleComponent> entity, ref BuckleDoAfterEvent args)
+ {
+ if (args.Cancelled || args.Handled || args.Target == null || args.Used == null)
+ return;
+
+ args.Handled = TryBuckle(args.Target.Value, args.User, args.Used.Value, popup: false);
+ }
+
+ /// <summary>
+ /// If the target being buckled to a chair/bed goes crit or is cuffed
+ /// Cancel the do-after time and try to buckle the target immediately
+ /// </summary>
+ /// <param name="args.Target"> The person being put in the chair/bed</param>
+ /// <param name="args.User"> The person putting a person in a chair/bed</param>
+ /// <param name="args.Used"> The chair/bed </param>
+ private void BuckleDoafterEarly(Entity<BuckleComponent> entity, BuckleDoAfterEvent args, CancellableEntityEventArgs ev)
+ {
+ if (args.Target == null || args.Used == null)
+ return;
+
+ if (TryComp<CuffableComponent>(args.Target, out var targetCuffableComp) && targetCuffableComp.CuffedHandCount > 0
+ || _mobState.IsIncapacitated(args.Target.Value))
+ {
+ ev.Cancel();
+ TryBuckle(args.Target.Value, args.User, args.Used.Value, popup: false);
+ }
+ }
}
-using Content.Shared.Buckle.Components;
+using Content.Shared.Buckle.Components;
+using Content.Shared.Cuffs.Components;
+using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
if (!StrapCanDragDropOn(uid, args.User, uid, args.Dragged, component))
return;
- args.Handled = TryBuckle(args.Dragged, args.User, uid, popup: false);
+ if (args.Dragged == args.User)
+ {
+ if (!TryComp(args.User, out BuckleComponent? buckle))
+ return;
+
+ args.Handled = TryBuckle(args.User, args.User, uid, buckle);
+ }
+ else
+ {
+ var doAfterArgs = new DoAfterArgs(EntityManager, args.User, component.BuckleDoafterTime, new BuckleDoAfterEvent(), args.User, args.Dragged, uid)
+ {
+ BreakOnMove = true,
+ BreakOnDamage = true,
+ AttemptFrequency = AttemptFrequency.EveryTick
+ };
+
+ _doAfter.TryStartDoAfter(doAfterArgs);
+ }
}
private bool StrapCanDragDropOn(
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
+using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedRotationVisualsSystem _rotationVisuals = default!;
+ [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
/// <inheritdoc/>
public override void Initialize()