Files
tbd-station-14/Content.Shared/ReagentSpeed/ReagentSpeedSystem.cs
deltanedas 262b9698cf make lube speed up lathes (#25515)
* add LatheGetSpeedEvent

* add LatheLube system

* make typical lathes accept lube

* spill

* :trollface:

* rework to generic ReagentSpeedSystem

* hyperlathe ops

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
2024-05-07 14:20:43 -04:00

34 lines
1.1 KiB
C#

using Content.Shared.Chemistry.EntitySystems;
namespace Content.Shared.ReagentSpeed;
public sealed class ReagentSpeedSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
/// <summary>
/// Consumes reagents and modifies the duration.
/// This can be production time firing delay etc.
/// </summary>
public TimeSpan ApplySpeed(Entity<ReagentSpeedComponent?> ent, TimeSpan time)
{
if (!Resolve(ent, ref ent.Comp, false))
return time;
if (!_solution.TryGetSolution(ent.Owner, ent.Comp.Solution, out _, out var solution))
return time;
foreach (var (reagent, fullModifier) in ent.Comp.Modifiers)
{
var used = solution.RemoveReagent(reagent, ent.Comp.Cost);
var efficiency = (used / ent.Comp.Cost).Float();
// scale the speed modifier so microdosing has less effect
var reduction = (1f - fullModifier) * efficiency;
var modifier = 1f - reduction;
time *= modifier;
}
return time;
}
}