Revert 'Revert 'Solution Entities'' (#23168)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Chemistry.ReactionEffects;
|
||||
using Content.Server.Spreader;
|
||||
using Content.Shared.Chemistry;
|
||||
@@ -21,6 +21,8 @@ using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Linq;
|
||||
|
||||
using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
@@ -42,7 +44,7 @@ public sealed class SmokeSystem : EntitySystem
|
||||
[Dependency] private readonly ReactiveSystem _reactive = default!;
|
||||
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
|
||||
private EntityQuery<SmokeComponent> _smokeQuery;
|
||||
@@ -59,6 +61,7 @@ public sealed class SmokeSystem : EntitySystem
|
||||
SubscribeLocalEvent<SmokeComponent, StartCollideEvent>(OnStartCollide);
|
||||
SubscribeLocalEvent<SmokeComponent, EndCollideEvent>(OnEndCollide);
|
||||
SubscribeLocalEvent<SmokeComponent, ReactionAttemptEvent>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<SmokeComponent, SolutionRelayEvent<ReactionAttemptEvent>>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<SmokeComponent, SpreadNeighborsEvent>(OnSmokeSpread);
|
||||
SubscribeLocalEvent<SmokeAffectedComponent, EntityUnpausedEvent>(OnAffectedUnpaused);
|
||||
}
|
||||
@@ -80,33 +83,33 @@ public sealed class SmokeSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartCollide(EntityUid uid, SmokeComponent component, ref StartCollideEvent args)
|
||||
private void OnStartCollide(Entity<SmokeComponent> entity, ref StartCollideEvent args)
|
||||
{
|
||||
if (_smokeAffectedQuery.HasComponent(args.OtherEntity))
|
||||
return;
|
||||
|
||||
var smokeAffected = AddComp<SmokeAffectedComponent>(args.OtherEntity);
|
||||
smokeAffected.SmokeEntity = uid;
|
||||
smokeAffected.SmokeEntity = entity;
|
||||
smokeAffected.NextSecond = _timing.CurTime + TimeSpan.FromSeconds(1);
|
||||
}
|
||||
|
||||
private void OnEndCollide(EntityUid uid, SmokeComponent component, ref EndCollideEvent args)
|
||||
private void OnEndCollide(Entity<SmokeComponent> entity, ref EndCollideEvent args)
|
||||
{
|
||||
// if we are already in smoke, make sure the thing we are exiting is the current smoke we are in.
|
||||
if (_smokeAffectedQuery.TryGetComponent(args.OtherEntity, out var smokeAffectedComponent))
|
||||
{
|
||||
if (smokeAffectedComponent.SmokeEntity != uid)
|
||||
if (smokeAffectedComponent.SmokeEntity != entity.Owner)
|
||||
return;
|
||||
}
|
||||
|
||||
var exists = Exists(uid);
|
||||
var exists = Exists(entity);
|
||||
|
||||
if (!TryComp<PhysicsComponent>(args.OtherEntity, out var body))
|
||||
return;
|
||||
|
||||
foreach (var ent in _physics.GetContactingEntities(args.OtherEntity, body))
|
||||
{
|
||||
if (exists && ent == uid)
|
||||
if (exists && ent == entity.Owner)
|
||||
continue;
|
||||
|
||||
if (!_smokeQuery.HasComponent(ent))
|
||||
@@ -121,51 +124,51 @@ public sealed class SmokeSystem : EntitySystem
|
||||
RemComp(args.OtherEntity, smokeAffectedComponent);
|
||||
}
|
||||
|
||||
private void OnAffectedUnpaused(EntityUid uid, SmokeAffectedComponent component, ref EntityUnpausedEvent args)
|
||||
private void OnAffectedUnpaused(Entity<SmokeAffectedComponent> entity, ref EntityUnpausedEvent args)
|
||||
{
|
||||
component.NextSecond += args.PausedTime;
|
||||
entity.Comp.NextSecond += args.PausedTime;
|
||||
}
|
||||
|
||||
private void OnSmokeSpread(EntityUid uid, SmokeComponent component, ref SpreadNeighborsEvent args)
|
||||
private void OnSmokeSpread(Entity<SmokeComponent> entity, ref SpreadNeighborsEvent args)
|
||||
{
|
||||
if (component.SpreadAmount == 0 || !_solutionSystem.TryGetSolution(uid, SmokeComponent.SolutionName, out var solution))
|
||||
if (entity.Comp.SpreadAmount == 0 || !_solutionContainerSystem.ResolveSolution(entity.Owner, SmokeComponent.SolutionName, ref entity.Comp.Solution, out var solution))
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Prototype(uid) is not { } prototype)
|
||||
if (Prototype(entity) is not { } prototype)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.NeighborFreeTiles.Any())
|
||||
return;
|
||||
|
||||
TryComp<TimedDespawnComponent>(uid, out var timer);
|
||||
TryComp<TimedDespawnComponent>(entity, out var timer);
|
||||
|
||||
// wtf is the logic behind any of this.
|
||||
var smokePerSpread = component.SpreadAmount / Math.Max(1, args.NeighborFreeTiles.Count);
|
||||
var smokePerSpread = entity.Comp.SpreadAmount / Math.Max(1, args.NeighborFreeTiles.Count);
|
||||
foreach (var neighbor in args.NeighborFreeTiles)
|
||||
{
|
||||
var coords = neighbor.Grid.GridTileToLocal(neighbor.Tile);
|
||||
var ent = Spawn(prototype.ID, coords);
|
||||
var spreadAmount = Math.Max(0, smokePerSpread);
|
||||
component.SpreadAmount -= args.NeighborFreeTiles.Count();
|
||||
entity.Comp.SpreadAmount -= args.NeighborFreeTiles.Count();
|
||||
|
||||
StartSmoke(ent, solution.Clone(), timer?.Lifetime ?? component.Duration, spreadAmount);
|
||||
StartSmoke(ent, solution.Clone(), timer?.Lifetime ?? entity.Comp.Duration, spreadAmount);
|
||||
|
||||
if (component.SpreadAmount == 0)
|
||||
if (entity.Comp.SpreadAmount == 0)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
args.Updates--;
|
||||
|
||||
if (args.NeighborFreeTiles.Count > 0 || args.Neighbors.Count == 0 || component.SpreadAmount < 1)
|
||||
if (args.NeighborFreeTiles.Count > 0 || args.Neighbors.Count == 0 || entity.Comp.SpreadAmount < 1)
|
||||
return;
|
||||
|
||||
// We have no more neighbours to spread to. So instead we will randomly distribute our volume to neighbouring smoke tiles.
|
||||
@@ -179,21 +182,21 @@ public sealed class SmokeSystem : EntitySystem
|
||||
continue;
|
||||
|
||||
smoke.SpreadAmount++;
|
||||
component.SpreadAmount--;
|
||||
entity.Comp.SpreadAmount--;
|
||||
EnsureComp<ActiveEdgeSpreaderComponent>(neighbor);
|
||||
|
||||
if (component.SpreadAmount == 0)
|
||||
if (entity.Comp.SpreadAmount == 0)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(EntityUid uid, SmokeComponent component, ReactionAttemptEvent args)
|
||||
private void OnReactionAttempt(Entity<SmokeComponent> entity, ref ReactionAttemptEvent args)
|
||||
{
|
||||
if (args.Solution.Name != SmokeComponent.SolutionName)
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
// Prevent smoke/foam fork bombs (smoke creating more smoke).
|
||||
@@ -201,12 +204,18 @@ public sealed class SmokeSystem : EntitySystem
|
||||
{
|
||||
if (effect is AreaReactionEffect)
|
||||
{
|
||||
args.Cancel();
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(Entity<SmokeComponent> entity, ref SolutionRelayEvent<ReactionAttemptEvent> args)
|
||||
{
|
||||
if (args.Name == SmokeComponent.SolutionName)
|
||||
OnReactionAttempt(entity, ref args.Event);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a smoke component for spreading.
|
||||
/// </summary>
|
||||
@@ -245,14 +254,14 @@ public sealed class SmokeSystem : EntitySystem
|
||||
if (!Resolve(smokeUid, ref component))
|
||||
return;
|
||||
|
||||
if (!_solutionSystem.TryGetSolution(smokeUid, SmokeComponent.SolutionName, out var solution) ||
|
||||
if (!_solutionContainerSystem.ResolveSolution(smokeUid, SmokeComponent.SolutionName, ref component.Solution, out var solution) ||
|
||||
solution.Contents.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReactWithEntity(entity, smokeUid, solution, component);
|
||||
UpdateVisuals(smokeUid);
|
||||
UpdateVisuals((smokeUid, component));
|
||||
}
|
||||
|
||||
private void ReactWithEntity(EntityUid entity, EntityUid smokeUid, Solution solution, SmokeComponent? component = null)
|
||||
@@ -263,11 +272,14 @@ public sealed class SmokeSystem : EntitySystem
|
||||
if (!TryComp<BloodstreamComponent>(entity, out var bloodstream))
|
||||
return;
|
||||
|
||||
var blockIngestion = _internals.AreInternalsWorking(entity);
|
||||
if (!_solutionContainerSystem.ResolveSolution(entity, bloodstream.ChemicalSolutionName, ref bloodstream.ChemicalSolution, out var chemSolution) || chemSolution.AvailableVolume <= 0)
|
||||
return;
|
||||
|
||||
var blockIngestion = _internals.AreInternalsWorking(entity);
|
||||
|
||||
var cloneSolution = solution.Clone();
|
||||
var availableTransfer = FixedPoint2.Min(cloneSolution.Volume, component.TransferRate);
|
||||
var transferAmount = FixedPoint2.Min(availableTransfer, bloodstream.ChemicalSolution.AvailableVolume);
|
||||
var transferAmount = FixedPoint2.Min(availableTransfer, chemSolution.AvailableVolume);
|
||||
var transferSolution = cloneSolution.SplitSolution(transferAmount);
|
||||
|
||||
foreach (var reagentQuantity in transferSolution.Contents.ToArray())
|
||||
@@ -296,7 +308,7 @@ public sealed class SmokeSystem : EntitySystem
|
||||
if (!Resolve(uid, ref component, ref xform))
|
||||
return;
|
||||
|
||||
if (!_solutionSystem.TryGetSolution(uid, SmokeComponent.SolutionName, out var solution) || !solution.Any())
|
||||
if (!_solutionContainerSystem.ResolveSolution(uid, SmokeComponent.SolutionName, ref component.Solution, out var solution) || !solution.Any())
|
||||
return;
|
||||
|
||||
if (!_mapManager.TryGetGrid(xform.GridUid, out var mapGrid))
|
||||
@@ -317,29 +329,30 @@ public sealed class SmokeSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Adds the specified solution to the relevant smoke solution.
|
||||
/// </summary>
|
||||
private void TryAddSolution(EntityUid uid, Solution solution)
|
||||
private void TryAddSolution(Entity<SmokeComponent?> smoke, Solution solution)
|
||||
{
|
||||
if (solution.Volume == FixedPoint2.Zero)
|
||||
return;
|
||||
|
||||
if (!_solutionSystem.TryGetSolution(uid, SmokeComponent.SolutionName, out var solutionArea))
|
||||
if (!Resolve(smoke, ref smoke.Comp))
|
||||
return;
|
||||
|
||||
var addSolution =
|
||||
solution.SplitSolution(FixedPoint2.Min(solution.Volume, solutionArea.AvailableVolume));
|
||||
if (!_solutionContainerSystem.ResolveSolution(smoke.Owner, SmokeComponent.SolutionName, ref smoke.Comp.Solution, out var solutionArea))
|
||||
return;
|
||||
|
||||
_solutionSystem.TryAddSolution(uid, solutionArea, addSolution);
|
||||
var addSolution = solution.SplitSolution(FixedPoint2.Min(solution.Volume, solutionArea.AvailableVolume));
|
||||
_solutionContainerSystem.TryAddSolution(smoke.Comp.Solution.Value, addSolution);
|
||||
|
||||
UpdateVisuals(uid);
|
||||
UpdateVisuals(smoke);
|
||||
}
|
||||
|
||||
private void UpdateVisuals(EntityUid uid)
|
||||
private void UpdateVisuals(Entity<SmokeComponent?, AppearanceComponent?> smoke)
|
||||
{
|
||||
if (!TryComp(uid, out AppearanceComponent? appearance) ||
|
||||
!_solutionSystem.TryGetSolution(uid, SmokeComponent.SolutionName, out var solution))
|
||||
if (!Resolve(smoke, ref smoke.Comp1, ref smoke.Comp2) ||
|
||||
!_solutionContainerSystem.ResolveSolution(smoke.Owner, SmokeComponent.SolutionName, ref smoke.Comp1.Solution, out var solution))
|
||||
return;
|
||||
|
||||
var color = solution.GetColor(_prototype);
|
||||
_appearance.SetData(uid, SmokeVisuals.Color, color, appearance);
|
||||
_appearance.SetData(smoke.Owner, SmokeVisuals.Color, color, smoke.Comp2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user