1
0

TrashOnSolutionEmptySystem.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Content.Server.Nutrition.Components;
  2. using Content.Shared.Chemistry.Components;
  3. using Content.Shared.Chemistry.Components.SolutionManager;
  4. using Content.Shared.Chemistry.EntitySystems;
  5. using Content.Shared.Tag;
  6. namespace Content.Server.Nutrition.EntitySystems
  7. {
  8. public sealed class TrashOnSolutionEmptySystem : EntitySystem
  9. {
  10. [Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
  11. [Dependency] private readonly TagSystem _tagSystem = default!;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. SubscribeLocalEvent<TrashOnSolutionEmptyComponent, MapInitEvent>(OnMapInit);
  16. SubscribeLocalEvent<TrashOnSolutionEmptyComponent, SolutionContainerChangedEvent>(OnSolutionChange);
  17. }
  18. public void OnMapInit(Entity<TrashOnSolutionEmptyComponent> entity, ref MapInitEvent args)
  19. {
  20. CheckSolutions(entity);
  21. }
  22. public void OnSolutionChange(Entity<TrashOnSolutionEmptyComponent> entity, ref SolutionContainerChangedEvent args)
  23. {
  24. CheckSolutions(entity);
  25. }
  26. public void CheckSolutions(Entity<TrashOnSolutionEmptyComponent> entity)
  27. {
  28. if (!EntityManager.HasComponent<SolutionContainerManagerComponent>(entity))
  29. return;
  30. if (_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.Solution, out _, out var solution))
  31. UpdateTags(entity, solution);
  32. }
  33. public void UpdateTags(Entity<TrashOnSolutionEmptyComponent> entity, Solution solution)
  34. {
  35. if (solution.Volume <= 0)
  36. {
  37. _tagSystem.AddTag(entity.Owner, "Trash");
  38. return;
  39. }
  40. if (_tagSystem.HasTag(entity.Owner, "Trash"))
  41. _tagSystem.RemoveTag(entity.Owner, "Trash");
  42. }
  43. }
  44. }