Revert 'Revert 'Solution Entities'' (#23168)
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Forensics;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.Forensics;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems;
|
||||
|
||||
@@ -25,11 +26,11 @@ public sealed partial class ChemistrySystem
|
||||
/// <summary>
|
||||
/// Default transfer amounts for the set-transfer verb.
|
||||
/// </summary>
|
||||
public static readonly List<int> TransferAmounts = new() {1, 5, 10, 15};
|
||||
public static readonly List<int> TransferAmounts = new() { 1, 5, 10, 15 };
|
||||
private void InitializeInjector()
|
||||
{
|
||||
SubscribeLocalEvent<InjectorComponent, GetVerbsEvent<AlternativeVerb>>(AddSetTransferVerbs);
|
||||
SubscribeLocalEvent<InjectorComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<InjectorComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<InjectorComponent, InjectorDoAfterEvent>(OnInjectDoAfter);
|
||||
SubscribeLocalEvent<InjectorComponent, ComponentStartup>(OnInjectorStartup);
|
||||
SubscribeLocalEvent<InjectorComponent, UseInHandEvent>(OnInjectorUse);
|
||||
@@ -37,7 +38,7 @@ public sealed partial class ChemistrySystem
|
||||
SubscribeLocalEvent<InjectorComponent, ComponentGetState>(OnInjectorGetState);
|
||||
}
|
||||
|
||||
private void AddSetTransferVerbs(EntityUid uid, InjectorComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
private void AddSetTransferVerbs(Entity<InjectorComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
|
||||
return;
|
||||
@@ -45,11 +46,14 @@ public sealed partial class ChemistrySystem
|
||||
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
|
||||
return;
|
||||
|
||||
var (uid, component) = entity;
|
||||
|
||||
// Add specific transfer verbs according to the container's size
|
||||
var priority = 0;
|
||||
var user = args.User;
|
||||
foreach (var amount in TransferAmounts)
|
||||
{
|
||||
if ( amount < component.MinimumTransferAmount.Int() || amount > component.MaximumTransferAmount.Int())
|
||||
if (amount < component.MinimumTransferAmount.Int() || amount > component.MaximumTransferAmount.Int())
|
||||
continue;
|
||||
|
||||
AlternativeVerb verb = new();
|
||||
@@ -58,7 +62,7 @@ public sealed partial class ChemistrySystem
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.TransferAmount = FixedPoint2.New(amount);
|
||||
_popup.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)), args.User, args.User);
|
||||
_popup.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)), user, user);
|
||||
};
|
||||
|
||||
// we want to sort by size, not alphabetically by the verb text.
|
||||
@@ -69,22 +73,22 @@ public sealed partial class ChemistrySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void UseInjector(EntityUid target, EntityUid user, EntityUid injector, InjectorComponent component)
|
||||
private void UseInjector(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
|
||||
{
|
||||
// Handle injecting/drawing for solutions
|
||||
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
if (injector.Comp.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
{
|
||||
if (_solutions.TryGetInjectableSolution(target, out var injectableSolution))
|
||||
if (_solutionContainers.TryGetInjectableSolution(target, out var injectableSolution, out _))
|
||||
{
|
||||
TryInject(component, injector, target, injectableSolution, user, false);
|
||||
TryInject(injector, target, injectableSolution.Value, user, false);
|
||||
}
|
||||
else if (_solutions.TryGetRefillableSolution(target, out var refillableSolution))
|
||||
else if (_solutionContainers.TryGetRefillableSolution(target, out var refillableSolution, out _))
|
||||
{
|
||||
TryInject(component, injector, target, refillableSolution, user, true);
|
||||
TryInject(injector, target, refillableSolution.Value, user, true);
|
||||
}
|
||||
else if (TryComp<BloodstreamComponent>(target, out var bloodstream))
|
||||
{
|
||||
TryInjectIntoBloodstream(component, injector, target, bloodstream, user);
|
||||
TryInjectIntoBloodstream(injector, (target, bloodstream), user);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,111 +96,112 @@ public sealed partial class ChemistrySystem
|
||||
("target", Identity.Entity(target, EntityManager))), injector, user);
|
||||
}
|
||||
}
|
||||
else if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Draw)
|
||||
else if (injector.Comp.ToggleState == SharedInjectorComponent.InjectorToggleMode.Draw)
|
||||
{
|
||||
// Draw from a bloodstream, if the target has that
|
||||
if (TryComp<BloodstreamComponent>(target, out var stream))
|
||||
if (TryComp<BloodstreamComponent>(target, out var stream) &&
|
||||
_solutionContainers.ResolveSolution(target, stream.BloodSolutionName, ref stream.BloodSolution))
|
||||
{
|
||||
TryDraw(component, injector, target, stream.BloodSolution, user, stream);
|
||||
TryDraw(injector, (target, stream), stream.BloodSolution.Value, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// Draw from an object (food, beaker, etc)
|
||||
if (_solutions.TryGetDrawableSolution(target, out var drawableSolution))
|
||||
if (_solutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _))
|
||||
{
|
||||
TryDraw(component, injector, target, drawableSolution, user);
|
||||
TryDraw(injector, target, drawableSolution.Value, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-cannot-draw-message",
|
||||
("target", Identity.Entity(target, EntityManager))), injector, user);
|
||||
("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, InjectorComponent component, SolutionChangedEvent args)
|
||||
private void OnSolutionChange(Entity<InjectorComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
Dirty(component);
|
||||
Dirty(entity);
|
||||
}
|
||||
|
||||
private void OnInjectorGetState(EntityUid uid, InjectorComponent component, ref ComponentGetState args)
|
||||
private void OnInjectorGetState(Entity<InjectorComponent> entity, ref ComponentGetState args)
|
||||
{
|
||||
_solutions.TryGetSolution(uid, InjectorComponent.SolutionName, out var solution);
|
||||
_solutionContainers.TryGetSolution(entity.Owner, InjectorComponent.SolutionName, out _, out var solution);
|
||||
|
||||
var currentVolume = solution?.Volume ?? FixedPoint2.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? FixedPoint2.Zero;
|
||||
|
||||
args.State = new SharedInjectorComponent.InjectorComponentState(currentVolume, maxVolume, component.ToggleState);
|
||||
args.State = new SharedInjectorComponent.InjectorComponentState(currentVolume, maxVolume, entity.Comp.ToggleState);
|
||||
}
|
||||
|
||||
private void OnInjectDoAfter(EntityUid uid, InjectorComponent component, DoAfterEvent args)
|
||||
private void OnInjectDoAfter(Entity<InjectorComponent> entity, ref InjectorDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled || args.Handled || args.Args.Target == null)
|
||||
return;
|
||||
|
||||
UseInjector(args.Args.Target.Value, args.Args.User, uid, component);
|
||||
UseInjector(entity, args.Args.Target.Value, args.Args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnInjectorAfterInteract(EntityUid uid, InjectorComponent component, AfterInteractEvent args)
|
||||
private void OnInjectorAfterInteract(Entity<InjectorComponent> entity, ref AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
return;
|
||||
|
||||
//Make sure we have the attacking entity
|
||||
if (args.Target is not { Valid: true } target || !HasComp<SolutionContainerManagerComponent>(uid))
|
||||
if (args.Target is not { Valid: true } target || !HasComp<SolutionContainerManagerComponent>(entity))
|
||||
return;
|
||||
|
||||
// Is the target a mob? If yes, use a do-after to give them time to respond.
|
||||
if (HasComp<MobStateComponent>(target) || HasComp<BloodstreamComponent>(target))
|
||||
{
|
||||
// Are use using an injector capible of targeting a mob?
|
||||
if (component.IgnoreMobs)
|
||||
if (entity.Comp.IgnoreMobs)
|
||||
return;
|
||||
|
||||
InjectDoAfter(component, args.User, target, uid);
|
||||
InjectDoAfter(entity, target, args.User);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
UseInjector(target, args.User, uid, component);
|
||||
UseInjector(entity, target, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnInjectorStartup(EntityUid uid, InjectorComponent component, ComponentStartup args)
|
||||
private void OnInjectorStartup(Entity<InjectorComponent> entity, ref ComponentStartup args)
|
||||
{
|
||||
// ???? why ?????
|
||||
Dirty(component);
|
||||
Dirty(entity);
|
||||
}
|
||||
|
||||
private void OnInjectorUse(EntityUid uid, InjectorComponent component, UseInHandEvent args)
|
||||
private void OnInjectorUse(Entity<InjectorComponent> entity, ref UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
Toggle(component, args.User, uid);
|
||||
Toggle(entity, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle between draw/inject state if applicable
|
||||
/// </summary>
|
||||
private void Toggle(InjectorComponent component, EntityUid user, EntityUid injector)
|
||||
private void Toggle(Entity<InjectorComponent> injector, EntityUid user)
|
||||
{
|
||||
if (component.InjectOnly)
|
||||
if (injector.Comp.InjectOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string msg;
|
||||
switch (component.ToggleState)
|
||||
switch (injector.Comp.ToggleState)
|
||||
{
|
||||
case SharedInjectorComponent.InjectorToggleMode.Inject:
|
||||
component.ToggleState = SharedInjectorComponent.InjectorToggleMode.Draw;
|
||||
injector.Comp.ToggleState = SharedInjectorComponent.InjectorToggleMode.Draw;
|
||||
msg = "injector-component-drawing-text";
|
||||
break;
|
||||
case SharedInjectorComponent.InjectorToggleMode.Draw:
|
||||
component.ToggleState = SharedInjectorComponent.InjectorToggleMode.Inject;
|
||||
injector.Comp.ToggleState = SharedInjectorComponent.InjectorToggleMode.Inject;
|
||||
msg = "injector-component-injecting-text";
|
||||
break;
|
||||
default:
|
||||
@@ -209,18 +214,18 @@ public sealed partial class ChemistrySystem
|
||||
/// <summary>
|
||||
/// Send informative pop-up messages and wait for a do-after to complete.
|
||||
/// </summary>
|
||||
private void InjectDoAfter(InjectorComponent component, EntityUid user, EntityUid target, EntityUid injector)
|
||||
private void InjectDoAfter(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
|
||||
{
|
||||
// Create a pop-up for the user
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, user);
|
||||
|
||||
if (!_solutions.TryGetSolution(injector, InjectorComponent.SolutionName, out var solution))
|
||||
if (!_solutionContainers.TryGetSolution(injector.Owner, InjectorComponent.SolutionName, out _, out var solution))
|
||||
return;
|
||||
|
||||
var actualDelay = MathF.Max(component.Delay, 1f);
|
||||
var actualDelay = MathF.Max(injector.Comp.Delay, 1f);
|
||||
|
||||
// Injections take 0.5 seconds longer per additional 5u
|
||||
actualDelay += (float) component.TransferAmount / component.Delay - 0.5f;
|
||||
actualDelay += (float) injector.Comp.TransferAmount / injector.Comp.Delay - 0.5f;
|
||||
|
||||
var isTarget = user != target;
|
||||
|
||||
@@ -244,7 +249,7 @@ public sealed partial class ChemistrySystem
|
||||
}
|
||||
|
||||
// Add an admin log, using the "force feed" log type. It's not quite feeding, but the effect is the same.
|
||||
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
if (injector.Comp.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
{
|
||||
_adminLogger.Add(LogType.ForceFeed,
|
||||
$"{EntityManager.ToPrettyString(user):user} is attempting to inject {EntityManager.ToPrettyString(target):target} with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}");
|
||||
@@ -255,11 +260,11 @@ public sealed partial class ChemistrySystem
|
||||
// Self-injections take half as long.
|
||||
actualDelay /= 2;
|
||||
|
||||
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
if (injector.Comp.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
_adminLogger.Add(LogType.Ingestion, $"{EntityManager.ToPrettyString(user):user} is attempting to inject themselves with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}.");
|
||||
}
|
||||
|
||||
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, actualDelay, new InjectorDoAfterEvent(), injector, target: target, used: injector)
|
||||
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, actualDelay, new InjectorDoAfterEvent(), injector.Owner, target: target, used: injector.Owner)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnDamage = true,
|
||||
@@ -268,77 +273,80 @@ public sealed partial class ChemistrySystem
|
||||
});
|
||||
}
|
||||
|
||||
private void TryInjectIntoBloodstream(InjectorComponent component, EntityUid injector, EntityUid target, BloodstreamComponent targetBloodstream, EntityUid user)
|
||||
private void TryInjectIntoBloodstream(Entity<InjectorComponent> injector, Entity<BloodstreamComponent> target, EntityUid user)
|
||||
{
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = FixedPoint2.Min(component.TransferAmount, targetBloodstream.ChemicalSolution.AvailableVolume);
|
||||
if (!_solutionContainers.ResolveSolution(target.Owner, target.Comp.ChemicalSolutionName, ref target.Comp.ChemicalSolution, out var chemSolution))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-cannot-inject-message", ("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
return;
|
||||
}
|
||||
|
||||
var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, chemSolution.AvailableVolume);
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-cannot-inject-message", ("target", Identity.Entity(target, EntityManager))), injector, user);
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-cannot-inject-message", ("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = _solutions.SplitSolution(user, targetBloodstream.ChemicalSolution, realTransferAmount);
|
||||
var removedSolution = _solutionContainers.SplitSolution(target.Comp.ChemicalSolution.Value, realTransferAmount);
|
||||
|
||||
_blood.TryAddToChemicals(target, removedSolution, targetBloodstream);
|
||||
_blood.TryAddToChemicals(target, removedSolution, target.Comp);
|
||||
|
||||
_reactiveSystem.DoEntityReaction(target, removedSolution, ReactionMethod.Injection);
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-inject-success-message",
|
||||
("amount", removedSolution.Volume),
|
||||
("target", Identity.Entity(target, EntityManager))), injector, user);
|
||||
("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
|
||||
Dirty(component);
|
||||
AfterInject(component, injector, target);
|
||||
Dirty(injector);
|
||||
AfterInject(injector, target);
|
||||
}
|
||||
|
||||
private void TryInject(InjectorComponent component, EntityUid injector, EntityUid targetEntity, Solution targetSolution, EntityUid user, bool asRefill)
|
||||
private void TryInject(Entity<InjectorComponent> injector, EntityUid targetEntity, Entity<SolutionComponent> targetSolution, EntityUid user, bool asRefill)
|
||||
{
|
||||
if (!_solutions.TryGetSolution(injector, InjectorComponent.SolutionName, out var solution)
|
||||
|| solution.Volume == 0)
|
||||
if (!_solutionContainers.TryGetSolution(injector.Owner, InjectorComponent.SolutionName, out var soln, out var solution) || solution.Volume == 0)
|
||||
return;
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = FixedPoint2.Min(component.TransferAmount, targetSolution.AvailableVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, targetSolution.Comp.Solution.AvailableVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-target-already-full-message", ("target", Identity.Entity(targetEntity, EntityManager))),
|
||||
injector, user);
|
||||
injector.Owner, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move units from attackSolution to targetSolution
|
||||
Solution removedSolution;
|
||||
if (TryComp<StackComponent>(targetEntity, out var stack))
|
||||
removedSolution = _solutions.SplitStackSolution(injector, solution, realTransferAmount, stack.Count);
|
||||
removedSolution = _solutionContainers.SplitStackSolution(soln.Value, realTransferAmount, stack.Count);
|
||||
else
|
||||
removedSolution = _solutions.SplitSolution(injector, solution, realTransferAmount);
|
||||
removedSolution = _solutionContainers.SplitSolution(soln.Value, realTransferAmount);
|
||||
|
||||
_reactiveSystem.DoEntityReaction(targetEntity, removedSolution, ReactionMethod.Injection);
|
||||
|
||||
if (!asRefill)
|
||||
_solutions.Inject(targetEntity, targetSolution, removedSolution);
|
||||
_solutionContainers.Inject(targetEntity, targetSolution, removedSolution);
|
||||
else
|
||||
_solutions.Refill(targetEntity, targetSolution, removedSolution);
|
||||
_solutionContainers.Refill(targetEntity, targetSolution, removedSolution);
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-transfer-success-message",
|
||||
("amount", removedSolution.Volume),
|
||||
("target", Identity.Entity(targetEntity, EntityManager))), injector, user);
|
||||
("target", Identity.Entity(targetEntity, EntityManager))), injector.Owner, user);
|
||||
|
||||
Dirty(component);
|
||||
AfterInject(component, injector, targetEntity);
|
||||
Dirty(injector);
|
||||
AfterInject(injector, targetEntity);
|
||||
}
|
||||
|
||||
private void AfterInject(InjectorComponent component, EntityUid injector, EntityUid target)
|
||||
private void AfterInject(Entity<InjectorComponent> injector, EntityUid target)
|
||||
{
|
||||
// Automatically set syringe to draw after completely draining it.
|
||||
if (_solutions.TryGetSolution(injector, InjectorComponent.SolutionName, out var solution)
|
||||
&& solution.Volume == 0)
|
||||
if (_solutionContainers.TryGetSolution(injector.Owner, InjectorComponent.SolutionName, out _, out var solution) && solution.Volume == 0)
|
||||
{
|
||||
component.ToggleState = SharedInjectorComponent.InjectorToggleMode.Draw;
|
||||
injector.Comp.ToggleState = SharedInjectorComponent.InjectorToggleMode.Draw;
|
||||
}
|
||||
|
||||
// Leave some DNA from the injectee on it
|
||||
@@ -346,13 +354,12 @@ public sealed partial class ChemistrySystem
|
||||
RaiseLocalEvent(target, ref ev);
|
||||
}
|
||||
|
||||
private void AfterDraw(InjectorComponent component, EntityUid injector, EntityUid target)
|
||||
private void AfterDraw(Entity<InjectorComponent> injector, EntityUid target)
|
||||
{
|
||||
// Automatically set syringe to inject after completely filling it.
|
||||
if (_solutions.TryGetSolution(injector, InjectorComponent.SolutionName, out var solution)
|
||||
&& solution.AvailableVolume == 0)
|
||||
if (_solutionContainers.TryGetSolution(injector.Owner, InjectorComponent.SolutionName, out _, out var solution) && solution.AvailableVolume == 0)
|
||||
{
|
||||
component.ToggleState = SharedInjectorComponent.InjectorToggleMode.Inject;
|
||||
injector.Comp.ToggleState = SharedInjectorComponent.InjectorToggleMode.Inject;
|
||||
}
|
||||
|
||||
// Leave some DNA from the drawee on it
|
||||
@@ -360,70 +367,68 @@ public sealed partial class ChemistrySystem
|
||||
RaiseLocalEvent(target, ref ev);
|
||||
}
|
||||
|
||||
private void TryDraw(InjectorComponent component, EntityUid injector, EntityUid targetEntity, Solution targetSolution, EntityUid user, BloodstreamComponent? stream = null)
|
||||
private void TryDraw(Entity<InjectorComponent> injector, Entity<BloodstreamComponent?> target, Entity<SolutionComponent> targetSolution, EntityUid user)
|
||||
{
|
||||
if (!_solutions.TryGetSolution(injector, InjectorComponent.SolutionName, out var solution)
|
||||
|| solution.AvailableVolume == 0)
|
||||
if (!_solutionContainers.TryGetSolution(injector.Owner, InjectorComponent.SolutionName, out var soln, out var solution) || solution.AvailableVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room, also make sure there's room in the injector
|
||||
var realTransferAmount = FixedPoint2.Min(component.TransferAmount, targetSolution.Volume, solution.AvailableVolume);
|
||||
var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, targetSolution.Comp.Solution.Volume, solution.AvailableVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-target-is-empty-message", ("target", Identity.Entity(targetEntity, EntityManager))),
|
||||
injector, user);
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-target-is-empty-message", ("target", Identity.Entity(target, EntityManager))),
|
||||
injector.Owner, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// We have some snowflaked behavior for streams.
|
||||
if (stream != null)
|
||||
if (target.Comp != null)
|
||||
{
|
||||
DrawFromBlood(user, injector, targetEntity, component, solution, stream, realTransferAmount);
|
||||
DrawFromBlood(injector, (target.Owner, target.Comp), soln.Value, realTransferAmount, user);
|
||||
return;
|
||||
}
|
||||
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = _solutions.Draw(targetEntity, targetSolution, realTransferAmount);
|
||||
var removedSolution = _solutionContainers.Draw(target.Owner, targetSolution, realTransferAmount);
|
||||
|
||||
if (!_solutions.TryAddSolution(injector, solution, removedSolution))
|
||||
if (!_solutionContainers.TryAddSolution(soln.Value, removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-draw-success-message",
|
||||
("amount", removedSolution.Volume),
|
||||
("target", Identity.Entity(targetEntity, EntityManager))), injector, user);
|
||||
("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
|
||||
Dirty(component);
|
||||
AfterDraw(component, injector, targetEntity);
|
||||
Dirty(injector);
|
||||
AfterDraw(injector, target);
|
||||
}
|
||||
|
||||
private void DrawFromBlood(EntityUid user, EntityUid injector, EntityUid target, InjectorComponent component, Solution injectorSolution, BloodstreamComponent stream, FixedPoint2 transferAmount)
|
||||
private void DrawFromBlood(Entity<InjectorComponent> injector, Entity<BloodstreamComponent> target, Entity<SolutionComponent> injectorSolution, FixedPoint2 transferAmount, EntityUid user)
|
||||
{
|
||||
var drawAmount = (float) transferAmount;
|
||||
var bloodAmount = drawAmount;
|
||||
var chemAmount = 0f;
|
||||
if (stream.ChemicalSolution.Volume > 0f) // If they have stuff in their chem stream, we'll draw some of that
|
||||
|
||||
if (_solutionContainers.ResolveSolution(target.Owner, target.Comp.ChemicalSolutionName, ref target.Comp.ChemicalSolution))
|
||||
{
|
||||
bloodAmount = drawAmount * 0.85f;
|
||||
chemAmount = drawAmount * 0.15f;
|
||||
var chemTemp = _solutionContainers.SplitSolution(target.Comp.ChemicalSolution.Value, drawAmount * 0.15f);
|
||||
_solutionContainers.TryAddSolution(injectorSolution, chemTemp);
|
||||
drawAmount -= (float) chemTemp.Volume;
|
||||
}
|
||||
|
||||
var bloodTemp = stream.BloodSolution.SplitSolution(bloodAmount);
|
||||
var chemTemp = stream.ChemicalSolution.SplitSolution(chemAmount);
|
||||
|
||||
_solutions.TryAddSolution(injector, injectorSolution, bloodTemp);
|
||||
_solutions.TryAddSolution(injector, injectorSolution, chemTemp);
|
||||
if (_solutionContainers.ResolveSolution(target.Owner, target.Comp.BloodSolutionName, ref target.Comp.BloodSolution))
|
||||
{
|
||||
var bloodTemp = _solutionContainers.SplitSolution(target.Comp.BloodSolution.Value, drawAmount);
|
||||
_solutionContainers.TryAddSolution(injectorSolution, bloodTemp);
|
||||
}
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-draw-success-message",
|
||||
("amount", transferAmount),
|
||||
("target", Identity.Entity(target, EntityManager))), injector, user);
|
||||
("target", Identity.Entity(target, EntityManager))), injector.Owner, user);
|
||||
|
||||
Dirty(component);
|
||||
AfterDraw(component, injector, target);
|
||||
Dirty(injector);
|
||||
AfterDraw(injector, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user