diff --git a/Content.Shared/Throwing/ThrownItemComponent.cs b/Content.Shared/Throwing/ThrownItemComponent.cs index eb23ba0994..c6c9c4a446 100644 --- a/Content.Shared/Throwing/ThrownItemComponent.cs +++ b/Content.Shared/Throwing/ThrownItemComponent.cs @@ -4,48 +4,51 @@ using Robust.Shared.Timing; namespace Content.Shared.Throwing { - [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] + [RegisterComponent, NetworkedComponent] public sealed partial class ThrownItemComponent : Component { /// /// The entity that threw this entity. /// - [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] - public EntityUid? Thrower { get; set; } + [DataField, ViewVariables(VVAccess.ReadWrite)] + public EntityUid? Thrower; /// /// The timestamp at which this entity was thrown. /// - [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] - public TimeSpan? ThrownTime { get; set; } + [DataField, ViewVariables(VVAccess.ReadWrite)] + public TimeSpan? ThrownTime; /// /// Compared to to land this entity, if any. /// - [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] - public TimeSpan? LandTime { get; set; } + [DataField, ViewVariables(VVAccess.ReadWrite)] + public TimeSpan? LandTime; /// /// Whether or not this entity was already landed. /// - [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] - public bool Landed { get; set; } + [DataField, ViewVariables(VVAccess.ReadWrite)] + public bool Landed; /// /// Whether or not to play a sound when the entity lands. /// - [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; } } diff --git a/Content.Shared/Throwing/ThrownItemSystem.cs b/Content.Shared/Throwing/ThrownItemSystem.cs index ec29bf7ee5..9b7ba3ebb0 100644 --- a/Content.Shared/Throwing/ThrownItemSystem.cs +++ b/Content.Shared/Throwing/ThrownItemSystem.cs @@ -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(PreventCollision); SubscribeLocalEvent(ThrowItem); SubscribeLocalEvent(OnThrownUnpaused); + SubscribeLocalEvent(OnThrownGetState); + SubscribeLocalEvent(OnThrownHandleState); + SubscribeLocalEvent(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,7 +134,9 @@ namespace Content.Shared.Throwing if (TryComp(uid, out var physics)) { _physics.SetBodyStatus(physics, BodyStatus.OnGround); - _broadphase.RegenerateContacts(uid, physics); + + if (physics.Awake) + _broadphase.RegenerateContacts(uid, physics); } if (EntityManager.TryGetComponent(uid, out FixturesComponent? manager))