Fix Injector (#6585)

This commit is contained in:
Leon Friedrich
2022-02-10 04:08:59 +13:00
committed by GitHub
parent b806980c07
commit 212c27cd6f
3 changed files with 21 additions and 27 deletions

View File

@@ -11,11 +11,8 @@ using Content.Shared.Database;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Localization;
using Robust.Shared.Player; using Robust.Shared.Player;
namespace Content.Server.Chemistry.EntitySystems; namespace Content.Server.Chemistry.EntitySystems;
@@ -42,12 +39,12 @@ public sealed partial class ChemistrySystem
private void OnInjectionComplete(InjectionCompleteEvent ev) private void OnInjectionComplete(InjectionCompleteEvent ev)
{ {
var component = ev.Component; ev.Component.CancelToken = null;
var user = ev.User; UseInjector(ev.Target, ev.User, ev.Component);
var target = ev.Target; }
component.CancelToken = null;
private void UseInjector(EntityUid target, EntityUid user, InjectorComponent component)
{
// Handle injecting/drawing for solutions // Handle injecting/drawing for solutions
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject) if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
{ {
@@ -116,9 +113,6 @@ public sealed partial class ChemistrySystem
return; return;
} }
if (!_blocker.CanInteract(args.User))
return;
//Make sure we have the attacking entity //Make sure we have the attacking entity
if (args.Target is not { Valid: true } target || if (args.Target is not { Valid: true } target ||
!HasComp<SolutionContainerManagerComponent>(uid)) !HasComp<SolutionContainerManagerComponent>(uid))
@@ -134,6 +128,9 @@ public sealed partial class ChemistrySystem
args.Handled = true; args.Handled = true;
return; return;
} }
UseInjector(target, args.User, component);
args.Handled = true;
} }
private void OnInjectorStartup(EntityUid uid, InjectorComponent component, ComponentStartup args) private void OnInjectorStartup(EntityUid uid, InjectorComponent component, ComponentStartup args)
@@ -188,7 +185,6 @@ public sealed partial class ChemistrySystem
if (!_solutions.TryGetSolution(component.Owner, InjectorComponent.SolutionName, out var solution)) if (!_solutions.TryGetSolution(component.Owner, InjectorComponent.SolutionName, out var solution))
return; return;
// Get entity for logging. Log with EntityUids when?
var actualDelay = MathF.Max(component.Delay, 1f); var actualDelay = MathF.Max(component.Delay, 1f);
if (user != target) if (user != target)
{ {
@@ -214,7 +210,6 @@ public sealed partial class ChemistrySystem
{ {
_logs.Add(LogType.ForceFeed, _logs.Add(LogType.ForceFeed,
$"{EntityManager.ToPrettyString(user):user} is attempting to inject {EntityManager.ToPrettyString(target):target} with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}"); $"{EntityManager.ToPrettyString(user):user} is attempting to inject {EntityManager.ToPrettyString(target):target} with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}");
// TODO solution pretty string.
} }
} }
else else
@@ -225,7 +220,6 @@ public sealed partial class ChemistrySystem
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject) if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
_logs.Add(LogType.Ingestion, _logs.Add(LogType.Ingestion,
$"{EntityManager.ToPrettyString(user):user} is attempting to inject themselves with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}."); $"{EntityManager.ToPrettyString(user):user} is attempting to inject themselves with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}.");
//TODO solution pretty string.
} }
component.CancelToken = new CancellationTokenSource(); component.CancelToken = new CancellationTokenSource();
@@ -358,7 +352,7 @@ public sealed partial class ChemistrySystem
// Move units from attackSolution to targetSolution // Move units from attackSolution to targetSolution
var removedSolution = _solutions.Draw(targetEntity, targetSolution, realTransferAmount); var removedSolution = _solutions.Draw(targetEntity, targetSolution, realTransferAmount);
if (!_solutions.TryAddSolution(targetEntity, solution, removedSolution)) if (!_solutions.TryAddSolution(component.Owner, solution, removedSolution))
{ {
return; return;
} }

View File

@@ -103,8 +103,8 @@ namespace Content.Server.Chemistry.EntitySystems
|| !Resolve(uid, ref appearanceComponent, false)) || !Resolve(uid, ref appearanceComponent, false))
return; return;
var filledVolumeFraction = solution.CurrentVolume.Float() / solution.MaxVolume.Float(); var filledVolumePercent = solution.CurrentVolume.Float() / solution.MaxVolume.Float();
appearanceComponent.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumeFraction)); appearanceComponent.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumePercent));
} }
/// <summary> /// <summary>

View File

@@ -1,5 +1,3 @@
using System;
using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry namespace Content.Shared.Chemistry
@@ -11,27 +9,29 @@ namespace Content.Shared.Chemistry
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]
public class SolutionContainerVisualState : ICloneable public sealed class SolutionContainerVisualState : ICloneable
{ {
public readonly Color Color; public readonly Color Color;
/// <summary>
/// Represents how full the container is, as a fraction equivalent to <see cref="FilledVolumeFraction"/>/<see cref="byte.MaxValue"/>.
/// </summary>
public readonly byte FilledVolumeFraction; public readonly byte FilledVolumeFraction;
// do we really need this just to save three bytes? // do we really need this just to save three bytes?
// This does seem silly
public float FilledVolumePercent => (float) FilledVolumeFraction / byte.MaxValue; public float FilledVolumePercent => (float) FilledVolumeFraction / byte.MaxValue;
/// <summary> /// <summary>
/// Sets the solution state of a container. /// Sets the solution state of a container.
/// </summary> /// </summary>
/// <param name="color"></param> public SolutionContainerVisualState(Color color, float filledVolumePercent)
/// <param name="filledVolumeFraction">The fraction of the container's volume that is filled.</param>
public SolutionContainerVisualState(Color color, float filledVolumeFraction)
{ {
Color = color; Color = color;
FilledVolumeFraction = (byte) (byte.MaxValue * filledVolumeFraction); FilledVolumeFraction = (byte) (byte.MaxValue * filledVolumePercent);
}
public SolutionContainerVisualState(Color color, byte filledVolumeFraction)
{
Color = color;
FilledVolumeFraction = filledVolumeFraction;
} }
public object Clone() public object Clone()