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:
metalgearsloth
2024-01-06 13:38:37 +11:00
committed by GitHub
parent 4dc0a5f6ae
commit 8b7bec2f1d
2 changed files with 55 additions and 18 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}