2021-11-11 16:10:57 -07:00
|
|
|
using Content.Server.Body.Components;
|
2021-11-30 16:47:21 -07:00
|
|
|
using Content.Server.Body.Systems;
|
2021-07-21 01:41:22 +10:00
|
|
|
using Content.Server.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2022-05-12 18:59:03 +08:00
|
|
|
using Content.Shared.Inventory;
|
2021-07-21 01:41:22 +10:00
|
|
|
using JetBrains.Annotations;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Events;
|
2022-05-12 18:59:03 +08:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2021-07-21 01:41:22 +10:00
|
|
|
namespace Content.Server.Chemistry.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
internal sealed class SolutionInjectOnCollideSystem : EntitySystem
|
|
|
|
|
{
|
2022-05-12 18:59:03 +08:00
|
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
2021-09-06 15:49:44 +02:00
|
|
|
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
2021-11-30 16:47:21 -07:00
|
|
|
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
2022-05-12 18:59:03 +08:00
|
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
2021-11-30 16:47:21 -07:00
|
|
|
|
2021-07-21 01:41:22 +10:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
private void HandleInjection(Entity<SolutionInjectOnCollideComponent> ent, ref StartCollideEvent args)
|
2021-07-21 01:41:22 +10:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
var component = ent.Comp;
|
2023-05-09 19:21:26 +12:00
|
|
|
var target = args.OtherEntity;
|
2022-05-12 18:59:03 +08:00
|
|
|
|
2023-05-09 19:21:26 +12:00
|
|
|
if (!args.OtherBody.Hard ||
|
2022-05-12 18:59:03 +08:00
|
|
|
!EntityManager.TryGetComponent<BloodstreamComponent>(target, out var bloodstream) ||
|
2023-10-19 12:34:31 -07:00
|
|
|
!_solutionsSystem.TryGetInjectableSolution(ent, out var solution))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-21 01:41:22 +10:00
|
|
|
|
2023-12-07 16:20:51 -05:00
|
|
|
if (component.BlockSlots != 0x0)
|
2022-05-12 18:59:03 +08:00
|
|
|
{
|
2023-12-07 16:20:51 -05:00
|
|
|
var containerEnumerator = _inventorySystem.GetSlotEnumerator(target, component.BlockSlots);
|
2022-05-12 18:59:03 +08:00
|
|
|
|
2023-12-07 16:20:51 -05:00
|
|
|
// TODO add a helper method for this?
|
|
|
|
|
if (containerEnumerator.MoveNext(out _))
|
2022-05-12 18:59:03 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 01:41:22 +10:00
|
|
|
var solRemoved = solution.SplitSolution(component.TransferAmount);
|
2023-01-12 16:41:40 +13:00
|
|
|
var solRemovedVol = solRemoved.Volume;
|
2023-05-09 19:21:26 +12:00
|
|
|
|
2021-07-21 01:41:22 +10:00
|
|
|
var solToInject = solRemoved.SplitSolution(solRemovedVol * component.TransferEfficiency);
|
|
|
|
|
|
2022-05-12 18:59:03 +08:00
|
|
|
_bloodstreamSystem.TryAddToChemicals(target, solToInject, bloodstream);
|
2021-07-21 01:41:22 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|