diff --git a/Content.Shared/Climbing/Components/ClimbingComponent.cs b/Content.Shared/Climbing/Components/ClimbingComponent.cs index 1ab861b1f7..df4632d8f7 100644 --- a/Content.Shared/Climbing/Components/ClimbingComponent.cs +++ b/Content.Shared/Climbing/Components/ClimbingComponent.cs @@ -1,3 +1,4 @@ +using Content.Shared.DoAfter; using System.Numerics; using Robust.Shared.GameStates; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; @@ -25,6 +26,12 @@ public sealed partial class ClimbingComponent : Component [AutoNetworkedField, DataField] public bool IsClimbing; + /// + /// The Climbing DoAfter. + /// + [DataField] + public DoAfterId? DoAfter; + /// /// Whether the owner is being moved onto the climbed entity. /// diff --git a/Content.Shared/Climbing/Systems/ClimbSystem.cs b/Content.Shared/Climbing/Systems/ClimbSystem.cs index 467d96187e..f8f2ffda88 100644 --- a/Content.Shared/Climbing/Systems/ClimbSystem.cs +++ b/Content.Shared/Climbing/Systems/ClimbSystem.cs @@ -62,6 +62,7 @@ public sealed partial class ClimbSystem : VirtualController SubscribeLocalEvent(OnDoAfter); SubscribeLocalEvent(OnClimbEndCollide); SubscribeLocalEvent(OnBuckled); + SubscribeLocalEvent(OnStored); SubscribeLocalEvent(OnCanDragDropOn); SubscribeLocalEvent>(AddClimbableVerb); @@ -234,14 +235,28 @@ public sealed partial class ClimbSystem : VirtualController }; _audio.PlayPredicted(comp.StartClimbSound, climbable, user); - return _doAfterSystem.TryStartDoAfter(args, out id); + var success = _doAfterSystem.TryStartDoAfter(args, out id); + + if (success) + climbing.DoAfter = id; + + return success; + } private void OnDoAfter(EntityUid uid, ClimbingComponent component, ClimbDoAfterEvent args) { + component.DoAfter = null; + if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null) return; + if (_containers.IsEntityInContainer(uid)) + { + args.Handled = true; + return; + } + Climb(uid, args.Args.User, args.Args.Target.Value, climbing: component); args.Handled = true; } @@ -520,7 +535,27 @@ public sealed partial class ClimbSystem : VirtualController private void OnBuckled(EntityUid uid, ClimbingComponent component, ref BuckledEvent args) { - StopClimb(uid, component); + StopOrCancelClimb(uid, component); + } + + private void OnStored(EntityUid uid, ClimbingComponent component, ref EntGotInsertedIntoContainerMessage args) + { + StopOrCancelClimb(uid, component); + } + + private void StopOrCancelClimb(EntityUid uid, ClimbingComponent component) + { + if (component.IsClimbing) + { + StopClimb(uid, component); + return; + } + + if (component.DoAfter != null) + { + _doAfterSystem.Cancel(component.DoAfter); + component.DoAfter = null; + } } private void OnGlassClimbed(EntityUid uid, GlassTableComponent component, ref ClimbedOnEvent args)