2025-03-02 13:28:13 +03:00
|
|
|
using Content.Server._CP14.Alchemy.Components;
|
2024-06-13 22:55:20 +03:00
|
|
|
using Content.Server._CP14.MagicEnergy;
|
2024-06-08 18:46:09 +03:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
|
|
|
|
using Content.Shared.FixedPoint;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
2025-02-28 15:55:47 +03:00
|
|
|
namespace Content.Server._CP14.Alchemy.EntitySystems;
|
2024-06-08 18:46:09 +03:00
|
|
|
|
2025-03-02 13:28:13 +03:00
|
|
|
public sealed partial class CP14SolutionCleanerSystem : EntitySystem
|
2024-06-08 18:46:09 +03:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
2024-06-13 22:55:20 +03:00
|
|
|
[Dependency] private readonly CP14MagicEnergyCrystalSlotSystem _magicSlot = default!;
|
2024-06-08 18:46:09 +03:00
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
2025-03-02 13:28:13 +03:00
|
|
|
var query = EntityQueryEnumerator<CP14SolutionCleanerComponent, SolutionContainerManagerComponent>();
|
2024-06-08 18:46:09 +03:00
|
|
|
while (query.MoveNext(out var uid, out var normalizer, out var containerManager))
|
|
|
|
|
{
|
|
|
|
|
if (_timing.CurTime <= normalizer.NextUpdateTime)
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-06-13 22:55:20 +03:00
|
|
|
if (!_magicSlot.HasEnergy(uid, 1))
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-06-08 18:46:09 +03:00
|
|
|
normalizer.NextUpdateTime = _timing.CurTime + normalizer.UpdateFrequency;
|
|
|
|
|
|
|
|
|
|
var solutionManager = new Entity<SolutionContainerManagerComponent?>(uid, containerManager);
|
|
|
|
|
|
|
|
|
|
if (!_solutionContainer.TryGetSolution(solutionManager,
|
|
|
|
|
normalizer.Solution,
|
|
|
|
|
out var solutionEnt,
|
|
|
|
|
out var solution))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (solution.Volume == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-03-02 13:28:13 +03:00
|
|
|
var minQuantity = FixedPoint2.MaxValue;
|
|
|
|
|
ReagentId? reagentId = null;
|
2024-06-08 18:46:09 +03:00
|
|
|
foreach (var (id, quantity) in solution.Contents)
|
|
|
|
|
{
|
2025-03-02 13:28:13 +03:00
|
|
|
if (quantity < minQuantity)
|
2024-06-08 18:46:09 +03:00
|
|
|
{
|
2025-03-02 13:28:13 +03:00
|
|
|
reagentId = id;
|
|
|
|
|
minQuantity = quantity;
|
2024-06-08 18:46:09 +03:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-02 13:28:13 +03:00
|
|
|
|
|
|
|
|
if (reagentId == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
_solutionContainer.RemoveReagent(solutionEnt.Value, reagentId.Value, normalizer.LeakageQuantity);
|
|
|
|
|
_audio.PlayPvs(normalizer.NormalizeSound, uid);
|
2024-06-08 18:46:09 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|