cleaning up more stuff with crematoriums and morgues (#11384)

This commit is contained in:
Nemanja
2022-09-19 19:59:04 -04:00
committed by GitHub
parent 19e094779a
commit 2ed3779405
10 changed files with 112 additions and 174 deletions

View File

@@ -0,0 +1,7 @@
namespace Content.Client.Morgue.Visualizers;
public enum CrematoriumVisualLayers : byte
{
Base,
LightBurning,
LightContent
}

View File

@@ -1,36 +0,0 @@
using Content.Shared.Morgue;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Morgue.Visualizers;
public sealed class CrematoriumVisualizerSystem : VisualizerSystem<CrematoriumVisualsComponent>
{
public override void Initialize()
{
base.Initialize();
}
protected override void OnAppearanceChange(EntityUid uid, CrematoriumVisualsComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
string? lightState = null;
if (args.Component.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning)
lightState = component.LightBurning;
else if (args.Component.TryGetData(StorageVisuals.HasContents, out bool hasContents) && hasContents)
lightState = component.LightContents;
if (lightState != null)
{
args.Sprite.LayerSetState(CrematoriumVisualLayers.Light, lightState);
args.Sprite.LayerSetVisible(CrematoriumVisualLayers.Light, true);
}
else
{
args.Sprite.LayerSetVisible(CrematoriumVisualLayers.Light, false);
}
}
}

View File

@@ -1,16 +0,0 @@
namespace Content.Client.Morgue.Visualizers;
[RegisterComponent]
public sealed class CrematoriumVisualsComponent : Component
{
[DataField("lightContents", required: true)]
public string LightContents = default!;
[DataField("lightBurning", required: true)]
public string LightBurning = default!;
}
public enum CrematoriumVisualLayers : byte
{
Base,
Light,
}

View File

@@ -60,7 +60,6 @@ public sealed class PrototypeSaveTest
"WeaponLauncherChinaLake", "WeaponLauncherChinaLake",
"WeaponLauncherRocket", "WeaponLauncherRocket",
"WeaponLauncherMultipleRocket", "WeaponLauncherMultipleRocket",
"Crematorium",
"JawsOfLife", "JawsOfLife",
"SyndicateJawsOfLife", "SyndicateJawsOfLife",
"LightReplacer", "LightReplacer",

View File

@@ -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;
}

View File

@@ -1,5 +1,4 @@
using Robust.Shared.Audio; using Robust.Shared.Audio;
using System.Threading;
namespace Content.Server.Morgue.Components; namespace Content.Server.Morgue.Components;
@@ -7,18 +6,10 @@ namespace Content.Server.Morgue.Components;
public sealed class CrematoriumComponent : Component public sealed class CrematoriumComponent : Component
{ {
/// <summary> /// <summary>
/// Whether or not the crematorium is currently cooking /// The time it takes to cook in second
/// </summary>
[ViewVariables]
public bool Cooking;
/// <summary>
/// The time it takes to cook
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public int BurnMilis = 5000; public int CookTime = 5;
public CancellationTokenSource? CremateCancelToken;
[DataField("cremateStartSound")] [DataField("cremateStartSound")]
public SoundSpecifier CremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg"); public SoundSpecifier CremateStartSound = new SoundPathSpecifier("/Audio/Items/lighter1.ogg");

View File

@@ -2,9 +2,7 @@ using Content.Server.Morgue.Components;
using Content.Shared.Morgue; using Content.Shared.Morgue;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Audio;
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using System.Threading;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
@@ -21,6 +19,8 @@ namespace Content.Server.Morgue;
public sealed class CrematoriumSystem : EntitySystem 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 GameTicker _ticker = default!;
[Dependency] private readonly EntityStorageSystem _entityStorage = default!; [Dependency] private readonly EntityStorageSystem _entityStorage = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedPopupSystem _popup = default!;
@@ -31,9 +31,9 @@ public sealed class CrematoriumSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<CrematoriumComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<CrematoriumComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<CrematoriumComponent, StorageOpenAttemptEvent>(OnAttemptOpen);
SubscribeLocalEvent<CrematoriumComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb); SubscribeLocalEvent<CrematoriumComponent, GetVerbsEvent<AlternativeVerb>>(AddCremateVerb);
SubscribeLocalEvent<CrematoriumComponent, SuicideEvent>(OnSuicide); SubscribeLocalEvent<CrematoriumComponent, SuicideEvent>(OnSuicide);
SubscribeLocalEvent<ActiveCrematoriumComponent, StorageOpenAttemptEvent>(OnAttemptOpen);
} }
private void OnExamine(EntityUid uid, CrematoriumComponent component, ExaminedEvent args) 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")); 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) 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)) if (!TryComp<EntityStorageComponent>(uid, out var storage))
return; 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; return;
AlternativeVerb verb = new() AlternativeVerb verb = new()
@@ -73,58 +75,56 @@ public sealed class CrematoriumSystem : EntitySystem
args.Verbs.Add(verb); 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)) if (!Resolve(uid, ref component, ref storage))
return; return false;
if (TryComp<AppearanceComponent>(uid, out var app)) if (HasComp<ActiveCrematoriumComponent>(uid))
app.SetData(CrematoriumVisuals.Burning, true); return false;
component.Cooking = true;
SoundSystem.Play(component.CrematingSound.GetSound(), Filter.Pvs(uid), uid); _audio.PlayPvs(component.CremateStartSound, uid);
_appearance.SetData(uid, CrematoriumVisuals.Burning, true);
component.CremateCancelToken?.Cancel(); _audio.PlayPvs(component.CrematingSound, uid);
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) AddComp<ActiveCrematoriumComponent>(uid);
{ return true;
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) 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)) if (!Resolve(uid, ref storage))
return; return;
if (component.Cooking || storage.Open || storage.Contents.ContainedEntities.Count < 1) _appearance.SetData(uid, CrematoriumVisuals.Burning, false);
return; 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) private void OnSuicide(EntityUid uid, CrematoriumComponent component, SuicideEvent args)
@@ -161,4 +161,17 @@ public sealed class CrematoriumSystem : EntitySystem
_entityStorage.CloseStorage(uid); _entityStorage.CloseStorage(uid);
Cremate(uid, component); 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);
}
}
} }

View File

@@ -2,17 +2,16 @@ using Content.Server.Morgue.Components;
using Content.Shared.Morgue; using Content.Shared.Morgue;
using Content.Shared.Examine; using Content.Shared.Examine;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Content.Server.Popups;
using Robust.Shared.Player;
using Robust.Shared.Audio;
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using Content.Shared.Body.Components; using Content.Shared.Body.Components;
using Content.Shared.Storage;
namespace Content.Server.Morgue; 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -54,7 +53,7 @@ public sealed partial class MorgueSystem : EntitySystem
if (storage.Contents.ContainedEntities.Count == 0) if (storage.Contents.ContainedEntities.Count == 0)
{ {
app.SetData(MorgueVisuals.Contents, MorgueContents.Empty); _appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.Empty);
return; return;
} }
@@ -65,14 +64,14 @@ public sealed partial class MorgueSystem : EntitySystem
if (!hasMob && HasComp<SharedBodyComponent>(ent)) if (!hasMob && HasComp<SharedBodyComponent>(ent))
hasMob = true; 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; return;
} }
} }
app.SetData(MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents); _appearance.SetData(uid, MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents, app);
} }
/// <summary> /// <summary>
@@ -86,7 +85,7 @@ public sealed partial class MorgueSystem : EntitySystem
{ {
comp.AccumulatedFrameTime += frameTime; comp.AccumulatedFrameTime += frameTime;
CheckContents(comp.Owner, comp, storage, appearance); CheckContents(comp.Owner, comp, storage);
if (comp.AccumulatedFrameTime < comp.BeepTime) if (comp.AccumulatedFrameTime < comp.BeepTime)
continue; continue;
@@ -95,7 +94,7 @@ public sealed partial class MorgueSystem : EntitySystem
if (comp.DoSoulBeep && appearance.TryGetData(MorgueVisuals.Contents, out MorgueContents contents) && contents == MorgueContents.HasSoul) 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);
} }
} }
} }

View File

@@ -59466,25 +59466,12 @@ entities:
pos: 26.5,10.5 pos: 26.5,10.5
parent: 69 parent: 69
type: Transform type: Transform
- uid: 5014
type: CrematoriumTray
components:
- parent: 5015
type: Transform
- canCollide: False
type: Physics
- uid: 5015 - uid: 5015
type: Crematorium type: Crematorium
components: components:
- pos: 25.5,13.5 - pos: 25.5,13.5
parent: 69 parent: 69
type: Transform type: Transform
- containers:
entity_storage: !type:Container
ents: []
morgue_tray: !type:ContainerSlot
ent: 5014
type: ContainerContainer
- uid: 5016 - uid: 5016
type: AsteroidRock type: AsteroidRock
components: components:

View File

@@ -2,6 +2,8 @@
id: Morgue id: Morgue
name: morgue name: morgue
description: Used to store bodies until someone fetches them. Includes a high-tech alert system for false-positives! description: Used to store bodies until someone fetches them. Includes a high-tech alert system for false-positives!
placement:
mode: SnapgridCenter
components: components:
- type: Sprite - type: Sprite
netsync: false netsync: false
@@ -45,7 +47,6 @@
- type: ContainerContainer - type: ContainerContainer
containers: containers:
entity_storage: !type:Container entity_storage: !type:Container
morgue_tray: !type:ContainerSlot
- type: Appearance - type: Appearance
- type: GenericVisualizer - type: GenericVisualizer
visuals: visuals:
@@ -71,32 +72,12 @@
- type: StaticPrice - type: StaticPrice
price: 200 price: 200
#needs to be removed
- type: entity
id: MorgueTray
name: morgue tray
description: If you lay down to have a rest on this, you'll soon have a problem.
noSpawn: true
components:
- type: Physics
bodyType: Static
- type: Fixtures
fixtures:
- shape:
!type:PhysShapeAabb
bounds: "-0.5,-0.5,0.5,0.5"
mass: 25
mask:
- Impassable
- type: Sprite
netsync: false
sprite: Structures/Storage/morgue.rsi
state: morgue_tray
- type: entity - type: entity
id: Crematorium id: Crematorium
name: crematorium name: crematorium
description: A human incinerator. Works well on barbecue nights. description: A human incinerator. Works well on barbecue nights.
placement:
mode: SnapgridCenter
components: components:
- type: Sprite - type: Sprite
netsync: false netsync: false
@@ -109,7 +90,11 @@
map: ["enum.StorageVisualLayers.Door"] map: ["enum.StorageVisualLayers.Door"]
- state: crema_contents_light - state: crema_contents_light
visible: false visible: false
map: ["enum.CrematoriumVisualLayers.Light"] map: ["enum.CrematoriumVisualLayers.LightContent"]
shader: unshaded
- state: crema_active_light
visible: false
map: ["enum.CrematoriumVisualLayers.LightBurning"]
shader: unshaded shader: unshaded
- type: Clickable - type: Clickable
- type: InteractionOutline - type: InteractionOutline
@@ -136,26 +121,24 @@
path: /Audio/Items/deconstruct.ogg path: /Audio/Items/deconstruct.ogg
- type: EntityStorageLayingDownOverride - type: EntityStorageLayingDownOverride
- type: Crematorium - type: Crematorium
- type: ContainerContainer
containers:
entity_storage: !type:Container
- type: Appearance - type: Appearance
visuals: visuals:
- type: StorageVisualizer - type: StorageVisualizer
state: crema_closed state: crema_closed
state_alt: crema_open state_alt: crema_open
state_open: crema_tray state_open: crema_tray
- type: CrematoriumVisuals - type: GenericVisualizer
lightContents: crema_contents_light visuals:
lightBurning: crema_active_light enum.CrematoriumVisuals.Burning:
enum.CrematoriumVisualLayers.LightBurning:
True: { visible: true }
False: { visible: false }
enum.StorageVisuals.HasContents:
enum.CrematoriumVisualLayers.LightContent:
True: { visible: true }
False: { visible: false }
- type: Transform - type: Transform
anchored: true anchored: true
#needs to be removed
- type: entity
id: CrematoriumTray
name: crematorium tray
parent: MorgueTray
noSpawn: true
components:
- type: Sprite
netsync: false
sprite: Structures/Storage/morgue.rsi
state: crema_tray