Solution refactor (#4407)
* Rename SolutionContainerCaps -> Capability * Move IExamine event to Chemistry System. * ECS the ISolutionChange into SolutionChangeEvent * Unify SolutionContainer into a single shared component * Replace ISolutionInteraction with SolutionContainerComponent * Move all methods from SolutionContainer to ChemistrySystem * Refactor EntitySystem calls to Dependencies * Refactor SolutionContainer to SolutionManager * Fix yamls * Fix test fails * Fix post merge issues * Fix various issues with SolutionManager * More fixes * Fix more components * Fix events not being directed * Fixes for Hypospray * Separate removal and iteration on Metabolism * Fix creampie problems * Address some of sloth's issues * Refactors for Systems * Refactored solution location * Fix tests * Address more sloth issues * Fix dependency * Fix merge conflicts * Add xmldocs for Capabilities components * Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable * Replace Grindable/Juiceable with Extractable * Refactor field names * Fix Drainable * Fix some issues with spillable and injector * Fix issues with Grinder * Fix Beaker having duplicate solutions * Fix foaming * Address some MGS issues * Fix Uid issues * Fix errors in solution Tranfer * Fixed some extra values constant values * Cola is drinkable now
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -23,38 +22,37 @@ namespace Content.Server.Fluids.Components
|
||||
public class BucketComponent : Component, IInteractUsing
|
||||
{
|
||||
public override string Name => "Bucket";
|
||||
public const string SolutionName = "bucket";
|
||||
|
||||
private List<EntityUid> _currentlyUsing = new();
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => Owner.TryGetComponent(out SolutionContainerComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
|
||||
get =>
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
? solution.MaxVolume
|
||||
: ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
solution.MaxVolume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => Owner.TryGetComponent(out SolutionContainerComponent? solution)
|
||||
public ReagentUnit CurrentVolume => EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
|
||||
[DataField("sound")]
|
||||
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Effects/Fluids/watersplash.ogg");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponentWarn<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents) ||
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
if (!solutionsSys.TryGetSolution(Owner, SolutionName, out var contents) ||
|
||||
_currentlyUsing.Contains(eventArgs.Using.Uid) ||
|
||||
!eventArgs.Using.TryGetComponent(out MopComponent? mopComponent) ||
|
||||
mopComponent.Mopping)
|
||||
@@ -101,15 +99,15 @@ namespace Content.Server.Fluids.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
var mopContents = mopComponent.Contents;
|
||||
var mopContents = mopComponent.MopSolution;
|
||||
|
||||
if (mopContents == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var solution = contents.SplitSolution(transferAmount);
|
||||
if (!mopContents.TryAddSolution(solution))
|
||||
var solution = solutionsSys.SplitSolution(Owner.Uid, contents, transferAmount);
|
||||
if (!solutionsSys.TryAddSolution(mopComponent.Owner.Uid, mopContents, solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -23,28 +23,36 @@ namespace Content.Server.Fluids.Components
|
||||
public class MopComponent : Component, IAfterInteract
|
||||
{
|
||||
public override string Name => "Mop";
|
||||
public const string SolutionName = "mop";
|
||||
|
||||
/// <summary>
|
||||
/// Used to prevent do_after spam if we're currently mopping.
|
||||
/// </summary>
|
||||
public bool Mopping { get; private set; }
|
||||
|
||||
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
|
||||
public Solution? MopSolution
|
||||
{
|
||||
get
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution);
|
||||
return solution;
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
|
||||
get => MopSolution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
var solution = MopSolution;
|
||||
if (solution != null)
|
||||
{
|
||||
solution.MaxVolume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume =>
|
||||
Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
public ReagentUnit CurrentVolume => MopSolution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
// Currently there's a separate amount for pickup and dropoff so
|
||||
// Picking up a puddle requires multiple clicks
|
||||
@@ -60,15 +68,7 @@ namespace Content.Server.Fluids.Components
|
||||
/// Multiplier for the do_after delay for how fast the mop works.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("speed")]
|
||||
private float _mopSpeed = 1;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
|
||||
}
|
||||
[DataField("speed")] private float _mopSpeed = 1;
|
||||
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace Content.Server.Fluids.Components
|
||||
* will spill some of the mop's solution onto the puddle which will evaporate eventually.
|
||||
*/
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents) ||
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var contents ) ||
|
||||
Mopping ||
|
||||
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
||||
{
|
||||
@@ -94,7 +94,8 @@ namespace Content.Server.Fluids.Components
|
||||
if (currentVolume > 0)
|
||||
{
|
||||
// Drop the liquid on the mop on to the ground
|
||||
contents.SplitSolution(CurrentVolume).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, CurrentVolume)
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,7 +118,8 @@ namespace Content.Server.Fluids.Components
|
||||
Mopping = true;
|
||||
|
||||
// So if the puddle has 20 units we mop in 2 seconds. Don't just store CurrentVolume given it can change so need to re-calc it anyway.
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleVolume.Float() / 10.0f, target: eventArgs.Target)
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleVolume.Float() / 10.0f,
|
||||
target: eventArgs.Target)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
@@ -138,7 +140,9 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
if (transferAmount == 0)
|
||||
{
|
||||
if (puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
if (
|
||||
puddleComponent
|
||||
.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
||||
@@ -154,13 +158,15 @@ namespace Content.Server.Fluids.Components
|
||||
puddleComponent.SplitSolution(transferAmount);
|
||||
}
|
||||
|
||||
if (puddleCleaned) //After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
||||
if (
|
||||
puddleCleaned) //After cleaning the puddle, make a new puddle with solution from the mop as a "wet floor". Then evaporate it slowly.
|
||||
{
|
||||
contents.SplitSolution(transferAmount).SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, transferAmount)
|
||||
.SpillAt(eventArgs.ClickLocation, "PuddleSmear");
|
||||
}
|
||||
else
|
||||
{
|
||||
contents.SplitSolution(transferAmount);
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, transferAmount);
|
||||
}
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _pickupSound.GetSound(), Owner);
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Content.Shared.Directions;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Maps;
|
||||
@@ -50,15 +50,22 @@ namespace Content.Server.Fluids.Components
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
public override string Name => "Puddle";
|
||||
|
||||
public const string DefaultSolutionName = "puddle";
|
||||
|
||||
private CancellationTokenSource? _evaporationToken;
|
||||
[DataField("evaporate_threshold")]
|
||||
private ReagentUnit _evaporateThreshold = ReagentUnit.New(20); // How few <Solution Quantity> we can hold prior to self-destructing
|
||||
|
||||
[DataField("evaporate_threshold")] private ReagentUnit
|
||||
_evaporateThreshold =
|
||||
ReagentUnit.New(20); // How few <Solution Quantity> we can hold prior to self-destructing
|
||||
|
||||
public ReagentUnit EvaporateThreshold
|
||||
{
|
||||
get => _evaporateThreshold;
|
||||
set => _evaporateThreshold = value;
|
||||
}
|
||||
|
||||
private ReagentUnit _slipThreshold = ReagentUnit.New(3);
|
||||
|
||||
public ReagentUnit SlipThreshold
|
||||
{
|
||||
get => _slipThreshold;
|
||||
@@ -83,40 +90,44 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => _contents.MaxVolume;
|
||||
set => _contents.MaxVolume = value;
|
||||
get => PuddleSolution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (PuddleSolution != null)
|
||||
{
|
||||
PuddleSolution.MaxVolume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public ReagentUnit CurrentVolume => _contents.CurrentVolume;
|
||||
[ViewVariables] public ReagentUnit CurrentVolume => PuddleSolution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
// Volume at which the fluid will try to spill to adjacent components
|
||||
// Currently a random number, potentially change
|
||||
public ReagentUnit OverflowVolume => _overflowVolume;
|
||||
[ViewVariables]
|
||||
[DataField("overflow_volume")]
|
||||
|
||||
[ViewVariables] [DataField("overflow_volume")]
|
||||
private ReagentUnit _overflowVolume = ReagentUnit.New(20);
|
||||
|
||||
private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
|
||||
private SolutionContainerComponent _contents = default!;
|
||||
public bool EmptyHolder => _contents.ReagentList.Count == 0;
|
||||
[DataField("variants")]
|
||||
private int _spriteVariants = 1;
|
||||
// Whether the underlying solution color should be used
|
||||
[DataField("recolor")]
|
||||
private bool _recolor = default;
|
||||
public bool EmptyHolder => PuddleSolution?.Contents.Count == 0;
|
||||
|
||||
[DataField("state")]
|
||||
private string _spriteState = "puddle";
|
||||
[DataField("variants")] private int _spriteVariants = 1;
|
||||
|
||||
// Whether the underlying solution color should be used
|
||||
[DataField("recolor")] private bool _recolor = default;
|
||||
|
||||
[DataField("state")] private string _spriteState = "puddle";
|
||||
|
||||
private bool Slippery => Owner.TryGetComponent(out SlipperyComponent? slippery) && slippery.Slippery;
|
||||
|
||||
private Solution? PuddleSolution => EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, DefaultSolutionName);
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_contents = Owner.EnsureComponentWarn<SolutionContainerComponent>();
|
||||
|
||||
// Smaller than 1m^3 for now but realistically this shouldn't be hit
|
||||
MaxVolume = ReagentUnit.New(1000);
|
||||
|
||||
@@ -143,7 +154,7 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if(Slippery)
|
||||
if (Slippery)
|
||||
{
|
||||
message.AddText(Loc.GetString("puddle-component-examine-is-slipper-text"));
|
||||
}
|
||||
@@ -160,13 +171,15 @@ namespace Content.Server.Fluids.Components
|
||||
}
|
||||
|
||||
// Flow rate should probably be controlled globally so this is it for now
|
||||
internal bool TryAddSolution(Solution solution, bool sound = true, bool checkForEvaporate = true, bool checkForOverflow = true)
|
||||
internal bool TryAddSolution(Solution solution, bool sound = true, bool checkForEvaporate = true,
|
||||
bool checkForOverflow = true)
|
||||
{
|
||||
if (solution.TotalVolume == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var result = _contents.TryAddSolution(solution);
|
||||
|
||||
var result = EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(Owner.Uid, PuddleSolution, solution);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
@@ -194,12 +207,15 @@ namespace Content.Server.Fluids.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
internal Solution SplitSolution(ReagentUnit quantity)
|
||||
internal void SplitSolution(ReagentUnit quantity)
|
||||
{
|
||||
var split = _contents.SplitSolution(quantity);
|
||||
CheckEvaporate();
|
||||
UpdateAppearance();
|
||||
return split;
|
||||
if (PuddleSolution != null)
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, PuddleSolution, quantity);
|
||||
CheckEvaporate();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CheckEvaporate()
|
||||
@@ -212,7 +228,12 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
public void Evaporate()
|
||||
{
|
||||
_contents.SplitSolution(ReagentUnit.Min(ReagentUnit.New(1), _contents.CurrentVolume));
|
||||
if (PuddleSolution != null)
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, PuddleSolution,
|
||||
ReagentUnit.Min(ReagentUnit.New(1), PuddleSolution.CurrentVolume));
|
||||
}
|
||||
|
||||
if (CurrentVolume == 0)
|
||||
{
|
||||
Owner.Delete();
|
||||
@@ -226,7 +247,7 @@ namespace Content.Server.Fluids.Components
|
||||
public void UpdateStatus()
|
||||
{
|
||||
_evaporationToken?.Cancel();
|
||||
if(Owner.Deleted) return;
|
||||
if (Owner.Deleted) return;
|
||||
|
||||
UpdateAppearance();
|
||||
UpdateSlip();
|
||||
@@ -262,15 +283,16 @@ namespace Content.Server.Fluids.Components
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Opacity based on level of fullness to overflow
|
||||
// Hard-cap lower bound for visibility reasons
|
||||
var volumeScale = (CurrentVolume.Float() / OverflowVolume.Float()) * 0.75f + 0.25f;
|
||||
var cappedScale = Math.Min(1.0f, volumeScale);
|
||||
// Color based on the underlying solutioncomponent
|
||||
Color newColor;
|
||||
if (_recolor)
|
||||
if (_recolor && PuddleSolution != null)
|
||||
{
|
||||
newColor = _contents.Color.WithAlpha(cappedScale);
|
||||
newColor = PuddleSolution.Color.WithAlpha(cappedScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -287,12 +309,10 @@ namespace Content.Server.Fluids.Components
|
||||
/// </summary>
|
||||
private void CheckOverflow()
|
||||
{
|
||||
if (CurrentVolume <= _overflowVolume || _overflown)
|
||||
{
|
||||
if (PuddleSolution == null || CurrentVolume <= _overflowVolume || _overflown)
|
||||
return;
|
||||
}
|
||||
|
||||
var nextPuddles = new List<PuddleComponent>() {this};
|
||||
var nextPuddles = new List<PuddleComponent>() { this };
|
||||
var overflownPuddles = new List<PuddleComponent>();
|
||||
|
||||
while (OverflowLeft > ReagentUnit.Zero && nextPuddles.Count > 0)
|
||||
@@ -321,7 +341,7 @@ namespace Content.Server.Fluids.Components
|
||||
{
|
||||
var adjacentPuddle = adjacent();
|
||||
var quantity = ReagentUnit.Min(overflowSplit, adjacentPuddle.OverflowVolume);
|
||||
var spillAmount = _contents.SplitSolution(quantity);
|
||||
var spillAmount = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, PuddleSolution, quantity);
|
||||
|
||||
adjacentPuddle.TryAddSolution(spillAmount, false, false, false);
|
||||
nextPuddles.Add(adjacentPuddle);
|
||||
@@ -390,7 +410,9 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
if (puddle == default)
|
||||
{
|
||||
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, mapGrid.DirectionToGrid(coords, direction)).GetComponent<PuddleComponent>();
|
||||
puddle = () =>
|
||||
Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, mapGrid.DirectionToGrid(coords, direction))
|
||||
.GetComponent<PuddleComponent>();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Coordinates.Helpers;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Content.Shared.Chemistry.Solution.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -23,7 +23,8 @@ namespace Content.Server.Fluids.Components
|
||||
/// <param name="prototype">The prototype to use.</param>
|
||||
/// <param name="sound">Play the spill sound.</param>
|
||||
/// <returns>The puddle if one was created, null otherwise.</returns>
|
||||
public static PuddleComponent? SpillAt(this Solution solution, IEntity entity, string prototype, bool sound = true)
|
||||
public static PuddleComponent? SpillAt(this Solution solution, IEntity entity, string prototype,
|
||||
bool sound = true)
|
||||
{
|
||||
return solution.SpillAt(entity.Transform.Coordinates, prototype, sound);
|
||||
}
|
||||
@@ -39,7 +40,8 @@ namespace Content.Server.Fluids.Components
|
||||
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
||||
/// <param name="sound">Play the spill sound.</param>
|
||||
/// <returns>True if a puddle was created, false otherwise.</returns>
|
||||
public static bool TrySpillAt(this Solution solution, IEntity entity, string prototype, [NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
||||
public static bool TrySpillAt(this Solution solution, IEntity entity, string prototype,
|
||||
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
||||
{
|
||||
puddle = solution.SpillAt(entity, prototype, sound);
|
||||
return puddle != null;
|
||||
@@ -53,14 +55,16 @@ namespace Content.Server.Fluids.Components
|
||||
/// <param name="prototype">The prototype to use.</param>
|
||||
/// <param name="sound">Whether or not to play the spill sound.</param>
|
||||
/// <returns>The puddle if one was created, null otherwise.</returns>
|
||||
public static PuddleComponent? SpillAt(this Solution solution, EntityCoordinates coordinates, string prototype, bool overflow = true, bool sound = true)
|
||||
public static PuddleComponent? SpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
||||
bool overflow = true, bool sound = true)
|
||||
{
|
||||
if (solution.TotalVolume == 0) return null;
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var mapGrid)) return null; // Let's not spill to space.
|
||||
if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var mapGrid))
|
||||
return null; // Let's not spill to space.
|
||||
|
||||
return SpillAt(mapGrid.GetTileRef(coordinates), solution, prototype, overflow, sound);
|
||||
}
|
||||
@@ -74,13 +78,15 @@ namespace Content.Server.Fluids.Components
|
||||
/// <param name="puddle">The puddle if one was created, null otherwise.</param>
|
||||
/// <param name="sound">Play the spill sound.</param>
|
||||
/// <returns>True if a puddle was created, false otherwise.</returns>
|
||||
public static bool TrySpillAt(this Solution solution, EntityCoordinates coordinates, string prototype, [NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
||||
public static bool TrySpillAt(this Solution solution, EntityCoordinates coordinates, string prototype,
|
||||
[NotNullWhen(true)] out PuddleComponent? puddle, bool sound = true)
|
||||
{
|
||||
puddle = solution.SpillAt(coordinates, prototype, sound);
|
||||
return puddle != null;
|
||||
}
|
||||
|
||||
public static bool TryGetPuddle(this TileRef tileRef, GridTileLookupSystem? gridTileLookupSystem, [NotNullWhen(true)] out PuddleComponent? puddle)
|
||||
public static bool TryGetPuddle(this TileRef tileRef, GridTileLookupSystem? gridTileLookupSystem,
|
||||
[NotNullWhen(true)] out PuddleComponent? puddle)
|
||||
{
|
||||
foreach (var entity in tileRef.GetEntitiesInTileFast(gridTileLookupSystem))
|
||||
{
|
||||
@@ -95,7 +101,8 @@ namespace Content.Server.Fluids.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PuddleComponent? SpillAt(this TileRef tileRef, Solution solution, string prototype, bool overflow = true, bool sound = true)
|
||||
public static PuddleComponent? SpillAt(this TileRef tileRef, Solution solution, string prototype,
|
||||
bool overflow = true, bool sound = true)
|
||||
{
|
||||
if (solution.TotalVolume <= 0) return null;
|
||||
|
||||
@@ -116,15 +123,18 @@ namespace Content.Server.Fluids.Components
|
||||
PuddleComponent? puddle = null;
|
||||
var spilt = false;
|
||||
|
||||
var spillEntities = IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
|
||||
var spillEntities = IoCManager.Resolve<IEntityLookup>()
|
||||
.GetEntitiesIntersecting(mapGrid.ParentMapId, spillGridCoords.Position).ToArray();
|
||||
foreach (var spillEntity in spillEntities)
|
||||
{
|
||||
if (spillEntity.TryGetComponent(out ISolutionInteractionsComponent? solutionContainerComponent) &&
|
||||
solutionContainerComponent.CanRefill)
|
||||
if (EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetRefillableSolution(spillEntity.Uid, out var solutionContainerComponent))
|
||||
{
|
||||
solutionContainerComponent.Refill(
|
||||
solution.SplitSolution(ReagentUnit.Min(solutionContainerComponent.RefillSpaceAvailable, solutionContainerComponent.MaxSpillRefill))
|
||||
);
|
||||
EntitySystem.Get<SolutionContainerSystem>().Refill(spillEntity.Uid, solutionContainerComponent,
|
||||
solution.SplitSolution(ReagentUnit.Min(
|
||||
solutionContainerComponent.AvailableVolume,
|
||||
solutionContainerComponent.MaxSpillRefill))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Chemistry.Solution.Components;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -15,6 +14,7 @@ namespace Content.Server.Fluids.Components
|
||||
public class SpillableComponent : Component, IDropped
|
||||
{
|
||||
public override string Name => "Spillable";
|
||||
public const string SolutionName = "puddle";
|
||||
|
||||
/// <summary>
|
||||
/// Transfers solution from the held container to the floor.
|
||||
@@ -25,8 +25,8 @@ namespace Content.Server.Fluids.Components
|
||||
protected override void GetData(IEntity user, SpillableComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) ||
|
||||
!component.Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent) ||
|
||||
!solutionComponent.CanDrain)
|
||||
!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetDrainableSolution(component.Owner.Uid, out var solutionComponent))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
@@ -40,30 +40,40 @@ namespace Content.Server.Fluids.Components
|
||||
|
||||
protected override void Activate(IEntity user, SpillableComponent component)
|
||||
{
|
||||
if (component.Owner.TryGetComponent<ISolutionInteractionsComponent>(out var solutionComponent))
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
if (component.Owner.HasComponent<SolutionContainerManagerComponent>())
|
||||
{
|
||||
if (!solutionComponent.CanDrain)
|
||||
if (solutionsSys.TryGetDrainableSolution(component.Owner.Uid, out var solutionComponent))
|
||||
{
|
||||
if (solutionComponent.DrainAvailable <= 0)
|
||||
{
|
||||
user.PopupMessage(user,
|
||||
Loc.GetString("spill-target-verb-activate-is-empty-message", ("owner", component.Owner)));
|
||||
}
|
||||
|
||||
// Need this as when we split the component's owner may be deleted
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.Drain(component.Owner.Uid, solutionComponent, solutionComponent.DrainAvailable)
|
||||
.SpillAt(component.Owner.Transform.Coordinates, "PuddleSmear");
|
||||
}
|
||||
else
|
||||
{
|
||||
user.PopupMessage(user,
|
||||
Loc.GetString("spill-target-verb-activate-cannot-drain-message",("owner", component.Owner)));
|
||||
Loc.GetString("spill-target-verb-activate-cannot-drain-message",
|
||||
("owner", component.Owner)));
|
||||
}
|
||||
|
||||
if (solutionComponent.DrainAvailable <= 0)
|
||||
{
|
||||
user.PopupMessage(user, Loc.GetString("spill-target-verb-activate-is-empty-message",("owner", component.Owner)));
|
||||
}
|
||||
|
||||
// Need this as when we split the component's owner may be deleted
|
||||
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(component.Owner.Transform.Coordinates, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Intentional && Owner.TryGetComponent(out ISolutionInteractionsComponent? solutionComponent))
|
||||
if (!eventArgs.Intentional
|
||||
&& EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solutionComponent))
|
||||
{
|
||||
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.Drain(Owner.Uid, solutionComponent, solutionComponent.DrainAvailable)
|
||||
.SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Cooldown;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification.Managers;
|
||||
@@ -30,6 +30,7 @@ namespace Content.Server.Fluids.Components
|
||||
internal sealed class SprayComponent : SharedSprayComponent, IAfterInteract, IUse, IActivate, IDropped
|
||||
{
|
||||
public const float SprayDistance = 3f;
|
||||
public const string SolutionName = "spray";
|
||||
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
@@ -82,14 +83,19 @@ namespace Content.Server.Fluids.Components
|
||||
[DataField("safetySound")]
|
||||
public SoundSpecifier SafetySound { get; } = new SoundPathSpecifier("/Audio/Machines/button.ogg");
|
||||
|
||||
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
public ReagentUnit CurrentVolume {
|
||||
get
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution);
|
||||
return solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
|
||||
|
||||
if (_hasSafety)
|
||||
{
|
||||
SetSafety(Owner, _safety);
|
||||
@@ -124,7 +130,7 @@ namespace Content.Server.Fluids.Components
|
||||
if (eventArgs.ClickLocation.GetGridId(entManager) != playerPos.GetGridId(entManager))
|
||||
return true;
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var contents))
|
||||
return true;
|
||||
|
||||
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;
|
||||
@@ -148,7 +154,7 @@ namespace Content.Server.Fluids.Components
|
||||
if (target.TryDistance(Owner.EntityManager, playerPos, out var distance) && distance > SprayDistance)
|
||||
target = eventArgs.User.Transform.Coordinates.Offset(diffNorm * SprayDistance);
|
||||
|
||||
var solution = contents.SplitSolution(_transferAmount);
|
||||
var solution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(Owner.Uid, contents, _transferAmount);
|
||||
|
||||
if (solution.TotalVolume <= ReagentUnit.Zero)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user