Revert 'Revert 'Solution Entities'' (#23168)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Server.Spreader;
|
||||
@@ -22,19 +23,13 @@ using Content.Shared.Popups;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.StepTrigger.Components;
|
||||
using Content.Shared.StepTrigger.Systems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Effects;
|
||||
using Robust.Server.Audio;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
@@ -91,7 +86,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
// Shouldn't need re-anchoring.
|
||||
SubscribeLocalEvent<PuddleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
|
||||
SubscribeLocalEvent<PuddleComponent, SolutionChangedEvent>(OnSolutionUpdate);
|
||||
SubscribeLocalEvent<PuddleComponent, SolutionContainerChangedEvent>(OnSolutionUpdate);
|
||||
SubscribeLocalEvent<PuddleComponent, ComponentInit>(OnPuddleInit);
|
||||
SubscribeLocalEvent<PuddleComponent, SpreadNeighborsEvent>(OnPuddleSpread);
|
||||
SubscribeLocalEvent<PuddleComponent, SlipEvent>(OnPuddleSlip);
|
||||
@@ -102,13 +97,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
InitializeTransfers();
|
||||
}
|
||||
|
||||
private void OnPuddleSpread(EntityUid uid, PuddleComponent component, ref SpreadNeighborsEvent args)
|
||||
private void OnPuddleSpread(Entity<PuddleComponent> entity, ref SpreadNeighborsEvent args)
|
||||
{
|
||||
var overflow = GetOverflowSolution(uid, component);
|
||||
var overflow = GetOverflowSolution(entity.Owner, entity.Comp);
|
||||
|
||||
if (overflow.Volume == FixedPoint2.Zero)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,7 +120,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
foreach (var neighbor in args.Neighbors)
|
||||
{
|
||||
if (!puddleQuery.TryGetComponent(neighbor, out var puddle) ||
|
||||
!_solutionContainerSystem.TryGetSolution(neighbor, puddle.SolutionName, out var neighborSolution) ||
|
||||
!_solutionContainerSystem.ResolveSolution(neighbor, puddle.SolutionName, ref puddle.Solution, out var neighborSolution) ||
|
||||
CanFullyEvaporate(neighborSolution))
|
||||
{
|
||||
continue;
|
||||
@@ -138,7 +133,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
var split = overflow.SplitSolution(remaining);
|
||||
|
||||
if (!_solutionContainerSystem.TryAddSolution(neighbor, neighborSolution, split))
|
||||
if (!_solutionContainerSystem.TryAddSolution(puddle.Solution.Value, split))
|
||||
continue;
|
||||
|
||||
args.Updates--;
|
||||
@@ -150,7 +145,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
if (overflow.Volume == FixedPoint2.Zero)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -173,7 +168,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
break;
|
||||
}
|
||||
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -186,7 +181,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
{
|
||||
// Overflow to neighbours (unless it's pure water)
|
||||
if (!puddleQuery.TryGetComponent(neighbor, out var puddle) ||
|
||||
!_solutionContainerSystem.TryGetSolution(neighbor, puddle.SolutionName, out var neighborSolution) ||
|
||||
!_solutionContainerSystem.ResolveSolution(neighbor, puddle.SolutionName, ref puddle.Solution, out var neighborSolution) ||
|
||||
CanFullyEvaporate(neighborSolution))
|
||||
{
|
||||
continue;
|
||||
@@ -194,7 +189,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
var split = overflow.SplitSolution(spillPerNeighbor);
|
||||
|
||||
if (!_solutionContainerSystem.TryAddSolution(neighbor, neighborSolution, split))
|
||||
if (!_solutionContainerSystem.TryAddSolution(puddle.Solution.Value, split))
|
||||
continue;
|
||||
|
||||
EnsureComp<ActiveEdgeSpreaderComponent>(neighbor);
|
||||
@@ -206,13 +201,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
}
|
||||
|
||||
// Add the remainder back
|
||||
if (_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var puddleSolution))
|
||||
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.SolutionName, ref entity.Comp.Solution))
|
||||
{
|
||||
_solutionContainerSystem.TryAddSolution(uid, puddleSolution, overflow);
|
||||
_solutionContainerSystem.TryAddSolution(entity.Comp.Solution.Value, overflow);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPuddleSlip(EntityUid uid, PuddleComponent component, ref SlipEvent args)
|
||||
private void OnPuddleSlip(Entity<PuddleComponent> entity, ref SlipEvent args)
|
||||
{
|
||||
// Reactive entities have a chance to get a touch reaction from slipping on a puddle
|
||||
// (i.e. it is implied they fell face first onto it or something)
|
||||
@@ -224,14 +219,14 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
if (!_random.Prob(0.5f))
|
||||
return;
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution))
|
||||
if (!_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.SolutionName, ref entity.Comp.Solution, out var solution))
|
||||
return;
|
||||
|
||||
_popups.PopupEntity(Loc.GetString("puddle-component-slipped-touch-reaction", ("puddle", uid)),
|
||||
_popups.PopupEntity(Loc.GetString("puddle-component-slipped-touch-reaction", ("puddle", entity.Owner)),
|
||||
args.Slipped, args.Slipped, PopupType.SmallCaution);
|
||||
|
||||
// Take 15% of the puddle solution
|
||||
var splitSol = _solutionContainerSystem.SplitSolution(uid, solution, solution.Volume * 0.15f);
|
||||
var splitSol = _solutionContainerSystem.SplitSolution(entity.Comp.Solution.Value, solution.Volume * 0.15f);
|
||||
_reactive.DoEntityReaction(args.Slipped, splitSol, ReactionMethod.Touch);
|
||||
}
|
||||
|
||||
@@ -248,27 +243,27 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
TickEvaporation();
|
||||
}
|
||||
|
||||
private void OnPuddleInit(EntityUid uid, PuddleComponent component, ComponentInit args)
|
||||
private void OnPuddleInit(Entity<PuddleComponent> entity, ref ComponentInit args)
|
||||
{
|
||||
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName, FixedPoint2.New(PuddleVolume), out _);
|
||||
_solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.SolutionName, FixedPoint2.New(PuddleVolume), out _);
|
||||
}
|
||||
|
||||
private void OnSolutionUpdate(EntityUid uid, PuddleComponent component, SolutionChangedEvent args)
|
||||
private void OnSolutionUpdate(Entity<PuddleComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
if (args.Solution.Name != component.SolutionName)
|
||||
if (args.SolutionId != entity.Comp.SolutionName)
|
||||
return;
|
||||
|
||||
if (args.Solution.Volume <= 0)
|
||||
{
|
||||
_deletionQueue.Add(uid);
|
||||
_deletionQueue.Add(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
_deletionQueue.Remove(uid);
|
||||
UpdateSlip(uid, component, args.Solution);
|
||||
UpdateSlow(uid, args.Solution);
|
||||
UpdateEvaporation(uid, args.Solution);
|
||||
UpdateAppearance(uid, component);
|
||||
_deletionQueue.Remove(entity);
|
||||
UpdateSlip(entity, entity.Comp, args.Solution);
|
||||
UpdateSlow(entity, args.Solution);
|
||||
UpdateEvaporation(entity, args.Solution);
|
||||
UpdateAppearance(entity, entity.Comp);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, PuddleComponent? puddleComponent = null, AppearanceComponent? appearance = null)
|
||||
@@ -281,7 +276,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
var volume = FixedPoint2.Zero;
|
||||
Color color = Color.White;
|
||||
|
||||
if (_solutionContainerSystem.TryGetSolution(uid, puddleComponent.SolutionName, out var solution))
|
||||
if (_solutionContainerSystem.ResolveSolution(uid, puddleComponent.SolutionName, ref puddleComponent.Solution, out var solution))
|
||||
{
|
||||
volume = solution.Volume / puddleComponent.OverflowVolume;
|
||||
|
||||
@@ -364,39 +359,31 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePuddleExamined(EntityUid uid, PuddleComponent component, ExaminedEvent args)
|
||||
private void HandlePuddleExamined(Entity<PuddleComponent> entity, ref ExaminedEvent args)
|
||||
{
|
||||
if (TryComp<StepTriggerComponent>(uid, out var slippery) && slippery.Active)
|
||||
if (TryComp<StepTriggerComponent>(entity, out var slippery) && slippery.Active)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("puddle-component-examine-is-slipper-text"));
|
||||
}
|
||||
|
||||
if (HasComp<EvaporationComponent>(uid))
|
||||
if (HasComp<EvaporationComponent>(entity) &&
|
||||
_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.SolutionName, ref entity.Comp.Solution, out var solution))
|
||||
{
|
||||
if (_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution) &&
|
||||
CanFullyEvaporate(solution))
|
||||
{
|
||||
if (CanFullyEvaporate(solution))
|
||||
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating"));
|
||||
}
|
||||
else if (solution?.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
|
||||
{
|
||||
else if (solution.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
|
||||
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-partial"));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, PuddleComponent puddle, ref AnchorStateChangedEvent args)
|
||||
private void OnAnchorChanged(Entity<PuddleComponent> entity, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored)
|
||||
QueueDel(uid);
|
||||
QueueDel(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -407,8 +394,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
if (!Resolve(uid, ref puddleComponent))
|
||||
return FixedPoint2.Zero;
|
||||
|
||||
return _solutionContainerSystem.TryGetSolution(uid, puddleComponent.SolutionName,
|
||||
out var solution)
|
||||
return _solutionContainerSystem.ResolveSolution(uid, puddleComponent.SolutionName, ref puddleComponent.Solution, out var solution)
|
||||
? solution.Volume
|
||||
: FixedPoint2.Zero;
|
||||
}
|
||||
@@ -432,14 +418,12 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
return false;
|
||||
|
||||
if (addedSolution.Volume == 0 ||
|
||||
!_solutionContainerSystem.TryGetSolution(puddleUid, puddleComponent.SolutionName,
|
||||
out var solution))
|
||||
!_solutionContainerSystem.ResolveSolution(puddleUid, puddleComponent.SolutionName, ref puddleComponent.Solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
solution.AddSolution(addedSolution, _prototypeManager);
|
||||
_solutionContainerSystem.UpdateChemicals(puddleUid, solution, true);
|
||||
_solutionContainerSystem.AddSolution(puddleComponent.Solution.Value, addedSolution);
|
||||
|
||||
if (checkForOverflow && IsOverflowing(puddleUid, puddleComponent))
|
||||
{
|
||||
@@ -482,15 +466,14 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
/// </summary>
|
||||
public Solution GetOverflowSolution(EntityUid uid, PuddleComponent? puddle = null)
|
||||
{
|
||||
if (!Resolve(uid, ref puddle) || !_solutionContainerSystem.TryGetSolution(uid, puddle.SolutionName,
|
||||
out var solution))
|
||||
if (!Resolve(uid, ref puddle) || !_solutionContainerSystem.ResolveSolution(uid, puddle.SolutionName, ref puddle.Solution))
|
||||
{
|
||||
return new Solution(0);
|
||||
}
|
||||
|
||||
// TODO: This is going to fail with struct solutions.
|
||||
var remaining = puddle.OverflowVolume;
|
||||
var split = _solutionContainerSystem.SplitSolution(uid, solution, CurrentVolume(uid, puddle) - remaining);
|
||||
var split = _solutionContainerSystem.SplitSolution(puddle.Solution.Value, CurrentVolume(uid, puddle) - remaining);
|
||||
return split;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user