Revert 'Revert 'Solution Entities'' (#23168)

This commit is contained in:
TemporalOroboros
2023-12-29 04:47:43 -08:00
committed by GitHub
parent 93e1af2f8d
commit d23c8d5c19
180 changed files with 3541 additions and 2956 deletions

View File

@@ -1,3 +1,4 @@
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Popups;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
@@ -24,7 +25,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
[Dependency] private readonly PuddleSystem _puddleSystem = default!;
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
public override void Initialize()
@@ -33,7 +34,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
SubscribeLocalEvent<AbsorbentComponent, ComponentInit>(OnAbsorbentInit);
SubscribeLocalEvent<AbsorbentComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<AbsorbentComponent, InteractNoHandEvent>(OnInteractNoHand);
SubscribeLocalEvent<AbsorbentComponent, SolutionChangedEvent>(OnAbsorbentSolutionChange);
SubscribeLocalEvent<AbsorbentComponent, SolutionContainerChangedEvent>(OnAbsorbentSolutionChange);
}
private void OnAbsorbentInit(EntityUid uid, AbsorbentComponent component, ComponentInit args)
@@ -42,14 +43,14 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
UpdateAbsorbent(uid, component);
}
private void OnAbsorbentSolutionChange(EntityUid uid, AbsorbentComponent component, SolutionChangedEvent args)
private void OnAbsorbentSolutionChange(EntityUid uid, AbsorbentComponent component, ref SolutionContainerChangedEvent args)
{
UpdateAbsorbent(uid, component);
}
private void UpdateAbsorbent(EntityUid uid, AbsorbentComponent component)
{
if (!_solutionSystem.TryGetSolution(uid, AbsorbentComponent.SolutionName, out var solution))
if (!_solutionContainerSystem.TryGetSolution(uid, AbsorbentComponent.SolutionName, out _, out var solution))
return;
var oldProgress = component.Progress.ShallowClone();
@@ -102,17 +103,17 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
public void Mop(EntityUid user, EntityUid target, EntityUid used, AbsorbentComponent component)
{
if (!_solutionSystem.TryGetSolution(used, AbsorbentComponent.SolutionName, out var absorbentSolution))
if (!_solutionContainerSystem.TryGetSolution(used, AbsorbentComponent.SolutionName, out var absorberSoln))
return;
if (_useDelay.ActiveDelay(used))
return;
// If it's a puddle try to grab from
if (!TryPuddleInteract(user, used, target, component, absorbentSolution))
if (!TryPuddleInteract(user, used, target, component, absorberSoln.Value))
{
// If it's refillable try to transfer
if (!TryRefillableInteract(user, used, target, component, absorbentSolution))
if (!TryRefillableInteract(user, used, target, component, absorberSoln.Value))
return;
}
}
@@ -120,24 +121,24 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
/// <summary>
/// Logic for an absorbing entity interacting with a refillable.
/// </summary>
private bool TryRefillableInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, Solution absorbentSolution)
private bool TryRefillableInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, Entity<SolutionComponent> absorbentSoln)
{
if (!TryComp(target, out RefillableSolutionComponent? refillable))
return false;
if (!_solutionSystem.TryGetRefillableSolution(target, out var refillableSolution, refillable: refillable))
if (!_solutionContainerSystem.TryGetRefillableSolution((target, refillable, null), out var refillableSoln, out var refillableSolution))
return false;
if (refillableSolution.Volume <= 0)
{
// Target empty - only transfer absorbent contents into refillable
if (!TryTransferFromAbsorbentToRefillable(user, used, target, component, absorbentSolution, refillableSolution))
if (!TryTransferFromAbsorbentToRefillable(user, used, target, component, absorbentSoln, refillableSoln.Value))
return false;
}
else
{
// Target non-empty - do a two-way transfer
if (!TryTwoWayAbsorbentRefillableTransfer(user, used, target, component, absorbentSolution, refillableSolution))
if (!TryTwoWayAbsorbentRefillableTransfer(user, used, target, component, absorbentSoln, refillableSoln.Value))
return false;
}
@@ -154,15 +155,17 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
EntityUid used,
EntityUid target,
AbsorbentComponent component,
Solution absorbentSolution,
Solution refillableSolution)
Entity<SolutionComponent> absorbentSoln,
Entity<SolutionComponent> refillableSoln)
{
var absorbentSolution = absorbentSoln.Comp.Solution;
if (absorbentSolution.Volume <= 0)
{
_popups.PopupEntity(Loc.GetString("mopping-system-target-container-empty", ("target", target)), user, user);
return false;
}
var refillableSolution = refillableSoln.Comp.Solution;
var transferAmount = component.PickupAmount < refillableSolution.AvailableVolume ?
component.PickupAmount :
refillableSolution.AvailableVolume;
@@ -174,17 +177,15 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
}
// Prioritize transferring non-evaporatives if absorbent has any
var contaminants = absorbentSolution.SplitSolutionWithout(transferAmount, PuddleSystem.EvaporationReagents);
var contaminants = _solutionContainerSystem.SplitSolutionWithout(absorbentSoln, transferAmount, PuddleSystem.EvaporationReagents);
if (contaminants.Volume > 0)
{
_solutionSystem.UpdateChemicals(used, absorbentSolution, true);
_solutionSystem.TryAddSolution(target, refillableSolution, contaminants);
_solutionContainerSystem.TryAddSolution(refillableSoln, contaminants);
}
else
{
var evaporatives = absorbentSolution.SplitSolution(transferAmount);
_solutionSystem.UpdateChemicals(used, absorbentSolution, true);
_solutionSystem.TryAddSolution(target, refillableSolution, evaporatives);
var evaporatives = _solutionContainerSystem.SplitSolution(absorbentSoln, transferAmount);
_solutionContainerSystem.TryAddSolution(refillableSoln, evaporatives);
}
return true;
@@ -198,12 +199,12 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
EntityUid used,
EntityUid target,
AbsorbentComponent component,
Solution absorbentSolution,
Solution refillableSolution)
Entity<SolutionComponent> absorbentSoln,
Entity<SolutionComponent> refillableSoln)
{
var contaminantsFromAbsorbent = absorbentSolution.SplitSolutionWithout(component.PickupAmount, PuddleSystem.EvaporationReagents);
_solutionSystem.UpdateChemicals(used, absorbentSolution, true);
var contaminantsFromAbsorbent = _solutionContainerSystem.SplitSolutionWithout(absorbentSoln, component.PickupAmount, PuddleSystem.EvaporationReagents);
var absorbentSolution = absorbentSoln.Comp.Solution;
if (contaminantsFromAbsorbent.Volume == FixedPoint2.Zero && absorbentSolution.AvailableVolume == FixedPoint2.Zero)
{
// Nothing to transfer to refillable and no room to absorb anything extra
@@ -217,8 +218,9 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
component.PickupAmount :
absorbentSolution.AvailableVolume;
var refillableSolution = refillableSoln.Comp.Solution;
var waterFromRefillable = refillableSolution.SplitSolutionWithOnly(waterPulled, PuddleSystem.EvaporationReagents);
_solutionSystem.UpdateChemicals(target, refillableSolution);
_solutionContainerSystem.UpdateChemicals(refillableSoln);
if (waterFromRefillable.Volume == FixedPoint2.Zero && contaminantsFromAbsorbent.Volume == FixedPoint2.Zero)
{
@@ -234,7 +236,7 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
if (waterFromRefillable.Volume > FixedPoint2.Zero)
{
// transfer water to absorbent
_solutionSystem.TryAddSolution(used, absorbentSolution, waterFromRefillable);
_solutionContainerSystem.TryAddSolution(absorbentSoln, waterFromRefillable);
anyTransferOccurred = true;
}
@@ -248,12 +250,12 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
{
// transfer as much contaminants to refillable as will fit
var contaminantsForRefillable = contaminantsFromAbsorbent.SplitSolution(refillableSolution.AvailableVolume);
_solutionSystem.TryAddSolution(target, refillableSolution, contaminantsForRefillable);
_solutionContainerSystem.TryAddSolution(refillableSoln, contaminantsForRefillable);
anyTransferOccurred = true;
}
// absorb everything that did not fit in the refillable back by the absorbent
_solutionSystem.TryAddSolution(used, absorbentSolution, contaminantsFromAbsorbent);
_solutionContainerSystem.TryAddSolution(absorbentSoln, contaminantsFromAbsorbent);
}
return anyTransferOccurred;
@@ -262,23 +264,24 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
/// <summary>
/// Logic for an absorbing entity interacting with a puddle.
/// </summary>
private bool TryPuddleInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent absorber, Solution absorberSoln)
private bool TryPuddleInteract(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent absorber, Entity<SolutionComponent> absorberSoln)
{
if (!TryComp(target, out PuddleComponent? puddle))
return false;
if (!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSoln) || puddleSoln.Volume <= 0)
if (!_solutionContainerSystem.ResolveSolution(target, puddle.SolutionName, ref puddle.Solution, out var puddleSolution) || puddleSolution.Volume <= 0)
return false;
// Check if the puddle has any non-evaporative reagents
if (_puddleSystem.CanFullyEvaporate(puddleSoln))
if (_puddleSystem.CanFullyEvaporate(puddleSolution))
{
_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.EvaporationReagents);
var absorberSolution = absorberSoln.Comp.Solution;
var available = absorberSolution.GetTotalPrototypeQuantity(PuddleSystem.EvaporationReagents);
// No material
if (available == FixedPoint2.Zero)
@@ -290,8 +293,8 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
var transferMax = absorber.PickupAmount;
var transferAmount = available > transferMax ? transferMax : available;
var puddleSplit = puddleSoln.SplitSolutionWithout(transferAmount, PuddleSystem.EvaporationReagents);
var absorberSplit = absorberSoln.SplitSolutionWithOnly(puddleSplit.Volume, PuddleSystem.EvaporationReagents);
var puddleSplit = puddleSolution.SplitSolutionWithout(transferAmount, PuddleSystem.EvaporationReagents);
var absorberSplit = absorberSolution.SplitSolutionWithOnly(puddleSplit.Volume, PuddleSystem.EvaporationReagents);
// Do tile reactions first
var coordinates = Transform(target).Coordinates;
@@ -300,11 +303,9 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
_puddleSystem.DoTileReactions(mapGrid.GetTileRef(coordinates), absorberSplit);
}
puddleSoln.AddSolution(absorberSplit, _prototype);
absorberSoln.AddSolution(puddleSplit, _prototype);
_solutionContainerSystem.AddSolution(puddle.Solution.Value, absorberSplit);
_solutionContainerSystem.AddSolution(absorberSoln, puddleSplit);
_solutionSystem.UpdateChemicals(used, absorberSoln);
_solutionSystem.UpdateChemicals(target, puddleSoln);
_audio.PlayPvs(absorber.PickupSound, target);
_useDelay.BeginDelay(used);