DeleteOnSolutionEmptySystem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Content.Server.Chemistry.Components.DeleteOnSolutionEmptyComponent;
  2. using Content.Shared.Chemistry.Components.SolutionManager;
  3. using Content.Shared.Chemistry.EntitySystems;
  4. namespace Content.Server.Chemistry.EntitySystems.DeleteOnSolutionEmptySystem
  5. {
  6. public sealed class DeleteOnSolutionEmptySystem : EntitySystem
  7. {
  8. [Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<DeleteOnSolutionEmptyComponent, ComponentStartup>(OnStartup);
  13. SubscribeLocalEvent<DeleteOnSolutionEmptyComponent, SolutionContainerChangedEvent>(OnSolutionChange);
  14. }
  15. public void OnStartup(Entity<DeleteOnSolutionEmptyComponent> entity, ref ComponentStartup args)
  16. {
  17. CheckSolutions(entity);
  18. }
  19. public void OnSolutionChange(Entity<DeleteOnSolutionEmptyComponent> entity, ref SolutionContainerChangedEvent args)
  20. {
  21. CheckSolutions(entity);
  22. }
  23. public void CheckSolutions(Entity<DeleteOnSolutionEmptyComponent> entity)
  24. {
  25. if (!TryComp(entity, out SolutionContainerManagerComponent? solutions))
  26. return;
  27. if (_solutionContainerSystem.TryGetSolution((entity.Owner, solutions), entity.Comp.Solution, out _, out var solution))
  28. if (solution.Volume <= 0)
  29. EntityManager.QueueDeleteEntity(entity);
  30. }
  31. }
  32. }