cleaning up more stuff with crematoriums and morgues (#11384)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
/// <summary>
|
||||
/// used to track actively cooking crematoriums
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveCrematoriumComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Accumulator = 0;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Robust.Shared.Audio;
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Morgue.Components;
|
||||
|
||||
@@ -7,18 +6,10 @@ namespace Content.Server.Morgue.Components;
|
||||
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
|
||||
/// The time it takes to cook in second
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int BurnMilis = 5000;
|
||||
|
||||
public CancellationTokenSource? CremateCancelToken;
|
||||
public int CookTime = 5;
|
||||
|
||||
[DataField("cremateStartSound")]
|
||||
public SoundSpecifier CremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");
|
||||
|
||||
@@ -2,9 +2,7 @@ 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;
|
||||
@@ -21,6 +19,8 @@ namespace Content.Server.Morgue;
|
||||
|
||||
public sealed class CrematoriumSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
[Dependency] private readonly EntityStorageSystem _entityStorage = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
@@ -31,9 +31,9 @@ public sealed class CrematoriumSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CrematoriumComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<CrematoriumComponent, StorageOpenAttemptEvent>(OnAttemptOpen);
|
||||
SubscribeLocalEvent<CrematoriumComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb);
|
||||
SubscribeLocalEvent<CrematoriumComponent, SuicideEvent>(OnSuicide);
|
||||
SubscribeLocalEvent<ActiveCrematoriumComponent, StorageOpenAttemptEvent>(OnAttemptOpen);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, CrematoriumComponent component, ExaminedEvent args)
|
||||
@@ -49,10 +49,9 @@ public sealed class CrematoriumSystem : EntitySystem
|
||||
args.PushMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-empty"));
|
||||
}
|
||||
|
||||
private void OnAttemptOpen(EntityUid uid, CrematoriumComponent component, StorageOpenAttemptEvent args)
|
||||
private void OnAttemptOpen(EntityUid uid, ActiveCrematoriumComponent component, StorageOpenAttemptEvent args)
|
||||
{
|
||||
if (component.Cooking)
|
||||
args.Cancel();
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void AddCremateVerb(EntityUid uid, CrematoriumComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
@@ -60,7 +59,10 @@ public sealed class CrematoriumSystem : EntitySystem
|
||||
if (!TryComp<EntityStorageComponent>(uid, out var storage))
|
||||
return;
|
||||
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || component.Cooking || storage.Open)
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null || storage.Open)
|
||||
return;
|
||||
|
||||
if (HasComp<ActiveCrematoriumComponent>(uid))
|
||||
return;
|
||||
|
||||
AlternativeVerb verb = new()
|
||||
@@ -73,58 +75,56 @@ public sealed class CrematoriumSystem : EntitySystem
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
public void Cremate(EntityUid uid, CrematoriumComponent? component = null, EntityStorageComponent? storage = null)
|
||||
public bool Cremate(EntityUid uid, CrematoriumComponent? component = null, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref storage))
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (TryComp<AppearanceComponent>(uid, out var app))
|
||||
app.SetData(CrematoriumVisuals.Burning, true);
|
||||
component.Cooking = true;
|
||||
if (HasComp<ActiveCrematoriumComponent>(uid))
|
||||
return false;
|
||||
|
||||
SoundSystem.Play(component.CrematingSound.GetSound(), Filter.Pvs(uid), uid);
|
||||
_audio.PlayPvs(component.CremateStartSound, uid);
|
||||
_appearance.SetData(uid, CrematoriumVisuals.Burning, true);
|
||||
|
||||
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;
|
||||
_audio.PlayPvs(component.CrematingSound, uid);
|
||||
|
||||
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);
|
||||
AddComp<ActiveCrematoriumComponent>(uid);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TryCremate(EntityUid uid, CrematoriumComponent component, EntityStorageComponent? storage = null)
|
||||
public bool TryCremate(EntityUid uid, CrematoriumComponent? component = null, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref storage))
|
||||
return false;
|
||||
|
||||
if (storage.Open || storage.Contents.ContainedEntities.Count < 1)
|
||||
return false;
|
||||
|
||||
return Cremate(uid, component, storage);
|
||||
}
|
||||
|
||||
private void FinishCooking(EntityUid uid, CrematoriumComponent component, EntityStorageComponent? storage = null)
|
||||
{
|
||||
if (!Resolve(uid, ref storage))
|
||||
return;
|
||||
|
||||
if (component.Cooking || storage.Open || storage.Contents.ContainedEntities.Count < 1)
|
||||
return;
|
||||
_appearance.SetData(uid, CrematoriumVisuals.Burning, false);
|
||||
RemComp<ActiveCrematoriumComponent>(uid);
|
||||
|
||||
SoundSystem.Play(component.CremateStartSound.GetSound(), Filter.Pvs(uid), uid);
|
||||
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);
|
||||
}
|
||||
|
||||
Cremate(uid, component, storage);
|
||||
_entityStorage.OpenStorage(uid, storage);
|
||||
_audio.PlayPvs(component.CremateFinishSound, uid);
|
||||
}
|
||||
|
||||
private void OnSuicide(EntityUid uid, CrematoriumComponent component, SuicideEvent args)
|
||||
@@ -161,4 +161,17 @@ public sealed class CrematoriumSystem : EntitySystem
|
||||
_entityStorage.CloseStorage(uid);
|
||||
Cremate(uid, component);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var (act, crem) in EntityQuery<ActiveCrematoriumComponent, CrematoriumComponent>())
|
||||
{
|
||||
act.Accumulator += frameTime;
|
||||
|
||||
if (act.Accumulator >= crem.CookTime)
|
||||
FinishCooking(act.Owner, crem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,16 @@ using Content.Server.Morgue.Components;
|
||||
using Content.Shared.Morgue;
|
||||
using Content.Shared.Examine;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Server.Popups;
|
||||
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;
|
||||
|
||||
public sealed partial class MorgueSystem : EntitySystem
|
||||
public sealed class MorgueSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -32,7 +31,7 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
return;
|
||||
|
||||
appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents);
|
||||
|
||||
|
||||
var text = contents switch
|
||||
{
|
||||
MorgueContents.HasSoul => "morgue-entity-storage-component-on-examine-details-body-has-soul",
|
||||
@@ -54,25 +53,25 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
|
||||
if (storage.Contents.ContainedEntities.Count == 0)
|
||||
{
|
||||
app.SetData(MorgueVisuals.Contents, MorgueContents.Empty);
|
||||
_appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
var hasMob = false;
|
||||
|
||||
|
||||
foreach (var ent in storage.Contents.ContainedEntities)
|
||||
{
|
||||
if (!hasMob && HasComp<SharedBodyComponent>(ent))
|
||||
hasMob = true;
|
||||
|
||||
if (TryComp<ActorComponent?>(ent, out var actor) && actor.PlayerSession != null)
|
||||
if (HasComp<ActorComponent?>(ent))
|
||||
{
|
||||
app.SetData(MorgueVisuals.Contents, MorgueContents.HasSoul);
|
||||
_appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.HasSoul, app);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
app.SetData(MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents);
|
||||
_appearance.SetData(uid, MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents, app);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,7 +85,7 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
{
|
||||
comp.AccumulatedFrameTime += frameTime;
|
||||
|
||||
CheckContents(comp.Owner, comp, storage, appearance);
|
||||
CheckContents(comp.Owner, comp, storage);
|
||||
|
||||
if (comp.AccumulatedFrameTime < comp.BeepTime)
|
||||
continue;
|
||||
@@ -95,7 +94,7 @@ public sealed partial class MorgueSystem : EntitySystem
|
||||
|
||||
if (comp.DoSoulBeep && appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents) && contents == MorgueContents.HasSoul)
|
||||
{
|
||||
SoundSystem.Play(comp.OccupantHasSoulAlarmSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner);
|
||||
_audio.PlayPvs(comp.OccupantHasSoulAlarmSound, comp.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user