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
|
namespace Content.Shared.Throwing
|
||||||
{
|
{
|
||||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public sealed partial class ThrownItemComponent : Component
|
public sealed partial class ThrownItemComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The entity that threw this entity.
|
/// The entity that threw this entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public EntityUid? Thrower { get; set; }
|
public EntityUid? Thrower;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="IGameTiming.CurTime"/> timestamp at which this entity was thrown.
|
/// The <see cref="IGameTiming.CurTime"/> timestamp at which this entity was thrown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan? ThrownTime { get; set; }
|
public TimeSpan? ThrownTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compared to <see cref="IGameTiming.CurTime"/> to land this entity, if any.
|
/// Compared to <see cref="IGameTiming.CurTime"/> to land this entity, if any.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan? LandTime { get; set; }
|
public TimeSpan? LandTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not this entity was already landed.
|
/// Whether or not this entity was already landed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool Landed { get; set; }
|
public bool Landed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not to play a sound when the entity lands.
|
/// Whether or not to play a sound when the entity lands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool PlayLandSound { get; set; }
|
public bool PlayLandSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ThrownItemComponentState : ComponentState
|
public sealed class ThrownItemComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public NetEntity? Thrower { get; }
|
public NetEntity? Thrower;
|
||||||
|
|
||||||
public ThrownItemComponentState(NetEntity? thrower)
|
public TimeSpan? ThrownTime;
|
||||||
{
|
|
||||||
Thrower = thrower;
|
public TimeSpan? LandTime;
|
||||||
}
|
|
||||||
|
public bool Landed;
|
||||||
|
|
||||||
|
public bool PlayLandSound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Shared.Database;
|
|||||||
using Content.Shared.Gravity;
|
using Content.Shared.Gravity;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Content.Shared.Physics.Pull;
|
using Content.Shared.Physics.Pull;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Events;
|
using Robust.Shared.Physics.Events;
|
||||||
@@ -35,9 +36,41 @@ namespace Content.Shared.Throwing
|
|||||||
SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
|
SubscribeLocalEvent<ThrownItemComponent, PreventCollideEvent>(PreventCollision);
|
||||||
SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
|
SubscribeLocalEvent<ThrownItemComponent, ThrownEvent>(ThrowItem);
|
||||||
SubscribeLocalEvent<ThrownItemComponent, EntityUnpausedEvent>(OnThrownUnpaused);
|
SubscribeLocalEvent<ThrownItemComponent, EntityUnpausedEvent>(OnThrownUnpaused);
|
||||||
|
SubscribeLocalEvent<ThrownItemComponent, ComponentGetState>(OnThrownGetState);
|
||||||
|
SubscribeLocalEvent<ThrownItemComponent, ComponentHandleState>(OnThrownHandleState);
|
||||||
|
|
||||||
SubscribeLocalEvent<PullStartedMessage>(HandlePullStarted);
|
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)
|
private void OnMapInit(EntityUid uid, ThrownItemComponent component, MapInitEvent args)
|
||||||
{
|
{
|
||||||
component.ThrownTime ??= _gameTiming.CurTime;
|
component.ThrownTime ??= _gameTiming.CurTime;
|
||||||
@@ -86,7 +119,6 @@ namespace Content.Shared.Throwing
|
|||||||
|
|
||||||
private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
|
private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
|
||||||
{
|
{
|
||||||
@event.Cancelled = true;
|
|
||||||
StopThrow(uid, thrownItem);
|
StopThrow(uid, thrownItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +134,8 @@ namespace Content.Shared.Throwing
|
|||||||
if (TryComp<PhysicsComponent>(uid, out var physics))
|
if (TryComp<PhysicsComponent>(uid, out var physics))
|
||||||
{
|
{
|
||||||
_physics.SetBodyStatus(physics, BodyStatus.OnGround);
|
_physics.SetBodyStatus(physics, BodyStatus.OnGround);
|
||||||
|
|
||||||
|
if (physics.Awake)
|
||||||
_broadphase.RegenerateContacts(uid, physics);
|
_broadphase.RegenerateContacts(uid, physics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user