EntityStorage ECS (#9291)
This commit is contained in:
@@ -1,145 +1,93 @@
|
||||
using Content.Server.Morgue.Components;
|
||||
using Content.Shared.Morgue;
|
||||
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.Popups;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Morgue
|
||||
namespace Content.Server.Morgue;
|
||||
|
||||
public sealed partial class MorgueSystem : EntitySystem
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class MorgueSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly StandingStateSystem _stando = default!;
|
||||
base.Initialize();
|
||||
|
||||
private float _accumulatedFrameTime;
|
||||
SubscribeLocalEvent<MorgueComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
/// <summary>
|
||||
/// Handles the examination text for looking at a morgue.
|
||||
/// </summary>
|
||||
private void OnExamine(EntityUid uid, MorgueComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
return;
|
||||
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul"));
|
||||
else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-no-soul"));
|
||||
else if (appearance.TryGetData(StorageVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents"));
|
||||
else
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-empty"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates data periodically in case something died/got deleted in the morgue.
|
||||
/// </summary>
|
||||
private void CheckContents(EntityUid uid, MorgueComponent? morgue = null, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref morgue, ref storage))
|
||||
return;
|
||||
|
||||
var hasMob = false;
|
||||
var hasSoul = false;
|
||||
|
||||
foreach (var ent in storage.Contents.ContainedEntities)
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CrematoriumEntityStorageComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb);
|
||||
SubscribeLocalEvent<CrematoriumEntityStorageComponent, ExaminedEvent>(OnCrematoriumExamined);
|
||||
SubscribeLocalEvent<CrematoriumEntityStorageComponent, SuicideEvent>(OnSuicide);
|
||||
SubscribeLocalEvent<MorgueEntityStorageComponent, ExaminedEvent>(OnMorgueExamined);
|
||||
if (!hasMob && HasComp<SharedBodyComponent>(ent))
|
||||
hasMob = true;
|
||||
if (!hasSoul && TryComp<ActorComponent?>(ent, out var actor) && actor.PlayerSession != null)
|
||||
hasSoul = true;
|
||||
}
|
||||
|
||||
private void OnSuicide(EntityUid uid, CrematoriumEntityStorageComponent component, SuicideEvent args)
|
||||
if (TryComp<AppearanceComponent>(uid, out var app))
|
||||
{
|
||||
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), PopupType.MediumCaution);
|
||||
}
|
||||
}
|
||||
|
||||
_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();
|
||||
app.SetData(MorgueVisuals.HasMob, hasMob);
|
||||
app.SetData(MorgueVisuals.HasSoul, hasSoul);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddCremateVerb(EntityUid uid, CrematoriumEntityStorageComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
/// <summary>
|
||||
/// Handles the periodic beeping that morgues do when a live body is inside.
|
||||
/// </summary>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var comp in EntityQuery<MorgueComponent>())
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || component.Cooking || component.Open )
|
||||
return;
|
||||
comp.AccumulatedFrameTime += frameTime;
|
||||
|
||||
AlternativeVerb verb = new();
|
||||
verb.Text = Loc.GetString("cremate-verb-get-data-text");
|
||||
// TODO VERB ICON add flame/burn symbol?
|
||||
verb.Act = () => component.TryCremate();
|
||||
verb.Impact = LogImpact.Medium; // could be a body? or evidence? I dunno.
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
CheckContents(comp.Owner, comp);
|
||||
|
||||
private void OnCrematoriumExamined(EntityUid uid, CrematoriumEntityStorageComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
return;
|
||||
if (comp.AccumulatedFrameTime < comp.BeepTime)
|
||||
continue;
|
||||
comp.AccumulatedFrameTime -= comp.BeepTime;
|
||||
|
||||
if (args.IsInDetailsRange)
|
||||
if (comp.DoSoulBeep && TryComp<AppearanceComponent>(comp.Owner, out var appearance) &&
|
||||
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
{
|
||||
if (appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-is-burning", ("owner", uid)));
|
||||
}
|
||||
|
||||
if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-has-contents"));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-empty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMorgueExamined(EntityUid uid, MorgueEntityStorageComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance)) return;
|
||||
|
||||
if (args.IsInDetailsRange)
|
||||
{
|
||||
if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul"));
|
||||
}
|
||||
else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-no-soul"));
|
||||
}
|
||||
else if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents"));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-empty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_accumulatedFrameTime += frameTime;
|
||||
|
||||
if (_accumulatedFrameTime >= 10)
|
||||
{
|
||||
foreach (var morgue in EntityManager.EntityQuery<MorgueEntityStorageComponent>())
|
||||
{
|
||||
morgue.Update();
|
||||
}
|
||||
_accumulatedFrameTime -= 10;
|
||||
SoundSystem.Play(comp.OccupantHasSoulAlarmSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user