Fix throwing asserts (#23562)
* Fix throwing bad regencontacts call Throwing needs throwing out the window but this stops it causing problems with anomalies. * Bandaid throwing
This commit is contained in:
@@ -4,48 +4,51 @@ using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Throwing
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class ThrownItemComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity that threw this entity.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public EntityUid? Thrower { get; set; }
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public EntityUid? Thrower;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IGameTiming.CurTime"/> timestamp at which this entity was thrown.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public TimeSpan? ThrownTime { get; set; }
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan? ThrownTime;
|
||||
|
||||
/// <summary>
|
||||
/// Compared to <see cref="IGameTiming.CurTime"/> to land this entity, if any.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public TimeSpan? LandTime { get; set; }
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan? LandTime;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this entity was already landed.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool Landed { get; set; }
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Landed;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to play a sound when the entity lands.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool PlayLandSound { get; set; }
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool PlayLandSound;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ThrownItemComponentState : ComponentState
|
||||
{
|
||||
public NetEntity? Thrower { get; }
|
||||
public NetEntity? Thrower;
|
||||
|
||||
public ThrownItemComponentState(NetEntity? thrower)
|
||||
{
|
||||
Thrower = thrower;
|
||||
}
|
||||
public TimeSpan? ThrownTime;
|
||||
|
||||
public TimeSpan? LandTime;
|
||||
|
||||
public bool Landed;
|
||||
|
||||
public bool PlayLandSound;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Shared.Database;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
@@ -35,9 +36,41 @@ namespace Content.Shared.Throwing
|
||||
SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
|
||||
SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
|
||||
SubscribeLocalEvent<ThrownItemComponent, EntityUnpausedEvent>(OnThrownUnpaused);
|
||||
SubscribeLocalEvent<ThrownItemComponent, ComponentGetState>(OnThrownGetState);
|
||||
SubscribeLocalEvent<ThrownItemComponent, ComponentHandleState>(OnThrownHandleState);
|
||||
|
||||
SubscribeLocalEvent<PullStartedMessage>(HandlePullStarted);
|
||||
}
|
||||
|
||||
private void OnThrownGetState(EntityUid uid, ThrownItemComponent component, ref ComponentGetState args)
|
||||
{
|
||||
// TODO: Throwing needs to handle this properly I just want the bad asserts to stop getting in my way.
|
||||
TryGetNetEntity(component.Thrower, out var nent);
|
||||
|
||||
args.State = new ThrownItemComponentState()
|
||||
{
|
||||
ThrownTime = component.ThrownTime,
|
||||
LandTime = component.LandTime,
|
||||
Thrower = nent,
|
||||
Landed = component.Landed,
|
||||
PlayLandSound = component.PlayLandSound,
|
||||
};
|
||||
}
|
||||
|
||||
private void OnThrownHandleState(EntityUid uid, ThrownItemComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not ThrownItemComponentState state)
|
||||
return;
|
||||
|
||||
TryGetEntity(state.Thrower, out var thrower);
|
||||
|
||||
component.ThrownTime = state.ThrownTime;
|
||||
component.LandTime = state.LandTime;
|
||||
component.Thrower = thrower;
|
||||
component.Landed = state.Landed;
|
||||
component.PlayLandSound = state.PlayLandSound;
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, ThrownItemComponent component, MapInitEvent args)
|
||||
{
|
||||
component.ThrownTime ??= _gameTiming.CurTime;
|
||||
@@ -86,7 +119,6 @@ namespace Content.Shared.Throwing
|
||||
|
||||
private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
|
||||
{
|
||||
@event.Cancelled = true;
|
||||
StopThrow(uid, thrownItem);
|
||||
}
|
||||
|
||||
@@ -102,6 +134,8 @@ namespace Content.Shared.Throwing
|
||||
if (TryComp<PhysicsComponent>(uid, out var physics))
|
||||
{
|
||||
_physics.SetBodyStatus(physics, BodyStatus.OnGround);
|
||||
|
||||
if (physics.Awake)
|
||||
_broadphase.RegenerateContacts(uid, physics);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user