Ensure grappled entities cleanup grapples when they crit/die (#4546)

* Ensure grappled entities cleanup grapples when they crit/die
This commit is contained in:
BarryNorfolk 2025-11-15 00:32:06 +01:00 committed by GitHub
parent 35cfe960ab
commit 150af3cc6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 0 deletions

View File

@ -57,6 +57,7 @@ public sealed partial class GrapplingSystem : SharedGrapplingSystem
SubscribeLocalEvent<GrapplerComponent, EscapeGrappleAlertEvent>(OnEscapeGrapplerAlert);
SubscribeLocalEvent<GrapplerComponent, MobStateChangedEvent>(OnGrapplerStateChanged);
SubscribeLocalEvent<GrappledComponent, MobStateChangedEvent>(OnGrappledStateChanged);
SubscribeLocalEvent<GrappledComponent, MoveInputEvent>(OnGrappledMove);
SubscribeLocalEvent<GrappledComponent, GrappledEscapeDoAfter>(OnEscapeDoAfter);
SubscribeLocalEvent<GrappledComponent, EscapeGrappleAlertEvent>(OnEscapeGrappledAlert);
@ -429,6 +430,24 @@ public sealed partial class GrapplingSystem : SharedGrapplingSystem
}
}
/// <summary>
/// Handles when a grappled entity enters crit or dies while being held by a grappler, releasing the
/// grappler for them.
/// </summary>
/// <param name="grappled">Grappled entity which has entered crit or death.</param>
/// <param name="args">Args for the event.</param>
private void OnGrappledStateChanged(Entity<GrappledComponent> grappled, ref MobStateChangedEvent args)
{
if (grappled.Comp.Grappler == EntityUid.Invalid)
return;
if (args.NewMobState == MobState.Critical ||
args.NewMobState == MobState.Dead)
{
ReleaseGrapple(grappled.Comp.Grappler, manualRelease: true);
}
}
/// <summary>
/// Handles releasing the effects of a grapple from both entities.
/// </summary>