mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Reaction;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Chemistry.EntitySystems;
|
|
|
|
public sealed partial class ReactiveContainerSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedContainerSystem _containerSystem = default!;
|
|
[Dependency] private ReactiveSystem _reactiveSystem = default!;
|
|
[Dependency] private SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ReactiveContainerComponent, EntInsertedIntoContainerMessage>(OnInserted);
|
|
SubscribeLocalEvent<ReactiveContainerComponent, SolutionChangedEvent>(OnSolutionChange);
|
|
}
|
|
|
|
private void OnInserted(EntityUid uid, ReactiveContainerComponent comp, EntInsertedIntoContainerMessage args)
|
|
{
|
|
// Only reactive entities can react with the solution
|
|
if (!HasComp<ReactiveComponent>(args.Entity))
|
|
return;
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(uid, comp.Solution, out _, out var solution))
|
|
return;
|
|
if (solution.Volume == 0)
|
|
return;
|
|
|
|
_reactiveSystem.DoEntityReaction(args.Entity, solution, ReactionMethod.Touch);
|
|
}
|
|
|
|
private void OnSolutionChange(EntityUid uid, ReactiveContainerComponent comp, SolutionChangedEvent args)
|
|
{
|
|
// The changes are already networked as part of the same game state.
|
|
if (_timing.ApplyingState)
|
|
return;
|
|
|
|
if (!_solutionContainerSystem.TryGetSolution(uid, comp.Solution, out _, out var solution))
|
|
return;
|
|
|
|
if (solution.Volume == 0)
|
|
return;
|
|
|
|
if (!_containerSystem.TryGetContainer(uid, comp.Container, out var container))
|
|
return;
|
|
|
|
foreach (var entity in container.ContainedEntities)
|
|
{
|
|
if (!HasComp<ReactiveComponent>(entity))
|
|
continue;
|
|
_reactiveSystem.DoEntityReaction(entity, solution, ReactionMethod.Touch);
|
|
}
|
|
}
|
|
}
|