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:
11
Content.Shared/Buckle/BuckleDoafterEvent.cs
Normal file
11
Content.Shared/Buckle/BuckleDoafterEvent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Content.Shared.Cuffs.Components;
|
||||
using Content.Shared.DoAfter;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Buckle;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class BuckleDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -84,6 +84,12 @@ public sealed partial class StrapComponent : Component
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<AlertPrototype> BuckledAlertType = "Buckled";
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to buckle someone else into a chair
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float BuckleDoafterTime = 2f;
|
||||
}
|
||||
|
||||
public enum StrapPosition
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
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;
|
||||
@@ -32,7 +34,24 @@ public abstract partial class SharedBuckleSystem
|
||||
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(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -36,6 +37,7 @@ public abstract partial class SharedBuckleSystem : EntitySystem
|
||||
[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()
|
||||
|
||||
Reference in New Issue
Block a user