Puddles & spreader refactor (#15191)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids.Components;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
public sealed partial class PuddleSystem
|
||||
{
|
||||
private static readonly TimeSpan EvaporationCooldown = TimeSpan.FromSeconds(1);
|
||||
|
||||
public const string EvaporationReagent = "Water";
|
||||
|
||||
private void OnEvaporationMapInit(EntityUid uid, EvaporationComponent component, MapInitEvent args)
|
||||
{
|
||||
component.NextTick = _timing.CurTime + EvaporationCooldown;
|
||||
}
|
||||
|
||||
private void UpdateEvaporation(EntityUid uid, Solution solution)
|
||||
{
|
||||
if (HasComp<EvaporationComponent>(uid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (solution.ContainsReagent(EvaporationReagent))
|
||||
{
|
||||
var evaporation = AddComp<EvaporationComponent>(uid);
|
||||
evaporation.NextTick = _timing.CurTime + EvaporationCooldown;
|
||||
return;
|
||||
}
|
||||
|
||||
RemComp<EvaporationComponent>(uid);
|
||||
}
|
||||
|
||||
private void TickEvaporation()
|
||||
{
|
||||
var query = EntityQueryEnumerator<EvaporationComponent, PuddleComponent>();
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
while (query.MoveNext(out var uid, out var evaporation, out var puddle))
|
||||
{
|
||||
if (evaporation.NextTick > curTime)
|
||||
continue;
|
||||
|
||||
evaporation.NextTick += EvaporationCooldown;
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(uid, puddle.SolutionName, out var puddleSolution))
|
||||
continue;
|
||||
|
||||
var reagentTick = evaporation.EvaporationAmount * EvaporationCooldown.TotalSeconds;
|
||||
puddleSolution.RemoveReagent(EvaporationReagent, reagentTick);
|
||||
|
||||
// Despawn if we're done
|
||||
if (puddleSolution.Volume == FixedPoint2.Zero)
|
||||
{
|
||||
// Spawn a *sparkle*
|
||||
Spawn("PuddleSparkle", xformQuery.GetComponent(uid).Coordinates);
|
||||
QueueDel(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanFullyEvaporate(Solution solution)
|
||||
{
|
||||
return solution.Contents.Count == 1 && solution.ContainsReagent(EvaporationReagent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user