SolutionRegenerationSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Chemistry.Components;
  2. using Content.Shared.Chemistry.EntitySystems;
  3. using Content.Shared.Chemistry.Components;
  4. using Content.Shared.Chemistry.Components.SolutionManager;
  5. using Content.Shared.FixedPoint;
  6. using Robust.Shared.Timing;
  7. namespace Content.Server.Chemistry.EntitySystems;
  8. public sealed class SolutionRegenerationSystem : EntitySystem
  9. {
  10. [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
  11. [Dependency] private readonly IGameTiming _timing = default!;
  12. public override void Update(float frameTime)
  13. {
  14. base.Update(frameTime);
  15. var query = EntityQueryEnumerator<SolutionRegenerationComponent, SolutionContainerManagerComponent>();
  16. while (query.MoveNext(out var uid, out var regen, out var manager))
  17. {
  18. if (_timing.CurTime < regen.NextRegenTime)
  19. continue;
  20. // timer ignores if its full, it's just a fixed cycle
  21. regen.NextRegenTime = _timing.CurTime + regen.Duration;
  22. if (_solutionContainer.ResolveSolution((uid, manager), regen.SolutionName, ref regen.SolutionRef, out var solution))
  23. {
  24. var amount = FixedPoint2.Min(solution.AvailableVolume, regen.Generated.Volume);
  25. if (amount <= FixedPoint2.Zero)
  26. continue;
  27. // dont bother cloning and splitting if adding the whole thing
  28. Solution generated;
  29. if (amount == regen.Generated.Volume)
  30. {
  31. generated = regen.Generated;
  32. }
  33. else
  34. {
  35. generated = regen.Generated.Clone().SplitSolution(amount);
  36. }
  37. _solutionContainer.TryAddSolution(regen.SolutionRef.Value, generated);
  38. }
  39. }
  40. }
  41. }