Files
tbd-station-14/Content.Server/Morgue/CrematoriumSystem.cs
2025-08-21 16:49:50 -07:00

59 lines
1.8 KiB
C#

using Content.Server.Ghost;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction.Events;
using Content.Shared.Morgue;
using Content.Shared.Morgue.Components;
using Content.Shared.Popups;
using Robust.Shared.Player;
namespace Content.Server.Morgue;
public sealed class CrematoriumSystem : SharedCrematoriumSystem
{
[Dependency] private readonly GhostSystem _ghostSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CrematoriumComponent, SuicideByEnvironmentEvent>(OnSuicideByEnvironment);
}
private void OnSuicideByEnvironment(Entity<CrematoriumComponent> ent, ref SuicideByEnvironmentEvent args)
{
if (args.Handled)
return;
var victim = args.Victim;
if (HasComp<ActorComponent>(victim) && Mind.TryGetMind(victim, out var mindId, out var mind))
{
_ghostSystem.OnGhostAttempt(mindId, false, mind: mind);
if (mind.OwnedEntity is { Valid: true } entity)
{
Popup.PopupEntity(Loc.GetString("crematorium-entity-storage-component-suicide-message"), entity);
}
}
Popup.PopupEntity(Loc.GetString("crematorium-entity-storage-component-suicide-message-others",
("victim", Identity.Entity(victim, EntityManager))),
victim,
Filter.PvsExcept(victim),
true,
PopupType.LargeCaution);
if (EntityStorage.CanInsert(victim, ent.Owner))
{
EntityStorage.CloseStorage(ent.Owner);
Standing.Down(victim, false);
EntityStorage.Insert(victim, ent.Owner);
}
else
{
EntityStorage.CloseStorage(ent.Owner);
Del(victim);
}
Cremate(ent.AsNullable());
args.Handled = true;
}
}