ReagentSpeedSystem.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using Content.Shared.Chemistry.EntitySystems;
  2. namespace Content.Shared.ReagentSpeed;
  3. public sealed class ReagentSpeedSystem : EntitySystem
  4. {
  5. [Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
  6. /// <summary>
  7. /// Consumes reagents and modifies the duration.
  8. /// This can be production time firing delay etc.
  9. /// </summary>
  10. public TimeSpan ApplySpeed(Entity<ReagentSpeedComponent?> ent, TimeSpan time)
  11. {
  12. if (!Resolve(ent, ref ent.Comp, false))
  13. return time;
  14. if (!_solution.TryGetSolution(ent.Owner, ent.Comp.Solution, out _, out var solution))
  15. return time;
  16. foreach (var (reagent, fullModifier) in ent.Comp.Modifiers)
  17. {
  18. var used = solution.RemoveReagent(reagent, ent.Comp.Cost);
  19. var efficiency = (used / ent.Comp.Cost).Float();
  20. // scale the speed modifier so microdosing has less effect
  21. var reduction = (1f - fullModifier) * efficiency;
  22. var modifier = 1f - reduction;
  23. time *= modifier;
  24. }
  25. return time;
  26. }
  27. }