Refactor chemical injection to be ECS (#4296)
This commit is contained in:
@@ -233,7 +233,7 @@ namespace Content.Client.Entry
|
|||||||
"ConveyorAssembly",
|
"ConveyorAssembly",
|
||||||
"TwoWayLever",
|
"TwoWayLever",
|
||||||
"FirelockElectronics",
|
"FirelockElectronics",
|
||||||
"ChemicalInjectionProjectile",
|
"SolutionInjectOnCollide",
|
||||||
"Machine",
|
"Machine",
|
||||||
"MachinePart",
|
"MachinePart",
|
||||||
"MachineFrame",
|
"MachineFrame",
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Content.Server.Body.Circulatory;
|
|
||||||
using Content.Shared.Chemistry.Reagent;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Physics.Collision;
|
|
||||||
using Robust.Shared.Physics.Dynamics;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
|
||||||
using Robust.Shared.ViewVariables;
|
|
||||||
|
|
||||||
namespace Content.Server.Chemistry.Components
|
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public class ChemicalInjectionProjectileComponent : Component, IStartCollide
|
|
||||||
{
|
|
||||||
public override string Name => "ChemicalInjectionProjectile";
|
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
private SolutionContainerComponent _solutionContainer = default!;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
[DataField("transferAmount")]
|
|
||||||
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1);
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
|
|
||||||
[DataField("transferEfficiency")]
|
|
||||||
private float _transferEfficiency = 1f;
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
_solutionContainer = Owner.EnsureComponent<SolutionContainerComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
|
||||||
{
|
|
||||||
if (!otherFixture.Body.Owner.TryGetComponent<BloodstreamComponent>(out var bloodstream))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var solution = _solutionContainer.Solution;
|
|
||||||
var solRemoved = solution.SplitSolution(TransferAmount);
|
|
||||||
var solRemovedVol = solRemoved.TotalVolume;
|
|
||||||
|
|
||||||
var solToInject = solRemoved.SplitSolution(solRemovedVol * TransferEfficiency);
|
|
||||||
|
|
||||||
bloodstream.TryTransferSolution(solToInject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.Chemistry.Reagent;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.Components
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// On colliding with an entity that has a bloodstream will dump its solution onto them.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
internal sealed class SolutionInjectOnCollideComponent : Component
|
||||||
|
{
|
||||||
|
public override string Name => "SolutionInjectOnCollide";
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("transferAmount")]
|
||||||
|
public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1);
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
|
||||||
|
|
||||||
|
[DataField("transferEfficiency")]
|
||||||
|
private float _transferEfficiency = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using Content.Server.Body.Circulatory;
|
||||||
|
using Content.Server.Chemistry.Components;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Physics.Dynamics;
|
||||||
|
|
||||||
|
namespace Content.Server.Chemistry.EntitySystems
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
internal sealed class SolutionInjectOnCollideSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<SolutionInjectOnCollideComponent, ComponentInit>(HandleInit);
|
||||||
|
SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleInit(EntityUid uid, SolutionInjectOnCollideComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
component.Owner.EnsureComponentWarn<SolutionContainerComponent>($"{nameof(SolutionInjectOnCollideComponent)} requires a SolutionContainer on {component.Owner}!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleInjection(EntityUid uid, SolutionInjectOnCollideComponent component, StartCollideEvent args)
|
||||||
|
{
|
||||||
|
if (!args.OtherFixture.Body.Owner.TryGetComponent<BloodstreamComponent>(out var bloodstream) ||
|
||||||
|
!ComponentManager.TryGetComponent(uid, out SolutionContainerComponent? solutionContainer)) return;
|
||||||
|
|
||||||
|
var solution = solutionContainer.Solution;
|
||||||
|
var solRemoved = solution.SplitSolution(component.TransferAmount);
|
||||||
|
var solRemovedVol = solRemoved.TotalVolume;
|
||||||
|
|
||||||
|
var solToInject = solRemoved.SplitSolution(solRemovedVol * component.TransferEfficiency);
|
||||||
|
|
||||||
|
bloodstream.TryTransferSolution(solToInject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,5 +92,5 @@
|
|||||||
- type: SolutionContainer
|
- type: SolutionContainer
|
||||||
maxVol: 15
|
maxVol: 15
|
||||||
caps: Refillable, Drainable
|
caps: Refillable, Drainable
|
||||||
- type: ChemicalInjectionProjectile
|
- type: SolutionInjectOnCollide
|
||||||
transferAmount: 15
|
transferAmount: 15
|
||||||
|
|||||||
Reference in New Issue
Block a user