Files
tbd-station-14/Content.Server/Fluids/EntitySystems/PuddleSystem.Evaporation.cs
Psychpsyo 6a18bdc023 Soapy Water & Edible Soap (#20364)
* soap reagent and soapy water

* make soapy water recognizable

* Fix tile cleaning bug

CleanDecalsReaction was able to take more than the reactVolume it was given.

* make soapy water an evaporating reagent

* Tile reactions when mopping

* Fix indescribably soap flavor

* Adjust soap flavours

Soap and soapy water now taste clean and syndie soap tastes like punishment.

* Better soap numbers & DeleteOnSolutionEmpty

* Changed TrashOnEmpty to TrashOnSolutionEmpty

* Last TrashOnSolutionEmpty change

* Fix merged code not compiling

* Requested changes.
2023-10-31 13:39:12 -07:00

76 lines
2.5 KiB
C#

using Content.Server.Fluids.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
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);
[ValidatePrototypeId<ReagentPrototype>]
private const string Water = "Water";
[ValidatePrototypeId<ReagentPrototype>]
private const string SoapyWater = "SoapyWater";
public static string[] EvaporationReagents = new[] { Water, SoapyWater };
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.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
{
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.SplitSolutionWithOnly(reagentTick, EvaporationReagents);
// 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.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume;
}
}