Fix Injector (#6585)
This commit is contained in:
@@ -11,11 +11,8 @@ using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Chemistry.EntitySystems;
|
||||
@@ -42,12 +39,12 @@ public sealed partial class ChemistrySystem
|
||||
|
||||
private void OnInjectionComplete(InjectionCompleteEvent ev)
|
||||
{
|
||||
var component = ev.Component;
|
||||
var user = ev.User;
|
||||
var target = ev.Target;
|
||||
|
||||
component.CancelToken = null;
|
||||
ev.Component.CancelToken = null;
|
||||
UseInjector(ev.Target, ev.User, ev.Component);
|
||||
}
|
||||
|
||||
private void UseInjector(EntityUid target, EntityUid user, InjectorComponent component)
|
||||
{
|
||||
// Handle injecting/drawing for solutions
|
||||
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
{
|
||||
@@ -116,9 +113,6 @@ public sealed partial class ChemistrySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_blocker.CanInteract(args.User))
|
||||
return;
|
||||
|
||||
//Make sure we have the attacking entity
|
||||
if (args.Target is not { Valid: true } target ||
|
||||
!HasComp<SolutionContainerManagerComponent>(uid))
|
||||
@@ -134,6 +128,9 @@ public sealed partial class ChemistrySystem
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
UseInjector(target, args.User, component);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
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))
|
||||
return;
|
||||
|
||||
// Get entity for logging. Log with EntityUids when?
|
||||
var actualDelay = MathF.Max(component.Delay, 1f);
|
||||
if (user != target)
|
||||
{
|
||||
@@ -214,7 +210,6 @@ public sealed partial class ChemistrySystem
|
||||
{
|
||||
_logs.Add(LogType.ForceFeed,
|
||||
$"{EntityManager.ToPrettyString(user):user} is attempting to inject {EntityManager.ToPrettyString(target):target} with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}");
|
||||
// TODO solution pretty string.
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -225,7 +220,6 @@ public sealed partial class ChemistrySystem
|
||||
if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Inject)
|
||||
_logs.Add(LogType.Ingestion,
|
||||
$"{EntityManager.ToPrettyString(user):user} is attempting to inject themselves with a solution {SolutionContainerSystem.ToPrettyString(solution):solution}.");
|
||||
//TODO solution pretty string.
|
||||
}
|
||||
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
@@ -358,7 +352,7 @@ public sealed partial class ChemistrySystem
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = _solutions.Draw(targetEntity, targetSolution, realTransferAmount);
|
||||
|
||||
if (!_solutions.TryAddSolution(targetEntity, solution, removedSolution))
|
||||
if (!_solutions.TryAddSolution(component.Owner, solution, removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
|| !Resolve(uid, ref appearanceComponent, false))
|
||||
return;
|
||||
|
||||
var filledVolumeFraction = solution.CurrentVolume.Float() / solution.MaxVolume.Float();
|
||||
appearanceComponent.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumeFraction));
|
||||
var filledVolumePercent = solution.CurrentVolume.Float() / solution.MaxVolume.Float();
|
||||
appearanceComponent.SetData(SolutionContainerVisuals.VisualState, new SolutionContainerVisualState(solution.Color, filledVolumePercent));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Chemistry
|
||||
@@ -11,27 +9,29 @@ namespace Content.Shared.Chemistry
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class SolutionContainerVisualState : ICloneable
|
||||
public sealed class SolutionContainerVisualState : ICloneable
|
||||
{
|
||||
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;
|
||||
|
||||
// do we really need this just to save three bytes?
|
||||
// This does seem silly
|
||||
public float FilledVolumePercent => (float) FilledVolumeFraction / byte.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the solution state of a container.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="filledVolumeFraction">The fraction of the container's volume that is filled.</param>
|
||||
public SolutionContainerVisualState(Color color, float filledVolumeFraction)
|
||||
public SolutionContainerVisualState(Color color, float filledVolumePercent)
|
||||
{
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user