diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs index 8d6a7ce2ed..0baa468426 100644 --- a/Content.Server/GameObjects/Components/AnchorableComponent.cs +++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs @@ -49,7 +49,11 @@ namespace Content.Server.GameObjects.Components BaseAnchoredAttemptEvent attempt = 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) return false; @@ -88,6 +92,8 @@ namespace Content.Server.GameObjects.Components if (Snap) Owner.SnapToGrid(Owner.EntityManager); + Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new BeforeAnchoredEvent(user, utilizing), false); + _physicsComponent.BodyType = BodyType.Static; Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new AnchoredEvent(user, utilizing), false); @@ -112,6 +118,8 @@ namespace Content.Server.GameObjects.Components if (_physicsComponent == null) return false; + Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new BeforeUnanchoredEvent(user, utilizing), false); + _physicsComponent.BodyType = BodyType.Dynamic; Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new UnanchoredEvent(user, utilizing), false); @@ -175,11 +183,27 @@ namespace Content.Server.GameObjects.Components } } + /// + /// Raised just before the entity's body type is changed. + /// + public class BeforeAnchoredEvent : BaseAnchoredEvent + { + public BeforeAnchoredEvent(IEntity user, IEntity tool) : base(user, tool) { } + } + public class AnchoredEvent : BaseAnchoredEvent { public AnchoredEvent(IEntity user, IEntity tool) : base(user, tool) { } } + /// + /// Raised just before the entity's body type is changed. + /// + public class BeforeUnanchoredEvent : BaseAnchoredEvent + { + public BeforeUnanchoredEvent(IEntity user, IEntity tool) : base(user, tool) { } + } + public class UnanchoredEvent : BaseAnchoredEvent { public UnanchoredEvent(IEntity user, IEntity tool) : base(user, tool) { }