Files
crystall-punk-14/Content.Server/Weapons/Ranged/Systems/ChemicalAmmoSystem.cs

50 lines
1.9 KiB
C#
Raw Permalink Normal View History

using Content.Server.Weapons.Ranged.Components;
2021-12-01 12:40:00 +11:00
using Content.Shared.Chemistry.Components;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Chemistry.EntitySystems;
using System.Linq;
2021-12-01 12:40:00 +11:00
namespace Content.Server.Weapons.Ranged.Systems
2021-12-01 12:40:00 +11:00
{
public sealed class ChemicalAmmoSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
2021-12-01 12:40:00 +11:00
public override void Initialize()
{
SubscribeLocalEvent<ChemicalAmmoComponent, AmmoShotEvent>(OnFire);
}
private void OnFire(Entity<ChemicalAmmoComponent> entity, ref AmmoShotEvent args)
2021-12-01 12:40:00 +11: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;
var projectileSolutionContainers = new List<(EntityUid, Entity<SolutionComponent>)>();
2021-12-01 12:40:00 +11:00
foreach (var projectile in projectiles)
{
if (_solutionContainerSystem
.TryGetSolution(projectile, entity.Comp.SolutionName, out var projectileSoln, out _))
2021-12-01 12:40:00 +11: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
foreach (var (_, projectileSolution) in projectileSolutionContainers)
2021-12-01 12:40:00 +11:00
{
var solutionToTransfer = _solutionContainerSystem.SplitSolution(ammoSoln.Value, solutionPerProjectile);
_solutionContainerSystem.TryAddSolution(projectileSolution, solutionToTransfer);
2021-12-01 12:40:00 +11:00
}
_solutionContainerSystem.RemoveAllSolution(ammoSoln.Value);
2021-12-01 12:40:00 +11:00
}
}
}