fix (#534)
This commit is contained in:
parent
eaf8b9dae2
commit
7efd457a51
3 changed files with 56 additions and 67 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,10 +74,13 @@ public abstract class SharedLayingDownSystem : EntitySystem
|
|||
private void OnStandingUpDoAfter(EntityUid uid, StandingStateComponent component, StandingUpDoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled
|
||||
|| HasComp<KnockedDownComponent>(uid)
|
||||
|| _mobState.IsIncapacitated(uid)
|
||||
|| !_standing.Stand(uid))
|
||||
|| HasComp<KnockedDownComponent>(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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a down attempt.
|
||||
/// </summary>
|
||||
public sealed class DownAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a stand attempt.
|
||||
/// </summary>
|
||||
public sealed class StandAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity becomes standing
|
||||
/// </summary>
|
||||
public sealed class StoodEvent : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity is not standing
|
||||
/// </summary>
|
||||
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 { }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue