Convert suicide to ecs (#8091)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
wrexbe
2022-05-12 05:05:16 -07:00
committed by GitHub
parent 6903209a31
commit 089e40a061
15 changed files with 362 additions and 282 deletions

View File

@@ -4,12 +4,22 @@ using Content.Shared.Examine;
using Content.Shared.Database;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Content.Shared.Interaction.Events;
using Robust.Server.GameObjects;
using Content.Server.Players;
using Content.Server.GameTicking;
using Content.Server.Popups;
using Content.Shared.Standing;
using Robust.Shared.Player;
namespace Content.Server.Morgue
{
[UsedImplicitly]
public sealed class MorgueSystem : EntitySystem
{
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly StandingStateSystem _stando = default!;
private float _accumulatedFrameTime;
@@ -19,9 +29,44 @@ namespace Content.Server.Morgue
SubscribeLocalEvent<CrematoriumEntityStorageComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb);
SubscribeLocalEvent<CrematoriumEntityStorageComponent, ExaminedEvent>(OnCrematoriumExamined);
SubscribeLocalEvent<CrematoriumEntityStorageComponent, SuicideEvent>(OnSuicide);
SubscribeLocalEvent<MorgueEntityStorageComponent, ExaminedEvent>(OnMorgueExamined);
}
private void OnSuicide(EntityUid uid, CrematoriumEntityStorageComponent component, SuicideEvent args)
{
if (args.Handled) return;
args.SetHandled(SuicideKind.Heat);
var victim = args.Victim;
if (TryComp(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is { } mind)
{
_ticker.OnGhostAttempt(mind, false);
if (mind.OwnedEntity is { Valid: true } entity)
{
_popup.PopupEntity(Loc.GetString("crematorium-entity-storage-component-suicide-message"), entity, Filter.Pvs(entity, entityManager: EntityManager));
}
}
_popup.PopupEntity(
Loc.GetString("crematorium-entity-storage-component-suicide-message-others", ("victim", victim)),
victim,
Filter.Pvs(victim, entityManager: EntityManager).RemoveWhereAttachedEntity(e => e == victim));
if (component.CanInsert(victim))
{
component.Insert(victim);
_stando.Down(victim, false);
}
else
{
EntityManager.DeleteEntity(victim);
}
component.Cremate();
}
private void AddCremateVerb(EntityUid uid, CrematoriumEntityStorageComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || component.Cooking || component.Open)