Files
tbd-station-14/Content.Server/Weapon/Ranged/Systems/ChemicalAmmoSystem.cs
metalgearsloth fb943a61dc Gun refactor (#8301)
Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: T-Stalker <le0nel_1van@hotmail.com>
Co-authored-by: T-Stalker <43253663+DogZeroX@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
2022-06-01 19:59:58 +10:00

50 lines
1.8 KiB
C#

using System.Linq;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Weapon.Ranged.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Server.Weapon.Ranged.Systems
{
public sealed class ChemicalAmmoSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<ChemicalAmmoComponent, AmmoShotEvent>(OnFire);
}
private void OnFire(EntityUid uid, ChemicalAmmoComponent component, AmmoShotEvent args)
{
if (!_solutionSystem.TryGetSolution(uid, component.SolutionName, out var ammoSolution))
return;
var projectiles = args.FiredProjectiles;
var projectileSolutionContainers = new List<(EntityUid, Solution)>();
foreach (var projectile in projectiles)
{
if (_solutionSystem
.TryGetSolution(projectile, component.SolutionName, out var projectileSolutionContainer))
{
projectileSolutionContainers.Add((uid, projectileSolutionContainer));
}
}
if (!projectileSolutionContainers.Any())
return;
var solutionPerProjectile = ammoSolution.CurrentVolume * (1 / projectileSolutionContainers.Count);
foreach (var (projectileUid, projectileSolution) in projectileSolutionContainers)
{
var solutionToTransfer = _solutionSystem.SplitSolution(uid, ammoSolution, solutionPerProjectile);
_solutionSystem.TryAddSolution(projectileUid, projectileSolution, solutionToTransfer);
}
_solutionSystem.RemoveAllSolution(uid, ammoSolution);
}
}
}