Skip to content

Commit

Permalink
Make delay incurred from additional syringe contents modifiable + tin…
Browse files Browse the repository at this point in the history
…y syringe buff/fix (space-wizards#29825)

* Make delay incurred by transfer amount modifiable

* No unintentional negative delay please

* Use more fixedpoint, hope I didn't break anything

* merge review suggestion

Co-authored-by: ShadowCommander <[email protected]>

---------

Co-authored-by: ShadowCommander <[email protected]>
  • Loading branch information
2 people authored and themias committed Aug 9, 2024
1 parent 3447c4c commit 52fcc6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,25 @@ private void InjectDoAfter(Entity<InjectorComponent> injector, EntityUid target,
if (!SolutionContainers.TryGetSolution(injector.Owner, injector.Comp.SolutionName, out _, out var solution))
return;

var actualDelay = MathHelper.Max(injector.Comp.Delay, TimeSpan.FromSeconds(1));
float amountToInject;
var actualDelay = injector.Comp.Delay;
FixedPoint2 amountToInject;
if (injector.Comp.ToggleState == InjectorToggleMode.Draw)
{
// additional delay is based on actual volume left to draw in syringe when smaller than transfer amount
amountToInject = Math.Min(injector.Comp.TransferAmount.Float(), (solution.MaxVolume - solution.Volume).Float());
amountToInject = FixedPoint2.Min(injector.Comp.TransferAmount, (solution.MaxVolume - solution.Volume));
}
else
{
// additional delay is based on actual volume left to inject in syringe when smaller than transfer amount
amountToInject = Math.Min(injector.Comp.TransferAmount.Float(), solution.Volume.Float());
amountToInject = FixedPoint2.Min(injector.Comp.TransferAmount, solution.Volume);
}

// Injections take 0.5 seconds longer per 5u of possible space/content
actualDelay += TimeSpan.FromSeconds(amountToInject / 10);
// First 5u(MinimumTransferAmount) doesn't incur delay
actualDelay += injector.Comp.DelayPerVolume * FixedPoint2.Max(0, amountToInject - injector.Comp.MinimumTransferAmount).Double();

// Ensure that minimum delay before incapacitation checks is 1 seconds
actualDelay = MathHelper.Max(actualDelay, TimeSpan.FromSeconds(1));


var isTarget = user != target;
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Chemistry/Components/InjectorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public sealed partial class InjectorComponent : Component
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(5);

/// <summary>
/// Each additional 1u after first 5u increases the delay by X seconds.
/// </summary>
[DataField]
public TimeSpan DelayPerVolume = TimeSpan.FromSeconds(0.1);

/// <summary>
/// The state of the injector. Determines it's attack behavior. Containers must have the
/// right SolutionCaps to support injection/drawing. For InjectOnly injectors this should
Expand Down

0 comments on commit 52fcc6a

Please sign in to comment.