Ghost command now releases artifact ghost role

This commit is contained in:
Jabak
2024-06-22 11:31:50 +03:00
parent 98657779b1
commit de755cb8d7
2 changed files with 38 additions and 0 deletions

View File

@@ -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<GhostAttemptHandleEvent>(HandleGhost);
}
/// <summary>
/// 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.
/// </summary>
private void HandleGhost(GhostAttemptHandleEvent ev)
{
// Return if CanReturnGlobal is already false
if (ev.CanReturnGlobal == false)
return;
if (!TryComp<ArtifactComponent>(ev.Mind.CurrentEntity, out var artifact))
return;
if (!TryComp<MindContainerComponent>(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);
}
}

View File

@@ -36,6 +36,7 @@ public sealed partial class ArtifactSystem : EntitySystem
InitializeCommands();
InitializeActions();
InitializeGhost();
}
/// <summary>