CatStation/Content.Shared/Fluids/EntitySystems/SpillWhenWornSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* 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
2026-05-09 03:29:58 +00:00

55 lines
2 KiB
C#

using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Clothing;
using Content.Shared.Fluids.Components;
namespace Content.Shared.Fluids.EntitySystems;
/// <inheritdoc cref="SpillWhenWornComponent"/>
public sealed partial class SpillWhenWornSystem : EntitySystem
{
[Dependency] private SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private SharedPuddleSystem _puddle = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpillWhenWornComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SpillWhenWornComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<SpillWhenWornComponent, SolutionAccessAttemptEvent>(OnSolutionAccessAttempt);
}
private void OnGotEquipped(Entity<SpillWhenWornComponent> ent, ref ClothingGotEquippedEvent args)
{
if (_solutionContainer.TryGetSolution(ent.Owner, ent.Comp.Solution, out var soln, out var solution)
&& solution.Volume > 0)
{
// Spill all solution on the player
var drainedSolution = _solutionContainer.Drain(ent.Owner, soln.Value, solution.Volume);
_puddle.TrySplashSpillAt(ent.Owner, Transform(args.Wearer).Coordinates, drainedSolution, out _);
}
// Flag as worn after draining, otherwise we'll block ourself from accessing!
ent.Comp.IsWorn = true;
Dirty(ent);
}
private void OnGotUnequipped(Entity<SpillWhenWornComponent> ent, ref ClothingGotUnequippedEvent args)
{
ent.Comp.IsWorn = false;
Dirty(ent);
}
private void OnSolutionAccessAttempt(Entity<SpillWhenWornComponent> ent, ref SolutionAccessAttemptEvent args)
{
// If we're not being worn right now, we don't care
if (!ent.Comp.IsWorn)
return;
// Make sure it's the right solution
if (ent.Comp.Solution != args.SolutionName)
return;
args.Cancelled = true;
}
}