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>
This commit is contained in:
deltanedas
2024-05-07 18:20:43 +00:00
committed by GitHub
parent 6301e94390
commit 262b9698cf
4 changed files with 116 additions and 18 deletions

View File

@@ -0,0 +1,33 @@
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;
}
}