1
0

MorgueSystem.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Content.Server.Storage.Components;
  2. using Content.Shared.Body.Components;
  3. using Content.Shared.Examine;
  4. using Content.Shared.Morgue;
  5. using Content.Shared.Morgue.Components;
  6. using Robust.Shared.Audio.Systems;
  7. using Robust.Shared.Player;
  8. namespace Content.Server.Morgue;
  9. public sealed class MorgueSystem : EntitySystem
  10. {
  11. [Dependency] private readonly SharedAudioSystem _audio = default!;
  12. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<MorgueComponent, ExaminedEvent>(OnExamine);
  17. }
  18. /// <summary>
  19. /// Handles the examination text for looking at a morgue.
  20. /// </summary>
  21. private void OnExamine(Entity<MorgueComponent> ent, ref ExaminedEvent args)
  22. {
  23. if (!args.IsInDetailsRange)
  24. return;
  25. _appearance.TryGetData<MorgueContents>(ent.Owner, MorgueVisuals.Contents, out var contents);
  26. var text = contents switch
  27. {
  28. MorgueContents.HasSoul => "morgue-entity-storage-component-on-examine-details-body-has-soul",
  29. MorgueContents.HasContents => "morgue-entity-storage-component-on-examine-details-has-contents",
  30. MorgueContents.HasMob => "morgue-entity-storage-component-on-examine-details-body-has-no-soul",
  31. _ => "morgue-entity-storage-component-on-examine-details-empty"
  32. };
  33. args.PushMarkup(Loc.GetString(text));
  34. }
  35. /// <summary>
  36. /// Updates data periodically in case something died/got deleted in the morgue.
  37. /// </summary>
  38. private void CheckContents(EntityUid uid, MorgueComponent? morgue = null, EntityStorageComponent? storage = null, AppearanceComponent? app = null)
  39. {
  40. if (!Resolve(uid, ref morgue, ref storage, ref app))
  41. return;
  42. if (storage.Contents.ContainedEntities.Count == 0)
  43. {
  44. _appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.Empty);
  45. return;
  46. }
  47. var hasMob = false;
  48. foreach (var ent in storage.Contents.ContainedEntities)
  49. {
  50. if (!hasMob && HasComp<BodyComponent>(ent))
  51. hasMob = true;
  52. if (HasComp<ActorComponent>(ent))
  53. {
  54. _appearance.SetData(uid, MorgueVisuals.Contents, MorgueContents.HasSoul, app);
  55. return;
  56. }
  57. }
  58. _appearance.SetData(uid, MorgueVisuals.Contents, hasMob ? MorgueContents.HasMob : MorgueContents.HasContents, app);
  59. }
  60. /// <summary>
  61. /// Handles the periodic beeping that morgues do when a live body is inside.
  62. /// </summary>
  63. public override void Update(float frameTime)
  64. {
  65. base.Update(frameTime);
  66. var query = EntityQueryEnumerator<MorgueComponent, EntityStorageComponent, AppearanceComponent>();
  67. while (query.MoveNext(out var uid, out var comp, out var storage, out var appearance))
  68. {
  69. comp.AccumulatedFrameTime += frameTime;
  70. CheckContents(uid, comp, storage);
  71. if (comp.AccumulatedFrameTime < comp.BeepTime)
  72. continue;
  73. comp.AccumulatedFrameTime -= comp.BeepTime;
  74. if (comp.DoSoulBeep && _appearance.TryGetData<MorgueContents>(uid, MorgueVisuals.Contents, out var contents, appearance) && contents == MorgueContents.HasSoul)
  75. {
  76. _audio.PlayPvs(comp.OccupantHasSoulAlarmSound, uid);
  77. }
  78. }
  79. }
  80. }