Melee refactor (#10897)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-09-29 15:51:59 +10:00
committed by GitHub
parent c583b7b361
commit f51248ecaa
140 changed files with 2440 additions and 1824 deletions

View File

@@ -0,0 +1,49 @@
using System.Linq;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Weapons.Ranged.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Server.Weapons.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);
}
}
}