Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-station-14 into 2024-10-Syndie-Cleanbot
  • Loading branch information
whatston3 committed Oct 2, 2024
2 parents b634975 + 39ebbe8 commit 3479509
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 13 deletions.
96 changes: 85 additions & 11 deletions Content.Server/Chemistry/EntitySystems/HypospraySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Server.Audio;
using Content.Shared.DoAfter; // Frontier

namespace Content.Server.Chemistry.EntitySystems;

public sealed class HypospraySystem : SharedHypospraySystem
{
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!; // Frontier - Upstream: #30704 - MIT

public override void Initialize()
{
Expand All @@ -32,8 +34,19 @@ public override void Initialize()
SubscribeLocalEvent<HyposprayComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<HyposprayComponent, MeleeHitEvent>(OnAttack);
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<HyposprayComponent, HyposprayDoAfterEvent>(OnDoAfter); // Frontier - Upstream: #30704 - MIT
}

// Frontier - Upstream: #30704 - MIT
private void OnDoAfter(Entity<HyposprayComponent> entity, ref HyposprayDoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Args.Target == null)
return;

args.Handled = TryDoInject(entity, args.Args.Target.Value, args.Args.User);
}
// End Frontier

private bool TryUseHypospray(Entity<HyposprayComponent> entity, EntityUid target, EntityUid user)
{
// if target is ineligible but is a container, try to draw from the container
Expand All @@ -43,6 +56,30 @@ private bool TryUseHypospray(Entity<HyposprayComponent> entity, EntityUid target
return TryDraw(entity, target, drawableSolution.Value, user);
}

// Frontier - Upstream: #30704 - MIT
if (entity.Comp.DoAfterTime > 0 && target != user)
{
// Is the target a mob? If yes, use a do-after to give them time to respond.
if (HasComp<MobStateComponent>(target) || HasComp<BloodstreamComponent>(target))
{
//If the injection would fail the doAfter can be skipped at this step
if (InjectionFailureCheck(entity, target, user, out _, out _, out _, out _))
{
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, entity.Comp.DoAfterTime, new HyposprayDoAfterEvent(), entity.Owner, target: target, used: entity.Owner)
{
BreakOnMove = true,
BreakOnWeightlessMove = false,
BreakOnDamage = true,
NeedHand = true,
BreakOnHandChange = true,
//Hidden = true // Frontier: if supporting this, should be configurable
});
}
return true;
}
}
// End Frontier

return TryDoInject(entity, target, user);
}

Expand All @@ -67,6 +104,9 @@ public void OnAttack(Entity<HyposprayComponent> entity, ref MeleeHitEvent args)
if (!args.HitEntities.Any())
return;

if (entity.Comp.PreventCombatInjection) // Frontier
return; // Frontier

TryDoInject(entity, args.HitEntities.First(), args.User);
}

Expand All @@ -93,17 +133,25 @@ public bool TryDoInject(Entity<HyposprayComponent> entity, EntityUid target, Ent
target = user;
}

if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var hypoSpraySoln, out var hypoSpraySolution) || hypoSpraySolution.Volume == 0)
{
_popup.PopupEntity(Loc.GetString("hypospray-component-empty-message"), target, user);
return true;
}

if (!_solutionContainers.TryGetInjectableSolution(target, out var targetSoln, out var targetSolution))
{
_popup.PopupEntity(Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target, EntityManager))), target, user);
return false;
}
// Frontier - Upstream: #30704 - MIT
// if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var hypoSpraySoln, out var hypoSpraySolution) || hypoSpraySolution.Volume == 0)
// {
// _popup.PopupEntity(Loc.GetString("hypospray-component-empty-message"), target, user);
// return true;
// }

// if (!_solutionContainers.TryGetInjectableSolution(target, out var targetSoln, out var targetSolution))
// {
// _popup.PopupEntity(Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target, EntityManager))), target, user);
// return false;
// }

if (!InjectionFailureCheck(entity, target, user, out var hypoSpraySoln, out var targetSoln, out var targetSolution, out var returnValue)
|| hypoSpraySoln == null
|| targetSoln == null
|| targetSolution == null)
return returnValue;
// End Frontier

_popup.PopupEntity(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message", ("other", target)), target, user);

Expand Down Expand Up @@ -191,4 +239,30 @@ private bool EligibleEntity(EntityUid entity, IEntityManager entMan, HyposprayCo
entMan.HasComponent<MobStateComponent>(entity)
: entMan.HasComponent<SolutionContainerManagerComponent>(entity);
}

// Frontier: Upstream: #30704 - MIT
private bool InjectionFailureCheck(Entity<HyposprayComponent> entity, EntityUid target, EntityUid user, out Entity<SolutionComponent>? hypoSpraySoln, out Entity<SolutionComponent>? targetSoln, out Solution? targetSolution, out bool returnValue)
{
hypoSpraySoln = null;
targetSoln = null;
targetSolution = null;
returnValue = false;

if (!_solutionContainers.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out hypoSpraySoln, out var hypoSpraySolution) || hypoSpraySolution.Volume == 0)
{
_popup.PopupEntity(Loc.GetString("hypospray-component-empty-message"), target, user);
returnValue = true;
return false;
}

if (!_solutionContainers.TryGetInjectableSolution(target, out targetSoln, out targetSolution))
{
_popup.PopupEntity(Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target, EntityManager))), target, user);
returnValue = false;
return false;
}

return true;
}
// End Frontier
}
22 changes: 22 additions & 0 deletions Content.Shared/Chemistry/Components/HyposprayComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.DoAfter; // Frontier: Upstream, #30704 - MIT
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
Expand Down Expand Up @@ -37,4 +38,25 @@ public sealed partial class HyposprayComponent : Component
/// </summary>
[DataField]
public bool InjectOnly = false;

// Frontier: Upstream, #30704 - MIT
/// <summary>
/// If set over 0, enables a doafter for the hypospray which must be completed for injection.
/// </summary>
[DataField]
public float DoAfterTime = 0f;
// End Frontier

/// <summary>
/// Frontier: if true, object will not inject when attacking.
/// </summary>
[DataField]
public bool PreventCombatInjection;
}

// Frontier: Upstream, #30704 - MIT
[Serializable, NetSerializable]
public sealed partial class HyposprayDoAfterEvent : SimpleDoAfterEvent
{
}
// End Frontier
11 changes: 9 additions & 2 deletions Resources/Changelog/Frontier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4199,6 +4199,12 @@ Entries:
message: Issues with Stasis floor tiles and SMES wiring.
id: 5354
time: '2024-10-02T09:27:03.0000000+00:00'
- author: whatston3
changes:
- type: Tweak
message: Chemical medipens now have a small delay when injecting others.
id: 5355
time: '2024-10-02T18:16:07.0000000+00:00'
- author: whatston3
changes:
- type: Tweak
Expand All @@ -4209,5 +4215,6 @@ Entries:
message: >-
Composite materials like plasma glass have been reduced in value and are
not printable from the base ore processor.
id: 5355
time: '2024-10-02T12:27:03.0000000+00:00'
id: 5356
time: '2024-10-02T18:17:03.0000000+00:00'

Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
transferAmount: 15
onlyAffectsMobs: false
injectOnly: true
preventCombatInjection: true # Frontier
doAfterTime: 2 # Frontier
- type: Appearance
- type: SolutionContainerVisuals
maxFillLevels: 1
Expand Down

0 comments on commit 3479509

Please sign in to comment.