mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* 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
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.FixedPoint;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Chemistry.EntitySystems;
|
|
|
|
public sealed partial class SolutionRegenerationSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<SolutionRegenerationComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(Entity<SolutionRegenerationComponent> ent, ref MapInitEvent args)
|
|
{
|
|
ent.Comp.NextRegenTime = _timing.CurTime + ent.Comp.Duration;
|
|
|
|
Dirty(ent);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
// TODO: SolutionRegenerationComponent on Solution Entities!
|
|
var query = EntityQueryEnumerator<SolutionRegenerationComponent, SolutionComponent>();
|
|
while (query.MoveNext(out var uid, out var regen, out var solution))
|
|
{
|
|
if (_timing.CurTime < regen.NextRegenTime)
|
|
continue;
|
|
|
|
// timer ignores if its full, it's just a fixed cycle
|
|
regen.NextRegenTime += regen.Duration;
|
|
// Needs to be networked and dirtied so that the client can reroll it during prediction
|
|
Dirty(uid, regen);
|
|
var amount = FixedPoint2.Min(solution.Solution.AvailableVolume, regen.Generated.Volume);
|
|
if (amount <= FixedPoint2.Zero)
|
|
continue;
|
|
|
|
// Don't bother cloning and splitting if adding the whole thing
|
|
var generated = amount == regen.Generated.Volume
|
|
? regen.Generated
|
|
: regen.Generated.Clone().SplitSolution(amount);
|
|
|
|
_solutionContainer.TryAddSolution((uid, solution), generated);
|
|
}
|
|
}
|
|
}
|