ChemicalAmmoComponent (#2739)
* ChemicalAmmoComponent * Moves BarrelFiredMessage to FireProjectiles Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -223,7 +223,8 @@
|
|||||||
"Machine",
|
"Machine",
|
||||||
"MachinePart",
|
"MachinePart",
|
||||||
"MachineFrame",
|
"MachineFrame",
|
||||||
"MachineBoard"
|
"MachineBoard",
|
||||||
|
"ChemicalAmmo"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using Content.Server.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public class ChemicalAmmoComponent : Component
|
||||||
|
{
|
||||||
|
public override string Name => "ChemicalAmmo";
|
||||||
|
|
||||||
|
private float _fractionTransfered;
|
||||||
|
|
||||||
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
|
{
|
||||||
|
base.ExposeData(serializer);
|
||||||
|
serializer.DataField(ref _fractionTransfered, "fractionTransfered", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||||
|
{
|
||||||
|
base.HandleMessage(message, component);
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case BarrelFiredMessage barrelFired:
|
||||||
|
TransferSolution(barrelFired);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TransferSolution(BarrelFiredMessage barrelFired)
|
||||||
|
{
|
||||||
|
if (!Owner.TryGetComponent<SolutionContainerComponent>(out var ammoSolutionContainer))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var projectiles = barrelFired.FiredProjectiles;
|
||||||
|
|
||||||
|
var projectileSolutionContainers = new List<SolutionContainerComponent>();
|
||||||
|
foreach (var projectile in projectiles)
|
||||||
|
{
|
||||||
|
if (projectile.TryGetComponent<SolutionContainerComponent>(out var projectileSolutionContainer))
|
||||||
|
{
|
||||||
|
projectileSolutionContainers.Add(projectileSolutionContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!projectileSolutionContainers.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var solutionPerProjectile = ammoSolutionContainer.CurrentVolume * (1 / projectileSolutionContainers.Count);
|
||||||
|
|
||||||
|
foreach (var projectileSolutionContainer in projectileSolutionContainers)
|
||||||
|
{
|
||||||
|
var solutionToTransfer = ammoSolutionContainer.SplitSolution(solutionPerProjectile);
|
||||||
|
projectileSolutionContainer.TryAddSolution(solutionToTransfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ammoSolutionContainer.RemoveAllSolution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -252,7 +252,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
{
|
{
|
||||||
var ammoComponent = ammo.GetComponent<AmmoComponent>();
|
var ammoComponent = ammo.GetComponent<AmmoComponent>();
|
||||||
|
|
||||||
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity);
|
FireProjectiles(shooter, projectile, ammoComponent.ProjectilesFired, ammoComponent.EvenSpreadAngle, angle, ammoComponent.Velocity, ammo);
|
||||||
|
|
||||||
if (CanMuzzleFlash)
|
if (CanMuzzleFlash)
|
||||||
{
|
{
|
||||||
@@ -351,7 +351,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles firing one or many projectiles
|
/// Handles firing one or many projectiles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void FireProjectiles(IEntity shooter, IEntity baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity)
|
private void FireProjectiles(IEntity shooter, IEntity baseProjectile, int count, float evenSpreadAngle, Angle angle, float velocity, IEntity ammo)
|
||||||
{
|
{
|
||||||
List<Angle> sprayAngleChange = null;
|
List<Angle> sprayAngleChange = null;
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
@@ -360,6 +360,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
sprayAngleChange = Linspace(-evenSpreadAngle / 2, evenSpreadAngle / 2, count);
|
sprayAngleChange = Linspace(-evenSpreadAngle / 2, evenSpreadAngle / 2, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firedProjectiles = new List<IEntity>();
|
||||||
for (var i = 0; i < count; i++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
IEntity projectile;
|
IEntity projectile;
|
||||||
@@ -373,6 +374,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
projectile =
|
projectile =
|
||||||
Owner.EntityManager.SpawnEntity(baseProjectile.Prototype.ID, baseProjectile.Transform.Coordinates);
|
Owner.EntityManager.SpawnEntity(baseProjectile.Prototype.ID, baseProjectile.Transform.Coordinates);
|
||||||
}
|
}
|
||||||
|
firedProjectiles.Add(projectile);
|
||||||
|
|
||||||
Angle projectileAngle;
|
Angle projectileAngle;
|
||||||
|
|
||||||
@@ -398,6 +400,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
|
|
||||||
projectile.Transform.LocalRotation = projectileAngle.Theta;
|
projectile.Transform.LocalRotation = projectileAngle.Theta;
|
||||||
}
|
}
|
||||||
|
ammo.SendMessage(this, new BarrelFiredMessage(firedProjectiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -458,4 +461,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
|||||||
message.AddText(fireRateMessage);
|
message.AddText(fireRateMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BarrelFiredMessage : ComponentMessage
|
||||||
|
{
|
||||||
|
public readonly List<IEntity> FiredProjectiles;
|
||||||
|
|
||||||
|
public BarrelFiredMessage(List<IEntity> firedProjectiles)
|
||||||
|
{
|
||||||
|
FiredProjectiles = firedProjectiles;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,3 +99,8 @@
|
|||||||
projectile: PelletShotgunTranquilizer
|
projectile: PelletShotgunTranquilizer
|
||||||
projectilesFired: 1
|
projectilesFired: 1
|
||||||
ammoSpread: 0
|
ammoSpread: 0
|
||||||
|
- type: ChemicalAmmo
|
||||||
|
- type: SolutionContainer
|
||||||
|
maxVol: 15
|
||||||
|
caps: AddTo, RemoveFrom
|
||||||
|
- type: Pourable
|
||||||
@@ -90,10 +90,7 @@
|
|||||||
damages:
|
damages:
|
||||||
Blunt: 1
|
Blunt: 1
|
||||||
- type: SolutionContainer
|
- type: SolutionContainer
|
||||||
maxVol: 10
|
maxVol: 15
|
||||||
contents:
|
caps: AddTo, RemoveFrom
|
||||||
reagents:
|
|
||||||
- ReagentId: chem.H2O
|
|
||||||
Quantity: 10
|
|
||||||
caps: RemoveFrom
|
|
||||||
- type: ChemicalInjectionProjectile
|
- type: ChemicalInjectionProjectile
|
||||||
|
transferAmount: 15
|
||||||
|
|||||||
Reference in New Issue
Block a user