Advanced Mop is now More Advanced + SolutionPurge Component (#15532)
Co-authored-by: Arimah <arimah42@gmail.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems;
|
||||
|
||||
public sealed class SolutionPurgeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SolutionPurgeComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||
SubscribeLocalEvent<SolutionPurgeComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<SolutionPurgeComponent, SolutionContainerManagerComponent>();
|
||||
while (query.MoveNext(out var uid, out var purge, out var manager))
|
||||
{
|
||||
if (_timing.CurTime < purge.NextPurgeTime)
|
||||
continue;
|
||||
|
||||
// timer ignores if it's empty, it's just a fixed cycle
|
||||
purge.NextPurgeTime += purge.Duration;
|
||||
if (_solutionContainer.TryGetSolution(uid, purge.Solution, out var solution, manager))
|
||||
_solutionContainer.SplitSolutionWithout(uid, solution, purge.Quantity, purge.Preserve.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnpaused(EntityUid uid, SolutionPurgeComponent comp, ref EntityUnpausedEvent args)
|
||||
{
|
||||
comp.NextPurgeTime += args.PausedTime;
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, SolutionPurgeComponent comp, MapInitEvent args)
|
||||
{
|
||||
if (comp.NextPurgeTime < _timing.CurTime)
|
||||
comp.NextPurgeTime = _timing.CurTime;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user