Fixes bug with anchorable attempt events, add "Before" events.

This commit is contained in:
Vera Aguilera Puerto
2021-06-03 09:35:49 +02:00
parent 841d07c622
commit c470a1c508

View File

@@ -49,7 +49,11 @@ namespace Content.Server.GameObjects.Components
BaseAnchoredAttemptEvent attempt = BaseAnchoredAttemptEvent attempt =
anchoring ? new AnchorAttemptEvent(user, utilizing) : new UnanchorAttemptEvent(user, utilizing); anchoring ? new AnchorAttemptEvent(user, utilizing) : new UnanchorAttemptEvent(user, utilizing);
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, attempt, false); // Need to cast the event or it will be raised as BaseAnchoredAttemptEvent.
if (anchoring)
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, (AnchorAttemptEvent) attempt, false);
else
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, (UnanchorAttemptEvent) attempt, false);
if (attempt.Cancelled) if (attempt.Cancelled)
return false; return false;
@@ -88,6 +92,8 @@ namespace Content.Server.GameObjects.Components
if (Snap) if (Snap)
Owner.SnapToGrid(Owner.EntityManager); Owner.SnapToGrid(Owner.EntityManager);
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new BeforeAnchoredEvent(user, utilizing), false);
_physicsComponent.BodyType = BodyType.Static; _physicsComponent.BodyType = BodyType.Static;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new AnchoredEvent(user, utilizing), false); Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new AnchoredEvent(user, utilizing), false);
@@ -112,6 +118,8 @@ namespace Content.Server.GameObjects.Components
if (_physicsComponent == null) if (_physicsComponent == null)
return false; return false;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new BeforeUnanchoredEvent(user, utilizing), false);
_physicsComponent.BodyType = BodyType.Dynamic; _physicsComponent.BodyType = BodyType.Dynamic;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new UnanchoredEvent(user, utilizing), false); Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new UnanchoredEvent(user, utilizing), false);
@@ -175,11 +183,27 @@ namespace Content.Server.GameObjects.Components
} }
} }
/// <summary>
/// Raised just before the entity's body type is changed.
/// </summary>
public class BeforeAnchoredEvent : BaseAnchoredEvent
{
public BeforeAnchoredEvent(IEntity user, IEntity tool) : base(user, tool) { }
}
public class AnchoredEvent : BaseAnchoredEvent public class AnchoredEvent : BaseAnchoredEvent
{ {
public AnchoredEvent(IEntity user, IEntity tool) : base(user, tool) { } public AnchoredEvent(IEntity user, IEntity tool) : base(user, tool) { }
} }
/// <summary>
/// Raised just before the entity's body type is changed.
/// </summary>
public class BeforeUnanchoredEvent : BaseAnchoredEvent
{
public BeforeUnanchoredEvent(IEntity user, IEntity tool) : base(user, tool) { }
}
public class UnanchoredEvent : BaseAnchoredEvent public class UnanchoredEvent : BaseAnchoredEvent
{ {
public UnanchoredEvent(IEntity user, IEntity tool) : base(user, tool) { } public UnanchoredEvent(IEntity user, IEntity tool) : base(user, tool) { }