2023-04-10 15:37:03 +10:00
|
|
|
using Content.Shared.Chemistry.Components;
|
|
|
|
|
using Content.Shared.FixedPoint;
|
|
|
|
|
using Content.Shared.Fluids.Components;
|
2024-09-28 18:09:30 +03:00
|
|
|
using Content.Shared.Maps;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Map.Components;
|
2023-04-10 15:37:03 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.Fluids.EntitySystems;
|
|
|
|
|
|
|
|
|
|
public sealed partial class PuddleSystem
|
|
|
|
|
{
|
2024-09-28 18:09:30 +03:00
|
|
|
[Dependency] private readonly SharedMapSystem _maps = default!; //CP14
|
|
|
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; //CP14
|
2023-04-10 15:37:03 +10:00
|
|
|
private static readonly TimeSpan EvaporationCooldown = TimeSpan.FromSeconds(1);
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnEvaporationMapInit(Entity<EvaporationComponent> entity, ref MapInitEvent args)
|
2023-04-10 15:37:03 +10:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
entity.Comp.NextTick = _timing.CurTime + EvaporationCooldown;
|
2024-09-28 18:09:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//CP14 Force evaporation under sky
|
|
|
|
|
var xform = Transform(entity);
|
|
|
|
|
if (TryComp<MapGridComponent>(xform.GridUid, out var mapGrid))
|
|
|
|
|
{
|
|
|
|
|
var tileRef = _maps.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates);
|
|
|
|
|
var tileDef = (ContentTileDefinition) _tileDefManager[tileRef.Tile.TypeId];
|
|
|
|
|
|
|
|
|
|
entity.Comp.CP14ForceEvaporation = tileDef.Weather;
|
|
|
|
|
}
|
|
|
|
|
//CP14 End force evaporation under sky
|
2023-04-10 15:37:03 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateEvaporation(EntityUid uid, Solution solution)
|
|
|
|
|
{
|
|
|
|
|
if (HasComp<EvaporationComponent>(uid))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 21:39:12 +01:00
|
|
|
if (solution.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
|
2023-04-10 15:37:03 +10:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!_solutionContainerSystem.ResolveSolution(uid, puddle.SolutionName, ref puddle.Solution, out var puddleSolution))
|
2023-04-10 15:37:03 +10:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var reagentTick = evaporation.EvaporationAmount * EvaporationCooldown.TotalSeconds;
|
2024-09-28 18:09:30 +03:00
|
|
|
|
|
|
|
|
//CP14 Force evaporation
|
|
|
|
|
if (!evaporation.CP14ForceEvaporation)
|
|
|
|
|
puddleSolution.SplitSolutionWithOnly(reagentTick, EvaporationReagents);
|
|
|
|
|
else
|
|
|
|
|
puddleSolution.SplitSolution(reagentTick);
|
|
|
|
|
//CP14 end force evaporation
|
2023-04-10 15:37:03 +10:00
|
|
|
|
|
|
|
|
// Despawn if we're done
|
|
|
|
|
if (puddleSolution.Volume == FixedPoint2.Zero)
|
|
|
|
|
{
|
|
|
|
|
// Spawn a *sparkle*
|
|
|
|
|
Spawn("PuddleSparkle", xformQuery.GetComponent(uid).Coordinates);
|
|
|
|
|
QueueDel(uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|