Fix every BuckleComponent subscribing to EventBus when buckled (#2504)

This commit is contained in:
Víctor Aguilera Puerto
2020-11-06 12:38:24 +01:00
committed by GitHub
parent 60dd0de96f
commit 6a469508ca
2 changed files with 19 additions and 6 deletions

View File

@@ -287,9 +287,6 @@ namespace Content.Server.GameObjects.Components.Buckle
SendMessage(new BuckleMessage(Owner, to)); SendMessage(new BuckleMessage(Owner, to));
Owner.EntityManager.EventBus.SubscribeEvent<MoveEvent>(EventSource.Local, this, MoveEvent);
if (Owner.TryGetComponent(out PullableComponent? pullableComponent)) if (Owner.TryGetComponent(out PullableComponent? pullableComponent))
{ {
if (pullableComponent.Puller != null) if (pullableComponent.Puller != null)
@@ -373,8 +370,6 @@ namespace Content.Server.GameObjects.Components.Buckle
SendMessage(new UnbuckleMessage(Owner, oldBuckledTo.Owner)); SendMessage(new UnbuckleMessage(Owner, oldBuckledTo.Owner));
Owner.EntityManager.EventBus.UnsubscribeEvent<MoveEvent>(EventSource.Local, this);
return true; return true;
} }
@@ -407,7 +402,7 @@ namespace Content.Server.GameObjects.Components.Buckle
/// too far from its strap. /// too far from its strap.
/// </summary> /// </summary>
/// <param name="moveEvent">The move event of a buckled entity.</param> /// <param name="moveEvent">The move event of a buckled entity.</param>
private void MoveEvent(MoveEvent moveEvent) public void OnMoveEvent(MoveEvent moveEvent)
{ {
if (moveEvent.Sender != Owner) if (moveEvent.Sender != Owner)
{ {

View File

@@ -2,6 +2,8 @@
using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.GameObjects.EntitySystems.Click;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
@@ -15,6 +17,22 @@ namespace Content.Server.GameObjects.EntitySystems
UpdatesAfter.Add(typeof(InteractionSystem)); UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem)); UpdatesAfter.Add(typeof(InputSystem));
EntityManager.EventBus.SubscribeEvent<MoveEvent>(EventSource.Local, this, MoveEvent);
}
public override void Shutdown()
{
base.Shutdown();
EntityManager.EventBus.UnsubscribeEvent<MoveEvent>(EventSource.Local, this);
}
private void MoveEvent(MoveEvent ev)
{
if (ev.Sender.TryGetComponent(out BuckleComponent buckle))
{
buckle.OnMoveEvent(ev);
}
} }
public override void Update(float frameTime) public override void Update(float frameTime)