CatStation/Content.Shared/Chemistry/EntitySystems/SolutionPurgeSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

46 lines
1.5 KiB
C#

using System.Linq;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Robust.Shared.Timing;
namespace Content.Shared.Chemistry.EntitySystems;
public sealed partial class SolutionPurgeSystem : EntitySystem
{
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SolutionPurgeComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<SolutionPurgeComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextPurgeTime = _timing.CurTime + ent.Comp.Duration;
Dirty(ent);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<SolutionPurgeComponent, SolutionComponent>();
while (query.MoveNext(out var uid, out var purge, out var solution))
{
if (_timing.CurTime < purge.NextPurgeTime)
continue;
// timer ignores if it's empty, it's just a fixed cycle
purge.NextPurgeTime += purge.Duration;
// Needs to be networked and dirtied so that the client can reroll it during prediction
Dirty(uid, purge);
_solutionContainer.SplitSolutionWithout((uid, solution),
purge.Quantity,
purge.Preserve.ToArray());
}
}
}