From f257846de711b1689f4086568b17366f03ab0a4d Mon Sep 17 00:00:00 2001
From: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Date: Tue, 13 Apr 2021 13:18:20 +0200
Subject: [PATCH] Anchorable component now raises cancellable event on
(un)anchor. (#3828)
---
.../Components/AnchorableComponent.cs | 24 +++++++++++++++++++
SpaceStation14.sln.DotSettings | 3 +++
2 files changed, 27 insertions(+)
diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs
index 368f6f1cce..e529354283 100644
--- a/Content.Server/GameObjects/Components/AnchorableComponent.cs
+++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs
@@ -83,6 +83,13 @@ namespace Content.Server.GameObjects.Components
if (_physicsComponent == null)
return false;
+ var attempt = new AnchorAttemptMessage();
+
+ Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, attempt, false);
+
+ if (attempt.Cancelled)
+ return false;
+
_physicsComponent.BodyType = BodyType.Static;
// Snap rotation to cardinal (multiple of 90)
@@ -100,6 +107,8 @@ namespace Content.Server.GameObjects.Components
if (Snap)
Owner.SnapToGrid(SnapGridOffset.Center, Owner.EntityManager);
+ Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new AnchoredMessage(), false);
+
return true;
}
@@ -120,8 +129,17 @@ namespace Content.Server.GameObjects.Components
if (_physicsComponent == null)
return false;
+ var attempt = new UnanchorAttemptMessage();
+
+ Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, attempt, false);
+
+ if (attempt.Cancelled)
+ return false;
+
_physicsComponent.BodyType = BodyType.Dynamic;
+ Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new UnanchoredMessage(), false);
+
return true;
}
@@ -147,4 +165,10 @@ namespace Content.Server.GameObjects.Components
return await TryToggleAnchor(eventArgs.User, eventArgs.Using);
}
}
+
+ public class AnchorAttemptMessage : CancellableEntityEventArgs { }
+ public class UnanchorAttemptMessage : CancellableEntityEventArgs { }
+
+ public class AnchoredMessage : EntityEventArgs {}
+ public class UnanchoredMessage : EntityEventArgs {}
}
diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings
index 171ae04e43..d67a3f3f24 100644
--- a/SpaceStation14.sln.DotSettings
+++ b/SpaceStation14.sln.DotSettings
@@ -165,6 +165,9 @@
True
True
True
+ True
+ True
+ True
True
True
True