Skip to content

Commit

Permalink
allow syringes to set transfer amount (#12173)
Browse files Browse the repository at this point in the history
* allow syringes to set transfer amount

* stripped custom transfer logic, and added delay per additional 5u transfered

* touch up

* another touch
  • Loading branch information
JustinTrotter authored Oct 26, 2022
1 parent 52a7a73 commit f2d05aa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Content.Server/Chemistry/Components/InjectorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Threading;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Server.UserInterface;
using Robust.Server.GameObjects;
using Content.Shared.Chemistry;

namespace Content.Server.Chemistry.Components
{
Expand All @@ -22,6 +25,20 @@ public sealed class InjectorComponent : SharedInjectorComponent
[DataField("injectOnly")]
public bool InjectOnly;

/// <summary>
/// The minimum amount of solution that can be transferred at once from this solution.
/// </summary>
[DataField("minTransferAmount")]
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5);

/// <summary>
/// The maximum amount of solution that can be transferred at once from this solution.
/// </summary>
[DataField("maxTransferAmount")]
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(50);

/// <summary>
/// Amount to inject or draw on each usage. If the injector is inject only, it will
/// attempt to inject it's entire contents upon use.
Expand Down
45 changes: 45 additions & 0 deletions Content.Server/Chemistry/EntitySystems/ChemistrySystem.Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@
using Robust.Shared.GameStates;
using Robust.Shared.Player;
using System.Threading;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Content.Shared.Popups;

namespace Content.Server.Chemistry.EntitySystems;

public sealed partial class ChemistrySystem
{

/// <summary>
/// Default transfer amounts for the set-transfer verb.
/// </summary>
public static readonly List<int> TransferAmounts = new() { 5, 10, 15};
private void InitializeInjector()
{
SubscribeLocalEvent<InjectorComponent, GetVerbsEvent<AlternativeVerb>>(AddSetTransferVerbs);
SubscribeLocalEvent<InjectorComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<InjectorComponent, HandDeselectedEvent>(OnInjectorDeselected);
SubscribeLocalEvent<InjectorComponent, ComponentStartup>(OnInjectorStartup);
Expand All @@ -33,6 +42,38 @@ private void InitializeInjector()
SubscribeLocalEvent<InjectionCancelledEvent>(OnInjectionCancelled);
}

private void AddSetTransferVerbs(EntityUid uid, InjectorComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;

if (!EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor))
return;

// Add specific transfer verbs according to the container's size
var priority = 0;
foreach (var amount in TransferAmounts)
{
if ( amount < component.MinimumTransferAmount.Int() || amount > component.MaximumTransferAmount.Int())
continue;

AlternativeVerb verb = new();
verb.Text = Loc.GetString("comp-solution-transfer-verb-amount", ("amount", amount));
verb.Category = VerbCategory.SetTransferAmount;
verb.Act = () =>
{
component.TransferAmount = FixedPoint2.New(amount);
args.User.PopupMessage(Loc.GetString("comp-solution-transfer-set-amount", ("amount", amount)));
};

// we want to sort by size, not alphabetically by the verb text.
verb.Priority = priority;
priority--;

args.Verbs.Add(verb);
}
}

private static void OnInjectionCancelled(InjectionCancelledEvent ev)
{
ev.Component.CancelToken = null;
Expand Down Expand Up @@ -196,6 +237,10 @@ private void InjectDoAfter(InjectorComponent component, EntityUid user, EntityUi
return;

var actualDelay = MathF.Max(component.Delay, 1f);

// Injections take 1 second longer per additional 5u
actualDelay += (float) component.TransferAmount / component.Delay - 1;

if (user != target)
{
// Create a pop-up for the target
Expand Down

0 comments on commit f2d05aa

Please sign in to comment.