Convert suicide to ecs (#8091)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Content.Server.Morgue.Components
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
#pragma warning disable 618
|
||||
public sealed class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent, ISuicideAct
|
||||
public sealed class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent
|
||||
#pragma warning restore 618
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
@@ -100,34 +100,5 @@ namespace Content.Server.Morgue.Components
|
||||
|
||||
}, _cremateCancelToken.Token);
|
||||
}
|
||||
|
||||
SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat)
|
||||
{
|
||||
if (_entities.TryGetComponent(victim, out ActorComponent? actor) && actor.PlayerSession.ContentData()?.Mind is {} mind)
|
||||
{
|
||||
EntitySystem.Get<GameTicker>().OnGhostAttempt(mind, false);
|
||||
|
||||
if (mind.OwnedEntity is {Valid: true} entity)
|
||||
{
|
||||
entity.PopupMessage(Loc.GetString("crematorium-entity-storage-component-suicide-message"));
|
||||
}
|
||||
}
|
||||
|
||||
victim.PopupMessageOtherClients(Loc.GetString("crematorium-entity-storage-component-suicide-message-others", ("victim", victim)));
|
||||
|
||||
if (CanInsert(victim))
|
||||
{
|
||||
Insert(victim);
|
||||
EntitySystem.Get<StandingStateSystem>().Down(victim, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_entities.DeleteEntity(victim);
|
||||
}
|
||||
|
||||
Cremate();
|
||||
|
||||
return SuicideKind.Heat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user