2022-09-29 15:51:59 +10:00
|
|
|
using Content.Server.Weapons.Ranged.Components;
|
2021-12-01 12:40:00 +11:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2022-06-01 19:59:58 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Events;
|
2024-09-02 06:26:04 -05:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2023-12-29 04:47:43 -08:00
|
|
|
using System.Linq;
|
2021-12-01 12:40:00 +11:00
|
|
|
|
2022-09-29 15:51:59 +10:00
|
|
|
namespace Content.Server.Weapons.Ranged.Systems
|
2021-12-01 12:40:00 +11:00
|
|
|
{
|
|
|
|
|
public sealed class ChemicalAmmoSystem : EntitySystem
|
|
|
|
|
{
|
2024-09-02 06:26:04 -05:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
2021-12-01 12:40:00 +11:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<ChemicalAmmoComponent, AmmoShotEvent>(OnFire);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnFire(Entity<ChemicalAmmoComponent> entity, ref AmmoShotEvent args)
|
2021-12-01 12:40:00 +11:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var ammoSoln, out var ammoSolution))
|
2021-12-01 12:40:00 +11:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var projectiles = args.FiredProjectiles;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
var projectileSolutionContainers = new List<(EntityUid, Entity<SolutionComponent>)>();
|
2021-12-01 12:40:00 +11:00
|
|
|
foreach (var projectile in projectiles)
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (_solutionContainerSystem
|
|
|
|
|
.TryGetSolution(projectile, entity.Comp.SolutionName, out var projectileSoln, out _))
|
2021-12-01 12:40:00 +11:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
projectileSolutionContainers.Add((projectile, projectileSoln.Value));
|
2021-12-01 12:40:00 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!projectileSolutionContainers.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-12 16:41:40 +13:00
|
|
|
var solutionPerProjectile = ammoSolution.Volume * (1 / projectileSolutionContainers.Count);
|
2021-12-01 12:40:00 +11:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
foreach (var (_, projectileSolution) in projectileSolutionContainers)
|
2021-12-01 12:40:00 +11:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
var solutionToTransfer = _solutionContainerSystem.SplitSolution(ammoSoln.Value, solutionPerProjectile);
|
|
|
|
|
_solutionContainerSystem.TryAddSolution(projectileSolution, solutionToTransfer);
|
2021-12-01 12:40:00 +11:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_solutionContainerSystem.RemoveAllSolution(ammoSoln.Value);
|
2021-12-01 12:40:00 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|