From 8d03e7a2bb9e8765604520f873654256ceec5b15 Mon Sep 17 00:00:00 2001 From: Whatstone <166147148+whatston3@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:16:07 -0400 Subject: [PATCH 1/2] Adds a doafter to chemical medipens (#2121) * Adds a doafter to chemical medipens * Merge changes from upstream #30704 * Update hypospray.yml * Update hypospray.yml --------- Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> Co-authored-by: Dvir --- .../EntitySystems/HypospraySystem.cs | 96 ++++++++++++++++--- .../Components/HyposprayComponent.cs | 22 +++++ .../Objects/Specific/Medical/hypospray.yml | 2 + 3 files changed, 109 insertions(+), 11 deletions(-) diff --git a/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs b/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs index 9b78e81aa00..dfeb1f2cea2 100644 --- a/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs +++ b/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs @@ -17,6 +17,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Robust.Server.Audio; +using Content.Shared.DoAfter; // Frontier namespace Content.Server.Chemistry.EntitySystems; @@ -24,6 +25,7 @@ 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() { @@ -32,8 +34,19 @@ public override void Initialize() SubscribeLocalEvent(OnAfterInteract); SubscribeLocalEvent(OnAttack); SubscribeLocalEvent(OnUseInHand); + SubscribeLocalEvent(OnDoAfter); // Frontier - Upstream: #30704 - MIT } + // Frontier - Upstream: #30704 - MIT + private void OnDoAfter(Entity 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 entity, EntityUid target, EntityUid user) { // if target is ineligible but is a container, try to draw from the container @@ -43,6 +56,30 @@ private bool TryUseHypospray(Entity 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(target) || HasComp(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); } @@ -67,6 +104,9 @@ public void OnAttack(Entity entity, ref MeleeHitEvent args) if (!args.HitEntities.Any()) return; + if (entity.Comp.PreventCombatInjection) // Frontier + return; // Frontier + TryDoInject(entity, args.HitEntities.First(), args.User); } @@ -93,17 +133,25 @@ public bool TryDoInject(Entity 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); @@ -191,4 +239,30 @@ private bool EligibleEntity(EntityUid entity, IEntityManager entMan, HyposprayCo entMan.HasComponent(entity) : entMan.HasComponent(entity); } + + // Frontier: Upstream: #30704 - MIT + private bool InjectionFailureCheck(Entity entity, EntityUid target, EntityUid user, out Entity? hypoSpraySoln, out Entity? 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 } diff --git a/Content.Shared/Chemistry/Components/HyposprayComponent.cs b/Content.Shared/Chemistry/Components/HyposprayComponent.cs index 05ef84bbaf7..cd647245fd0 100644 --- a/Content.Shared/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Shared/Chemistry/Components/HyposprayComponent.cs @@ -1,3 +1,4 @@ +using Content.Shared.DoAfter; // Frontier: Upstream, #30704 - MIT using Content.Shared.FixedPoint; using Robust.Shared.GameStates; using Robust.Shared.Serialization; @@ -37,4 +38,25 @@ public sealed partial class HyposprayComponent : Component /// [DataField] public bool InjectOnly = false; + + // Frontier: Upstream, #30704 - MIT + /// + /// If set over 0, enables a doafter for the hypospray which must be completed for injection. + /// + [DataField] + public float DoAfterTime = 0f; + // End Frontier + + /// + /// Frontier: if true, object will not inject when attacking. + /// + [DataField] + public bool PreventCombatInjection; +} + +// Frontier: Upstream, #30704 - MIT +[Serializable, NetSerializable] +public sealed partial class HyposprayDoAfterEvent : SimpleDoAfterEvent +{ } +// End Frontier diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml index f1b2e4d0778..7341de8f06a 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml @@ -116,6 +116,8 @@ transferAmount: 15 onlyAffectsMobs: false injectOnly: true + preventCombatInjection: true # Frontier + doAfterTime: 2 # Frontier - type: Appearance - type: SolutionContainerVisuals maxFillLevels: 1 From 39ebbe87c681d68ee6437db7701998fdcb9c8ff2 Mon Sep 17 00:00:00 2001 From: FrontierATC Date: Wed, 2 Oct 2024 18:16:38 +0000 Subject: [PATCH 2/2] Automatic Changelog (#2121) --- Resources/Changelog/Frontier.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Resources/Changelog/Frontier.yml b/Resources/Changelog/Frontier.yml index 12f5931c728..66f4ff95158 100644 --- a/Resources/Changelog/Frontier.yml +++ b/Resources/Changelog/Frontier.yml @@ -4199,3 +4199,9 @@ 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'