SharedArtifactCrusherSystem.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Content.Shared.Examine;
  2. using Content.Shared.Storage.Components;
  3. using Robust.Shared.Audio.Systems;
  4. using Robust.Shared.Containers;
  5. using Content.Shared.Emag.Systems;
  6. namespace Content.Shared.Xenoarchaeology.Equipment;
  7. /// <summary>
  8. /// This handles logic relating to <see cref="ArtifactCrusherComponent"/>
  9. /// </summary>
  10. public abstract class SharedArtifactCrusherSystem : EntitySystem
  11. {
  12. [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
  13. [Dependency] protected readonly SharedAudioSystem AudioSystem = default!;
  14. [Dependency] protected readonly SharedContainerSystem ContainerSystem = default!;
  15. [Dependency] private readonly EmagSystem _emag = default!;
  16. /// <inheritdoc/>
  17. public override void Initialize()
  18. {
  19. base.Initialize();
  20. SubscribeLocalEvent<ArtifactCrusherComponent, ComponentInit>(OnInit);
  21. SubscribeLocalEvent<ArtifactCrusherComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
  22. SubscribeLocalEvent<ArtifactCrusherComponent, StorageOpenAttemptEvent>(OnStorageOpenAttempt);
  23. SubscribeLocalEvent<ArtifactCrusherComponent, ExaminedEvent>(OnExamine);
  24. SubscribeLocalEvent<ArtifactCrusherComponent, GotEmaggedEvent>(OnEmagged);
  25. }
  26. private void OnInit(Entity<ArtifactCrusherComponent> ent, ref ComponentInit args)
  27. {
  28. ent.Comp.OutputContainer = ContainerSystem.EnsureContainer<Container>(ent, ent.Comp.OutputContainerName);
  29. }
  30. private void OnStorageAfterOpen(Entity<ArtifactCrusherComponent> ent, ref StorageAfterOpenEvent args)
  31. {
  32. StopCrushing(ent);
  33. ContainerSystem.EmptyContainer(ent.Comp.OutputContainer);
  34. }
  35. private void OnEmagged(Entity<ArtifactCrusherComponent> ent, ref GotEmaggedEvent args)
  36. {
  37. if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
  38. return;
  39. if (_emag.CheckFlag(ent, EmagType.Interaction))
  40. return;
  41. if (ent.Comp.AutoLock)
  42. return;
  43. ent.Comp.AutoLock = true;
  44. args.Handled = true;
  45. }
  46. private void OnStorageOpenAttempt(Entity<ArtifactCrusherComponent> ent, ref StorageOpenAttemptEvent args)
  47. {
  48. if (ent.Comp.AutoLock && ent.Comp.Crushing)
  49. args.Cancelled = true;
  50. }
  51. private void OnExamine(Entity<ArtifactCrusherComponent> ent, ref ExaminedEvent args)
  52. {
  53. args.PushMarkup(ent.Comp.AutoLock ? Loc.GetString("artifact-crusher-examine-autolocks") : Loc.GetString("artifact-crusher-examine-no-autolocks"));
  54. }
  55. public void StopCrushing(Entity<ArtifactCrusherComponent> ent, bool early = true)
  56. {
  57. var (_, crusher) = ent;
  58. if (!crusher.Crushing)
  59. return;
  60. crusher.Crushing = false;
  61. Appearance.SetData(ent, ArtifactCrusherVisuals.Crushing, false);
  62. if (early)
  63. {
  64. AudioSystem.Stop(crusher.CrushingSoundEntity?.Item1, crusher.CrushingSoundEntity?.Item2);
  65. crusher.CrushingSoundEntity = null;
  66. }
  67. Dirty(ent, ent.Comp);
  68. }
  69. }