From de755cb8d7a7efe01bb9c3023047fcd58e23ac99 Mon Sep 17 00:00:00 2001 From: Jabak <163307958+Jabaks@users.noreply.github.com> Date: Sat, 22 Jun 2024 11:31:50 +0300 Subject: [PATCH] Ghost command now releases artifact ghost role --- .../XenoArtifacts/ArtifactSystem.Ghost.cs | 37 +++++++++++++++++++ .../XenoArtifacts/ArtifactSystem.cs | 1 + 2 files changed, 38 insertions(+) create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Ghost.cs diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Ghost.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Ghost.cs new file mode 100644 index 0000000000..3c1a929620 --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Ghost.cs @@ -0,0 +1,37 @@ +using Content.Server.GameTicking; +using Content.Shared.Mind.Components; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts; + +public partial class ArtifactSystem +{ + [Dependency] private readonly GameTicker _gameTicker = default!; + + private void InitializeGhost() + { + SubscribeLocalEvent(HandleGhost); + } + + /// + /// The expected way to trigger this handler is from using the /ghost command as an artifact, + /// which calls OnGhostAttempt with CanReturnGlobal set to `true`. Because of this, the artifact ghost role isn't freed. + /// This method calls OnGhostAttempt with CanReturnGlobal parameter set to `false`, if the ghosting entity is an artifact. + /// + private void HandleGhost(GhostAttemptHandleEvent ev) + { + // Return if CanReturnGlobal is already false + if (ev.CanReturnGlobal == false) + return; + + if (!TryComp(ev.Mind.CurrentEntity, out var artifact)) + return; + if (!TryComp(ev.Mind.CurrentEntity, out var mindcontainer)) + return; + + if (!mindcontainer.Mind.HasValue) + return; + + ev.Handled = true; + ev.Result = _gameTicker.OnGhostAttempt(mindcontainer.Mind.Value, false, false, ev.Mind); + } +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs index 955fe827d7..8e5834d975 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs @@ -36,6 +36,7 @@ public sealed partial class ArtifactSystem : EntitySystem InitializeCommands(); InitializeActions(); + InitializeGhost(); } ///