CatStation/Content.Shared/Chemistry/EntitySystems/SolutionSpikerSystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

67 lines
2.7 KiB
C#

using Content.Shared.Popups;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Interaction;
namespace Content.Shared.Chemistry.EntitySystems;
/// <summary>
/// Entity system used to handle when solution containers are 'spiked'
/// with another entity. Triggers the source entity afterwards.
/// Uses refillable solution as the target solution, as that indicates
/// 'easy' refills.
///
/// Examples of spikable entity interactions include pills being dropped into glasses,
/// eggs being cracked into bowls, and so on.
/// </summary>
public sealed partial class SolutionSpikerSystem : EntitySystem
{
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private SharedSolutionContainerSystem _solution = default!;
public override void Initialize()
{
SubscribeLocalEvent<RefillableSolutionComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInteractUsing(Entity<RefillableSolutionComponent> entity, ref InteractUsingEvent args)
{
if (TrySpike(args.Used, (args.Target, entity.Comp), args.User))
args.Handled = true;
}
/// <summary>
/// Immediately transfer all reagents from this entity, to the other entity.
/// The source entity will then be acted on by TriggerSystem.
/// </summary>
/// <param name="source">Source of the solution.</param>
/// <param name="target">Target to spike with the solution from source.</param>
/// <param name="user">User spiking the target solution.</param>
private bool TrySpike(Entity<SolutionSpikerComponent?> source,
Entity<RefillableSolutionComponent?> target,
EntityUid user)
{
if (!Resolve(source, ref source.Comp, false)
|| !_solution.TryGetRefillableSolution((target, target.Comp), out var targetSoln, out var targetSolution)
|| !_solution.TryGetSolution(source.Owner, source.Comp.SourceSolution, out _, out var sourceSolution))
{
return false;
}
if (targetSolution.Volume == 0 && !source.Comp.IgnoreEmpty)
{
_popup.PopupEntity(Loc.GetString(source.Comp.PopupEmpty, ("spiked-entity", target), ("spike-entity", source)), user, user);
return false;
}
if (!_solution.ForceAddSolution(targetSoln.Value, sourceSolution))
return false;
_popup.PopupEntity(Loc.GetString(source.Comp.Popup, ("spiked-entity", target), ("spike-entity", source)), user, user);
sourceSolution.RemoveAllSolution();
if (source.Comp.Delete)
QueueDel(source);
return true;
}
}