Improve pulling error logs (#10762)
This commit is contained in:
@@ -40,49 +40,6 @@ namespace Content.Shared.Pulling.Components
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public bool PrevFixedRotation;
|
public bool PrevFixedRotation;
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
|
||||||
{
|
|
||||||
return new PullableComponentState(Puller);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
||||||
{
|
|
||||||
base.HandleComponentState(curState, nextState);
|
|
||||||
|
|
||||||
if (curState is not PullableComponentState state)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.Puller.HasValue)
|
|
||||||
{
|
|
||||||
EntitySystem.Get<SharedPullingStateManagementSystem>().ForceDisconnectPullable(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.Puller.Value.IsValid())
|
|
||||||
{
|
|
||||||
Logger.Error($"Invalid entity {state.Puller.Value} for pulling");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Puller == state.Puller)
|
|
||||||
{
|
|
||||||
// don't disconnect and reconnect a puller for no reason
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedPullerComponent?>(state.Puller.Value, out var comp))
|
|
||||||
{
|
|
||||||
Logger.Error($"Entity {state.Puller.Value} for pulling had no Puller component");
|
|
||||||
// ensure it disconnects from any different puller, still
|
|
||||||
EntitySystem.Get<SharedPullingStateManagementSystem>().ForceDisconnectPullable(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntitySystem.Get<SharedPullingStateManagementSystem>().ForceRelationship(comp, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnRemove()
|
protected override void OnRemove()
|
||||||
{
|
{
|
||||||
if (Puller != null)
|
if (Puller != null)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Linq;
|
|||||||
using Content.Shared.Physics.Pull;
|
using Content.Shared.Physics.Pull;
|
||||||
using Content.Shared.Pulling.Components;
|
using Content.Shared.Pulling.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -24,6 +25,41 @@ namespace Content.Shared.Pulling
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<SharedPullableComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<SharedPullableComponent, ComponentShutdown>(OnShutdown);
|
||||||
|
SubscribeLocalEvent<SharedPullableComponent, ComponentGetState>(OnGetState);
|
||||||
|
SubscribeLocalEvent<SharedPullableComponent, ComponentHandleState>(OnHandleState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGetState(EntityUid uid, SharedPullableComponent component, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new PullableComponentState(component.Puller);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHandleState(EntityUid uid, SharedPullableComponent component, ref ComponentHandleState args)
|
||||||
|
{
|
||||||
|
if (args.Current is not PullableComponentState state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!state.Puller.HasValue)
|
||||||
|
{
|
||||||
|
ForceDisconnectPullable(component);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.Puller == state.Puller)
|
||||||
|
{
|
||||||
|
// don't disconnect and reconnect a puller for no reason
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryComp<SharedPullerComponent?>(state.Puller.Value, out var comp))
|
||||||
|
{
|
||||||
|
Logger.Error($"Pullable state for entity {ToPrettyString(uid)} had invalid puller entity {ToPrettyString(state.Puller.Value)}");
|
||||||
|
// ensure it disconnects from any different puller, still
|
||||||
|
ForceDisconnectPullable(component);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ForceRelationship(comp, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShutdown(EntityUid uid, SharedPullableComponent component, ComponentShutdown args)
|
private void OnShutdown(EntityUid uid, SharedPullableComponent component, ComponentShutdown args)
|
||||||
|
|||||||
Reference in New Issue
Block a user