Buckling an entity requires a do-after (#29621)
* Buckling an entity requires a do-after * Works but feels like bad code? * Cleanup --------- Co-authored-by: plykiya <plykiya@protonmail.com>
This commit is contained in:
@@ -2,7 +2,9 @@ using System.Diagnostics.CodeAnalysis;
|
||||
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;
|
||||
@@ -51,6 +53,12 @@ public abstract partial class SharedBuckleSystem
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -516,4 +524,39 @@ public abstract partial class SharedBuckleSystem
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user