Move moving unbuckling to update to avoid an event bus concurrent modification exception (#1509)

This commit is contained in:
DrSmugleaf
2020-07-28 08:37:03 +02:00
committed by GitHub
parent 264062cd15
commit bd7079278e
3 changed files with 69 additions and 33 deletions

View File

@@ -13,34 +13,6 @@ namespace Content.Server.GameObjects.EntitySystems
[UsedImplicitly]
public class BuckleSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
#pragma warning restore 649
/// <summary>
/// Checks if a buckled entity should be unbuckled from moving
/// too far from its strap.
/// </summary>
/// <param name="moveEvent">The move event of a buckled entity.</param>
private void MoveEvent(MoveEvent moveEvent)
{
if (!moveEvent.Sender.TryGetComponent(out BuckleComponent buckle) ||
buckle.BuckledTo == null ||
!buckle.BuckleOffset.HasValue)
{
return;
}
var bucklePosition = buckle.BuckledTo.Owner.Transform.GridPosition.Offset(buckle.BuckleOffset.Value);
if (moveEvent.NewPosition.InRange(_mapManager, bucklePosition, 0.2f))
{
return;
}
buckle.TryUnbuckle(buckle.Owner, true);
}
public override void Initialize()
{
base.Initialize();
@@ -49,8 +21,6 @@ namespace Content.Server.GameObjects.EntitySystems
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
SubscribeLocalEvent<MoveEvent>(MoveEvent);
}
public override void Update(float frameTime)