EntityStorage ECS (#9291)
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Standing;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public sealed class BodyBagEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
protected override bool AddToContents(EntityUid entity)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<SharedBodyComponent>(entity) && !EntitySystem.Get<StandingStateSystem>().IsDown(entity)) return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Content.Server/Morgue/Components/CrematoriumComponent.cs
Normal file
31
Content.Server/Morgue/Components/CrematoriumComponent.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Content.Shared.Sound;
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class CrematoriumComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not the crematorium is currently cooking
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool Cooking;
|
||||
|
||||
/// <summary>
|
||||
/// The time it takes to cook
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int BurnMilis = 5000;
|
||||
|
||||
public CancellationTokenSource? CremateCancelToken;
|
||||
|
||||
[DataField("cremateStartSound")]
|
||||
public SoundSpecifier CremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
|
||||
|
||||
[DataField("crematingSound")]
|
||||
public SoundSpecifier CrematingSound = new SoundPathSpecifier("/Audio/Effects/burning.ogg");
|
||||
|
||||
[DataField("cremateFinishSound")]
|
||||
public SoundSpecifier CremateFinishSound = new SoundPathSpecifier("/Audio/Machines/ding.ogg");
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
|
||||
using System.Threading;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(MorgueEntityStorageComponent))]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
#pragma warning disable 618
|
||||
public sealed class CrematoriumEntityStorageComponent : MorgueEntityStorageComponent
|
||||
#pragma warning restore 618
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[DataField("cremateStartSound")] private SoundSpecifier _cremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
|
||||
[DataField("crematingSound")] private SoundSpecifier _crematingSound = new SoundPathSpecifier("/Audio/Effects/burning.ogg");
|
||||
[DataField("cremateFinishSound")] private SoundSpecifier _cremateFinishSound = new SoundPathSpecifier("/Audio/Machines/ding.ogg");
|
||||
|
||||
[ViewVariables]
|
||||
public bool Cooking { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _burnMilis = 5000;
|
||||
|
||||
private CancellationTokenSource? _cremateCancelToken;
|
||||
|
||||
public override bool CanOpen(EntityUid user, bool silent = false)
|
||||
{
|
||||
if (Cooking)
|
||||
{
|
||||
if (!silent)
|
||||
Owner.PopupMessage(user, Loc.GetString("crematorium-entity-storage-component-is-cooking-safety-message"));
|
||||
return false;
|
||||
}
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
public void TryCremate()
|
||||
{
|
||||
if (Cooking) return;
|
||||
if (Open) return;
|
||||
|
||||
SoundSystem.Play(_cremateStartSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
Cremate();
|
||||
}
|
||||
|
||||
public void Cremate()
|
||||
{
|
||||
if (Open)
|
||||
CloseStorage();
|
||||
|
||||
if(_entities.TryGetComponent(Owner, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(CrematoriumVisuals.Burning, true);
|
||||
Cooking = true;
|
||||
|
||||
SoundSystem.Play(_crematingSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
_cremateCancelToken?.Cancel();
|
||||
|
||||
_cremateCancelToken = new CancellationTokenSource();
|
||||
Owner.SpawnTimer(_burnMilis, () =>
|
||||
{
|
||||
if (_entities.Deleted(Owner))
|
||||
return;
|
||||
if(_entities.TryGetComponent(Owner, out appearanceComponent))
|
||||
appearanceComponent.SetData(CrematoriumVisuals.Burning, false);
|
||||
Cooking = false;
|
||||
|
||||
if (Contents.ContainedEntities.Count > 0)
|
||||
{
|
||||
for (var i = Contents.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = Contents.ContainedEntities[i];
|
||||
Contents.Remove(item);
|
||||
_entities.DeleteEntity(item);
|
||||
}
|
||||
|
||||
var ash = _entities.SpawnEntity("Ash", _entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
Contents.Insert(ash);
|
||||
}
|
||||
|
||||
TryOpenStorage(Owner);
|
||||
|
||||
SoundSystem.Play(_cremateFinishSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
|
||||
}, _cremateCancelToken.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class EntityStorageLayingDownOverrideComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
26
Content.Server/Morgue/Components/MorgueComponent.cs
Normal file
26
Content.Server/Morgue/Components/MorgueComponent.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Content.Shared.Sound;
|
||||
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class MorgueComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not the morgue beeps if a living player is inside.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("doSoulBeep")]
|
||||
public bool DoSoulBeep = true;
|
||||
|
||||
[ViewVariables]
|
||||
public float AccumulatedFrameTime = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time between each beep.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public float BeepTime = 10f;
|
||||
|
||||
[DataField("occupantHasSoulAlarmSound")]
|
||||
public SoundSpecifier OccupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Directions;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
[Virtual]
|
||||
public class MorgueEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
private const CollisionGroup TrayCanOpenMask = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("trayPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
private string? _trayPrototypeId;
|
||||
|
||||
[ViewVariables]
|
||||
private EntityUid? _tray;
|
||||
|
||||
[ViewVariables]
|
||||
public ContainerSlot? TrayContainer { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("doSoulBeep")]
|
||||
public bool DoSoulBeep = true;
|
||||
|
||||
[DataField("occupantHasSoulAlarmSound")]
|
||||
private SoundSpecifier _occupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
appearance.SetData(MorgueVisuals.Open, false);
|
||||
TrayContainer = Owner.EnsureContainer<ContainerSlot>("morgue_tray", out _);
|
||||
}
|
||||
|
||||
public override Vector2 ContentsDumpPosition()
|
||||
{
|
||||
if (_tray != null)
|
||||
return _entMan.GetComponent<TransformComponent>(_tray.Value).WorldPosition;
|
||||
return base.ContentsDumpPosition();
|
||||
}
|
||||
|
||||
protected override bool AddToContents(EntityUid entity)
|
||||
{
|
||||
if (_entMan.HasComponent<SharedBodyComponent>(entity) && !EntitySystem.Get<StandingStateSystem>().IsDown(entity))
|
||||
return false;
|
||||
return base.AddToContents(entity);
|
||||
}
|
||||
|
||||
public override bool CanOpen(EntityUid user, bool silent = false)
|
||||
{
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner,
|
||||
_entMan.GetComponent<TransformComponent>(Owner).Coordinates.Offset(_entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetCardinalDir()),
|
||||
collisionMask: TrayCanOpenMask
|
||||
))
|
||||
{
|
||||
if (!silent)
|
||||
Owner.PopupMessage(user, Loc.GetString("morgue-entity-storage-component-cannot-open-no-space"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
protected override void OpenStorage()
|
||||
{
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData(MorgueVisuals.Open, true);
|
||||
appearance.SetData(MorgueVisuals.HasContents, false);
|
||||
appearance.SetData(MorgueVisuals.HasMob, false);
|
||||
appearance.SetData(MorgueVisuals.HasSoul, false);
|
||||
}
|
||||
|
||||
if (_tray == null)
|
||||
{
|
||||
_tray = _entMan.SpawnEntity(_trayPrototypeId, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var trayComp = _tray.Value.EnsureComponent<MorgueTrayComponent>();
|
||||
trayComp.Morgue = Owner;
|
||||
}
|
||||
else
|
||||
{
|
||||
TrayContainer?.Remove(_tray.Value);
|
||||
}
|
||||
|
||||
_entMan.GetComponent<TransformComponent>(_tray.Value).Coordinates = new EntityCoordinates(Owner, 0, -1);
|
||||
|
||||
base.OpenStorage();
|
||||
}
|
||||
|
||||
private void CheckContents()
|
||||
{
|
||||
var count = 0;
|
||||
var hasMob = false;
|
||||
var hasSoul = false;
|
||||
foreach (var entity in Contents.ContainedEntities)
|
||||
{
|
||||
count++;
|
||||
if (!hasMob && _entMan.HasComponent<SharedBodyComponent>(entity))
|
||||
hasMob = true;
|
||||
if (!hasSoul && _entMan.TryGetComponent<ActorComponent?>(entity, out var actor) && actor.PlayerSession != null)
|
||||
hasSoul = true;
|
||||
}
|
||||
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData(MorgueVisuals.HasContents, count > 0);
|
||||
appearance.SetData(MorgueVisuals.HasMob, hasMob);
|
||||
appearance.SetData(MorgueVisuals.HasSoul, hasSoul);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CloseStorage()
|
||||
{
|
||||
base.CloseStorage();
|
||||
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
|
||||
appearance.SetData(MorgueVisuals.Open, false);
|
||||
CheckContents();
|
||||
|
||||
if (_tray != null)
|
||||
{
|
||||
TrayContainer?.Insert(_tray.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<EntityUid> DetermineCollidingEntities()
|
||||
{
|
||||
if (_tray == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var entityLookup = EntitySystem.Get<EntityLookupSystem>();
|
||||
foreach (var entity in entityLookup.GetEntitiesIntersecting(_tray.Value, flags: LookupFlags.None))
|
||||
{
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
|
||||
//Called every 10 seconds
|
||||
public void Update()
|
||||
{
|
||||
CheckContents();
|
||||
|
||||
if (DoSoulBeep && _entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance) &&
|
||||
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
|
||||
{
|
||||
SoundSystem.Play(_occupantHasSoulAlarmSound.GetSound(), Filter.Pvs(Owner), Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
namespace Content.Server.Morgue.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public sealed class MorgueTrayComponent : Component, IActivate
|
||||
{
|
||||
[ViewVariables]
|
||||
public EntityUid Morgue { get; set; }
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (Morgue != default && !entMan.Deleted(Morgue) && entMan.TryGetComponent<MorgueEntityStorageComponent?>(Morgue, out var comp))
|
||||
{
|
||||
comp.Activate(new ActivateEventArgs(eventArgs.User, Morgue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Content.Server/Morgue/CrematoriumSystem.cs
Normal file
162
Content.Server/Morgue/CrematoriumSystem.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using Content.Server.Morgue.Components;
|
||||
using Content.Shared.Morgue;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Server.Storage.Components;
|
||||
using System.Threading;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Morgue;
|
||||
|
||||
public sealed class CrematoriumSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
[Dependency] private readonly EntityStorageSystem _entityStorage = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly StandingStateSystem _standing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CrematoriumComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<CrematoriumComponent, StorageOpenAttemptEvent>(OnAttemptOpen);
|
||||
SubscribeLocalEvent<CrematoriumComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb);
|
||||
SubscribeLocalEvent<CrematoriumComponent, SuicideEvent>(OnSuicide);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, CrematoriumComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
return;
|
||||
|
||||
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(StorageVisuals.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 OnAttemptOpen(EntityUid uid, CrematoriumComponent component, StorageOpenAttemptEvent args)
|
||||
{
|
||||
if (component.Cooking)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void AddCremateVerb(EntityUid uid, CrematoriumComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!TryComp<EntityStorageComponent>(uid, out var storage))
|
||||
return;
|
||||
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || component.Cooking || storage.Open)
|
||||
return;
|
||||
|
||||
AlternativeVerb verb = new()
|
||||
{
|
||||
Text = Loc.GetString("cremate-verb-get-data-text"),
|
||||
// TODO VERB ICON add flame/burn symbol?
|
||||
Act = () => TryCremate(uid, component, storage),
|
||||
Impact = LogImpact.Medium // could be a body? or evidence? I dunno.
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
public void Cremate(EntityUid uid, CrematoriumComponent? component = null, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref storage))
|
||||
return;
|
||||
|
||||
if (TryComp<AppearanceComponent>(uid, out var app))
|
||||
app.SetData(CrematoriumVisuals.Burning, true);
|
||||
component.Cooking = true;
|
||||
|
||||
SoundSystem.Play(component.CrematingSound.GetSound(), Filter.Pvs(uid), uid);
|
||||
|
||||
component.CremateCancelToken?.Cancel();
|
||||
component.CremateCancelToken = new CancellationTokenSource();
|
||||
uid.SpawnTimer(component.BurnMilis, () =>
|
||||
{
|
||||
if (Deleted(uid))
|
||||
return;
|
||||
if (TryComp<AppearanceComponent>(uid, out var app))
|
||||
app.SetData(CrematoriumVisuals.Burning, false);
|
||||
component.Cooking = false;
|
||||
|
||||
if (storage.Contents.ContainedEntities.Count > 0)
|
||||
{
|
||||
for (var i = storage.Contents.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = storage.Contents.ContainedEntities[i];
|
||||
storage.Contents.Remove(item);
|
||||
EntityManager.DeleteEntity(item);
|
||||
}
|
||||
|
||||
var ash = Spawn("Ash", Transform(uid).Coordinates);
|
||||
storage.Contents.Insert(ash);
|
||||
}
|
||||
|
||||
_entityStorage.OpenStorage(uid, storage);
|
||||
|
||||
SoundSystem.Play(component.CremateFinishSound.GetSound(), Filter.Pvs(uid), uid);
|
||||
|
||||
}, component.CremateCancelToken.Token);
|
||||
}
|
||||
|
||||
public void TryCremate(EntityUid uid, CrematoriumComponent component, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref storage))
|
||||
return;
|
||||
|
||||
if (component.Cooking || storage.Open || storage.Contents.ContainedEntities.Count < 1)
|
||||
return;
|
||||
|
||||
SoundSystem.Play(component.CremateStartSound.GetSound(), Filter.Pvs(uid), uid);
|
||||
|
||||
Cremate(uid, component, storage);
|
||||
}
|
||||
|
||||
private void OnSuicide(EntityUid uid, CrematoriumComponent 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));
|
||||
}
|
||||
}
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("crematorium-entity-storage-component-suicide-message-others", ("victim", victim)),
|
||||
victim, Filter.PvsExcept(victim), PopupType.LargeCaution);
|
||||
|
||||
if (_entityStorage.CanInsert(uid))
|
||||
{
|
||||
_entityStorage.CloseStorage(uid);
|
||||
_standing.Down(victim, false);
|
||||
_entityStorage.Insert(victim, uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityManager.DeleteEntity(victim);
|
||||
}
|
||||
_entityStorage.CloseStorage(uid);
|
||||
Cremate(uid, component);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Server.Morgue.Components;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
|
||||
namespace Content.Server.Morgue;
|
||||
|
||||
public sealed class EntityStorageLayingDownOverrideSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StandingStateSystem _standing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EntityStorageLayingDownOverrideComponent, StorageBeforeCloseEvent>(OnBeforeClose);
|
||||
}
|
||||
|
||||
private void OnBeforeClose(EntityUid uid, EntityStorageLayingDownOverrideComponent component, StorageBeforeCloseEvent args)
|
||||
{
|
||||
foreach (var ent in args.Contents)
|
||||
if (HasComp<SharedBodyComponent>(ent) && !_standing.IsDown(ent))
|
||||
args.Contents.Remove(ent);
|
||||
}
|
||||
}
|
||||
@@ -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