* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
70 lines
3.2 KiB
C#
70 lines
3.2 KiB
C#
using Content.Server.Chemistry.Components;
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
|
using Content.Server.Explosion.EntitySystems;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
using Content.Shared.Interaction;
|
|
|
|
namespace Content.Server.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 class SolutionSpikableSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
|
[Dependency] private readonly TriggerSystem _triggerSystem = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<RefillableSolutionComponent, InteractUsingEvent>(OnInteractUsing);
|
|
}
|
|
|
|
private void OnInteractUsing(Entity<RefillableSolutionComponent> entity, ref InteractUsingEvent args)
|
|
{
|
|
TrySpike(args.Used, args.Target, args.User, entity.Comp);
|
|
}
|
|
|
|
/// <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 void TrySpike(EntityUid source, EntityUid target, EntityUid user, RefillableSolutionComponent? spikableTarget = null,
|
|
SolutionSpikerComponent? spikableSource = null,
|
|
SolutionContainerManagerComponent? managerSource = null,
|
|
SolutionContainerManagerComponent? managerTarget = null)
|
|
{
|
|
if (!Resolve(source, ref spikableSource, ref managerSource, false)
|
|
|| !Resolve(target, ref spikableTarget, ref managerTarget, false)
|
|
|| !_solutionContainerSystem.TryGetRefillableSolution((target, spikableTarget, managerTarget), out var targetSoln, out var targetSolution)
|
|
|| !_solutionContainerSystem.TryGetSolution((source, managerSource), spikableSource.SourceSolution, out _, out var sourceSolution))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (targetSolution.Volume == 0 && !spikableSource.IgnoreEmpty)
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString(spikableSource.PopupEmpty, ("spiked-entity", target), ("spike-entity", source)), user, user);
|
|
return;
|
|
}
|
|
|
|
if (!_solutionContainerSystem.ForceAddSolution(targetSoln.Value, sourceSolution))
|
|
return;
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString(spikableSource.Popup, ("spiked-entity", target), ("spike-entity", source)), user, user);
|
|
sourceSolution.RemoveAllSolution();
|
|
_triggerSystem.Trigger(source, user);
|
|
}
|
|
}
|