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.
This commit is contained in:
Psychpsyo
2023-10-31 21:39:12 +01:00
committed by GitHub
parent 672969b710
commit 6a18bdc023
57 changed files with 415 additions and 78 deletions

View File

@@ -1,7 +1,6 @@
using Content.Server.Popups;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
using Content.Shared.Fluids.Components;
@@ -9,6 +8,7 @@ using Content.Shared.Interaction;
using Content.Shared.Timing;
using Content.Shared.Weapons.Melee;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
@@ -17,6 +17,7 @@ namespace Content.Server.Fluids.EntitySystems;
/// <inheritdoc/>
public sealed class AbsorbentSystem : SharedAbsorbentSystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popups = default!;
@@ -55,13 +56,13 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
var oldProgress = component.Progress.ShallowClone();
component.Progress.Clear();
var water = solution.GetTotalPrototypeQuantity(PuddleSystem.EvaporationReagent);
var water = solution.GetTotalPrototypeQuantity(PuddleSystem.EvaporationReagents);
if (water > FixedPoint2.Zero)
{
component.Progress[_prototype.Index<ReagentPrototype>(PuddleSystem.EvaporationReagent).SubstanceColor] = water.Float();
component.Progress[solution.GetColorWithOnly(_prototype, PuddleSystem.EvaporationReagents)] = water.Float();
}
var otherColor = solution.GetColorWithout(_prototype, PuddleSystem.EvaporationReagent);
var otherColor = solution.GetColorWithout(_prototype, PuddleSystem.EvaporationReagents);
var other = (solution.Volume - water).Float();
if (other > 0f)
@@ -140,7 +141,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
// Remove the non-water reagents.
// Remove water on target
// Then do the transfer.
var nonWater = absorberSoln.SplitSolutionWithout(component.PickupAmount, PuddleSystem.EvaporationReagent);
var nonWater = absorberSoln.SplitSolutionWithout(component.PickupAmount, PuddleSystem.EvaporationReagents);
_solutionContainerSystem.UpdateChemicals(used, absorberSoln, true);
if (nonWater.Volume == FixedPoint2.Zero && absorberSoln.AvailableVolume == FixedPoint2.Zero)
@@ -153,18 +154,16 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
component.PickupAmount :
absorberSoln.AvailableVolume;
var water = refillableSolution.RemoveReagent(PuddleSystem.EvaporationReagent, transferAmount);
var water = refillableSolution.SplitSolutionWithOnly(transferAmount, PuddleSystem.EvaporationReagents);
_solutionContainerSystem.UpdateChemicals(target, refillableSolution);
if (water == FixedPoint2.Zero && nonWater.Volume == FixedPoint2.Zero)
if (water.Volume == FixedPoint2.Zero && nonWater.Volume == FixedPoint2.Zero)
{
_popups.PopupEntity(Loc.GetString("mopping-system-target-container-empty-water", ("target", target)), user, user);
return false;
}
if (water > 0 && !_solutionContainerSystem.TryAddReagent(used, absorberSoln, PuddleSystem.EvaporationReagent, water,
out _))
if (water.Volume > 0 && !_solutionContainerSystem.TryAddSolution(used, absorberSoln, water))
{
_popups.PopupEntity(Loc.GetString("mopping-system-full", ("used", used)), used, user);
}
@@ -217,18 +216,18 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
if (!TryComp(target, out PuddleComponent? puddle))
return false;
if (!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSolution) || puddleSolution.Volume <= 0)
if (!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSoln) || puddleSoln.Volume <= 0)
return false;
// Check if the puddle has any non-evaporative reagents
if (_puddleSystem.CanFullyEvaporate(puddleSolution))
if (_puddleSystem.CanFullyEvaporate(puddleSoln))
{
_popups.PopupEntity(Loc.GetString("mopping-system-puddle-evaporate", ("target", target)), user, user);
return true;
}
// Check if we have any evaporative reagents on our absorber to transfer
var available = absorberSoln.GetTotalPrototypeQuantity(PuddleSystem.EvaporationReagent);
var available = absorberSoln.GetTotalPrototypeQuantity(PuddleSystem.EvaporationReagents);
// No material
if (available == FixedPoint2.Zero)
@@ -240,14 +239,21 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
var transferMax = absorber.PickupAmount;
var transferAmount = available > transferMax ? transferMax : available;
var split = puddleSolution.SplitSolutionWithout(transferAmount, PuddleSystem.EvaporationReagent);
var puddleSplit = puddleSoln.SplitSolutionWithout(transferAmount, PuddleSystem.EvaporationReagents);
var absorberSplit = absorberSoln.SplitSolutionWithOnly(puddleSplit.Volume, PuddleSystem.EvaporationReagents);
absorberSoln.RemoveReagent(PuddleSystem.EvaporationReagent, split.Volume);
puddleSolution.AddReagent(PuddleSystem.EvaporationReagent, split.Volume);
absorberSoln.AddSolution(split, _prototype);
// Do tile reactions first
var coordinates = Transform(target).Coordinates;
if (_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
{
_puddleSystem.DoTileReactions(mapGrid.GetTileRef(coordinates), absorberSplit);
}
puddleSoln.AddSolution(absorberSplit, _prototype);
absorberSoln.AddSolution(puddleSplit, _prototype);
_solutionSystem.UpdateChemicals(used, absorberSoln);
_solutionSystem.UpdateChemicals(target, puddleSolution);
_solutionSystem.UpdateChemicals(target, puddleSoln);
_audio.PlayPvs(absorber.PickupSound, target);
_useDelay.BeginDelay(used);

View File

@@ -11,7 +11,12 @@ public sealed partial class PuddleSystem
private static readonly TimeSpan EvaporationCooldown = TimeSpan.FromSeconds(1);
[ValidatePrototypeId<ReagentPrototype>]
public const string EvaporationReagent = "Water";
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)
{
@@ -25,7 +30,7 @@ public sealed partial class PuddleSystem
return;
}
if (solution.ContainsPrototype(EvaporationReagent))
if (solution.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
{
var evaporation = AddComp<EvaporationComponent>(uid);
evaporation.NextTick = _timing.CurTime + EvaporationCooldown;
@@ -51,7 +56,7 @@ public sealed partial class PuddleSystem
continue;
var reagentTick = evaporation.EvaporationAmount * EvaporationCooldown.TotalSeconds;
_solutionContainerSystem.RemoveReagent(uid, puddleSolution, EvaporationReagent, reagentTick);
puddleSolution.SplitSolutionWithOnly(reagentTick, EvaporationReagents);
// Despawn if we're done
if (puddleSolution.Volume == FixedPoint2.Zero)
@@ -65,6 +70,6 @@ public sealed partial class PuddleSystem
public bool CanFullyEvaporate(Solution solution)
{
return solution.Contents.Count == 1 && solution.ContainsPrototype(EvaporationReagent);
return solution.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume;
}
}

View File

@@ -373,7 +373,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
{
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating"));
}
else if (solution?.ContainsPrototype(EvaporationReagent) == true)
else if (solution?.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
{
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-partial"));
}
@@ -602,16 +602,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
if (tileReact)
{
// First, do all tile reactions
for (var i = solution.Contents.Count - 1; i >= 0; i--)
{
var (reagent, quantity) = solution.Contents[i];
var proto = _prototypeManager.Index<ReagentPrototype>(reagent.Prototype);
var removed = proto.ReactionTile(tileRef, quantity);
if (removed <= FixedPoint2.Zero)
continue;
solution.RemoveReagent(reagent, removed);
}
DoTileReactions(tileRef, solution);
}
// Tile reactions used up everything.
@@ -660,6 +651,21 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
#endregion
public void DoTileReactions(TileRef tileRef, Solution solution)
{
for (var i = solution.Contents.Count - 1; i >= 0; i--)
{
var (reagent, quantity) = solution.Contents[i];
var proto = _prototypeManager.Index<ReagentPrototype>(reagent.Prototype);
var removed = proto.ReactionTile(tileRef, quantity);
if (removed <= FixedPoint2.Zero)
continue;
solution.RemoveReagent(reagent, removed);
}
}
/// <summary>
/// Tries to get the relevant puddle entity for a tile.
/// </summary>