From 7efd457a5124c307552c15b7239a080e9d9af6e5 Mon Sep 17 00:00:00 2001 From: haiwwkes <49613070+rhailrake@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:39:38 +0500 Subject: [PATCH] fix (#534) --- .../Buckle/SharedBuckleSystem.Buckle.cs | 2 +- .../Standing/SharedLayingDownSystem.cs | 14 ++- .../Standing/StandingStateSystem.cs | 107 ++++++++---------- 3 files changed, 56 insertions(+), 67 deletions(-) diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs index 8d04c9dcac..b8b94b130f 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs @@ -380,7 +380,7 @@ public abstract partial class SharedBuckleSystem _standing.Stand(buckle, force: true); break; case StrapPosition.Down: - _standing.Down(buckle, false, false); + _standing.Down(buckle, false, false, force:true); break; } diff --git a/Content.Shared/Standing/SharedLayingDownSystem.cs b/Content.Shared/Standing/SharedLayingDownSystem.cs index 077d1dadd0..fb1f39c2fa 100644 --- a/Content.Shared/Standing/SharedLayingDownSystem.cs +++ b/Content.Shared/Standing/SharedLayingDownSystem.cs @@ -74,10 +74,13 @@ public abstract class SharedLayingDownSystem : EntitySystem private void OnStandingUpDoAfter(EntityUid uid, StandingStateComponent component, StandingUpDoAfterEvent args) { if (args.Handled || args.Cancelled - || HasComp(uid) - || _mobState.IsIncapacitated(uid) - || !_standing.Stand(uid)) + || HasComp(uid) + || _mobState.IsIncapacitated(uid) + || !_standing.Stand(uid)) + { component.CurrentState = StandingState.Lying; + return; + } component.CurrentState = StandingState.Standing; } @@ -127,7 +130,8 @@ public abstract class SharedLayingDownSystem : EntitySystem { if (!Resolve(uid, ref standingState, false) || !Resolve(uid, ref layingDown, false) - || standingState.CurrentState is not StandingState.Standing) + || standingState.CurrentState is not StandingState.Standing + || _standing.IsDown(uid)) { if (behavior == DropHeldItemsBehavior.AlwaysDrop) RaiseLocalEvent(uid, new DropHandItemsEvent()); @@ -135,7 +139,7 @@ public abstract class SharedLayingDownSystem : EntitySystem return false; } - _standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, standingState); + _standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, standingState: standingState); return true; } } diff --git a/Content.Shared/Standing/StandingStateSystem.cs b/Content.Shared/Standing/StandingStateSystem.cs index 61836b4c28..6b737d90a3 100644 --- a/Content.Shared/Standing/StandingStateSystem.cs +++ b/Content.Shared/Standing/StandingStateSystem.cs @@ -18,7 +18,6 @@ namespace Content.Shared.Standing [Dependency] private readonly MovementSpeedModifierSystem _movement = default!; [Dependency] private readonly SharedBuckleSystem _buckle = default!; - // If StandingCollisionLayer value is ever changed to more than one layer, the logic needs to be edited. private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable; public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null) @@ -32,44 +31,54 @@ namespace Content.Shared.Standing public bool Down(EntityUid uid, bool playSound = true, bool dropHeldItems = true, + bool force = false, StandingStateComponent? standingState = null, AppearanceComponent? appearance = null, - HandsComponent? hands = null) + HandsComponent? hands = null, + LayingDownComponent? layingDown = null) { - // TODO: This should actually log missing comps... if (!Resolve(uid, ref standingState, false)) return false; - // Optional component. - Resolve(uid, ref appearance, ref hands, false); + // Optional components + Resolve(uid, ref appearance, ref hands, ref layingDown, false); - if (standingState.CurrentState is StandingState.Lying or StandingState.GettingUp) + if (standingState.CurrentState is StandingState.Lying) return true; - // This is just to avoid most callers doing this manually saving boilerplate - // 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to. - // We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway - // and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent. + // Even if we're getting up, we want to reset to lying down + if (standingState.CurrentState is StandingState.GettingUp) + { + standingState.CurrentState = StandingState.Lying; + Dirty(uid, standingState); + return true; + } + if (dropHeldItems && hands != null) RaiseLocalEvent(uid, new DropHandItemsEvent(), false); - if (TryComp(uid, out BuckleComponent? buckle) && buckle.Buckled && !_buckle.TryUnbuckle(uid, uid, buckleComp: buckle)) - return false; + // Only check buckle if we're not forcing + if (!force) + { + if (TryComp(uid, out BuckleComponent? buckle) && + buckle.Buckled && + !_buckle.TryUnbuckle(uid, uid, buckleComp: buckle)) + return false; - var msg = new DownAttemptEvent(); - RaiseLocalEvent(uid, msg, false); + var msg = new DownAttemptEvent(); + RaiseLocalEvent(uid, msg, false); - if (msg.Cancelled) - return false; + if (msg.Cancelled) + return false; + } standingState.CurrentState = StandingState.Lying; + Dirty(uid, standingState); RaiseLocalEvent(uid, new DownedEvent(), false); - // Seemed like the best place to put it _appearance.SetData(uid, RotationVisuals.RotationState, RotationState.Horizontal, appearance); - // Change collision masks to allow going under certain entities like flaps and tables if (TryComp(uid, out FixturesComponent? fixtureComponent)) { foreach (var (key, fixture) in fixtureComponent.Fixtures) @@ -82,12 +91,7 @@ namespace Content.Shared.Standing } } - // check if component was just added or streamed to client - // if true, no need to play sound - mob was down before player could seen that - if (standingState.LifeStage <= ComponentLifeStage.Starting) - return true; - - if (playSound) + if (standingState.LifeStage > ComponentLifeStage.Starting && playSound) _audio.PlayPredicted(standingState.DownSound, uid, null); _movement.RefreshMovementSpeedModifiers(uid); @@ -97,20 +101,27 @@ namespace Content.Shared.Standing public bool Stand(EntityUid uid, StandingStateComponent? standingState = null, AppearanceComponent? appearance = null, + LayingDownComponent? layingDown = null, bool force = false) { - // TODO: This should actually log missing comps... if (!Resolve(uid, ref standingState, false)) return false; - // Optional component. - Resolve(uid, ref appearance, false); + Resolve(uid, ref appearance, ref layingDown, false); - if (standingState.CurrentState is StandingState.Standing - || TryComp(uid, out BuckleComponent? buckle) - && buckle.Buckled && !_buckle.TryUnbuckle(uid, uid, buckleComp: buckle)) + // Already standing + if (standingState.CurrentState is StandingState.Standing) return true; + if (!force && TryComp(uid, out BuckleComponent? buckle)) + { + if (buckle.Buckled) + { + if (!_buckle.TryUnbuckle(uid, uid, buckleComp: buckle)) + return false; + } + } + if (!force) { var msg = new StandAttemptEvent(); @@ -141,35 +152,9 @@ namespace Content.Shared.Standing } } - public sealed class DropHandItemsEvent : EventArgs - { - } - - /// - /// Subscribe if you can potentially block a down attempt. - /// - public sealed class DownAttemptEvent : CancellableEntityEventArgs - { - } - - /// - /// Subscribe if you can potentially block a stand attempt. - /// - public sealed class StandAttemptEvent : CancellableEntityEventArgs - { - } - - /// - /// Raised when an entity becomes standing - /// - public sealed class StoodEvent : EntityEventArgs - { - } - - /// - /// Raised when an entity is not standing - /// - public sealed class DownedEvent : EntityEventArgs - { - } + public sealed class DropHandItemsEvent : EventArgs { } + public sealed class DownAttemptEvent : CancellableEntityEventArgs { } + public sealed class StandAttemptEvent : CancellableEntityEventArgs { } + public sealed class StoodEvent : EntityEventArgs { } + public sealed class DownedEvent : EntityEventArgs { } }