Files
tbd-station-14/Content.Server/Chemistry/EntitySystems/SolutionInjectOnCollideSystem.cs
nikthechampiongr ef132c8a7b Fix tranquiliser shells not working (#23886)
* Fix tranquiliser darts not working

Fixes a bug introduced by 9f47079d02 which
was made to stop the fly-by fixture from triggering the system. This was
done by checking whether the fixture was hard. Apparently the
projectile's fixture is never hard as well. The change just makes it so
that check only succeeds when the fixture is a fly-by fixture.

* Remove something that I think is redundant

* Remove random using directive that somehow appeared.

* Address Review

* Adress Review 2

* Put the appropriate fixture ids
2024-01-10 18:02:37 -05:00

53 lines
1.9 KiB
C#

using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.Inventory;
using JetBrains.Annotations;
using Robust.Shared.Physics.Events;
namespace Content.Server.Chemistry.EntitySystems;
public sealed class SolutionInjectOnCollideSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainersSystem = default!;
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
}
private void HandleInjection(Entity<SolutionInjectOnCollideComponent> ent, ref StartCollideEvent args)
{
var component = ent.Comp;
var target = args.OtherEntity;
if (!args.OtherBody.Hard ||
args.OurFixtureId != ent.Comp.FixtureId ||
!EntityManager.TryGetComponent<BloodstreamComponent>(target, out var bloodstream) ||
!_solutionContainersSystem.TryGetInjectableSolution(ent.Owner, out var solution, out _))
{
return;
}
if (component.BlockSlots != 0x0)
{
var containerEnumerator = _inventorySystem.GetSlotEnumerator(target, component.BlockSlots);
// TODO add a helper method for this?
if (containerEnumerator.MoveNext(out _))
return;
}
var solRemoved = _solutionContainersSystem.SplitSolution(solution.Value, component.TransferAmount);
var solRemovedVol = solRemoved.Volume;
var solToInject = solRemoved.SplitSolution(solRemovedVol * component.TransferEfficiency);
_bloodstreamSystem.TryAddToChemicals(target, solToInject, bloodstream);
}
}