From: blueDev2 <89804215+blueDev2@users.noreply.github.com> Date: Thu, 30 May 2024 04:18:07 +0000 (-0400) Subject: Fixed hypo and injector entities going into disposal units (#28317) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=3efd7559b02105a5b1266fc30106b5dd5ca2aa79;p=space-station-14.git Fixed hypo and injector entities going into disposal units (#28317) --- diff --git a/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs b/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs index 56cc0f9670..7b70497c7d 100644 --- a/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs +++ b/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs @@ -35,16 +35,16 @@ public sealed class HypospraySystem : SharedHypospraySystem SubscribeLocalEvent(OnUseInHand); } - private void UseHypospray(Entity entity, EntityUid target, EntityUid user) + private bool TryUseHypospray(Entity entity, EntityUid target, EntityUid user) { // if target is ineligible but is a container, try to draw from the container if (!EligibleEntity(target, EntityManager, entity) && _solutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _)) { - TryDraw(entity, target, drawableSolution.Value, user); + return TryDraw(entity, target, drawableSolution.Value, user); } - TryDoInject(entity, target, user); + return TryDoInject(entity, target, user); } private void OnUseInHand(Entity entity, ref UseInHandEvent args) @@ -52,8 +52,7 @@ public sealed class HypospraySystem : SharedHypospraySystem if (args.Handled) return; - TryDoInject(entity, args.User, args.User); - args.Handled = true; + args.Handled = TryDoInject(entity, args.User, args.User); } public void OnAfterInteract(Entity entity, ref AfterInteractEvent args) @@ -61,8 +60,7 @@ public sealed class HypospraySystem : SharedHypospraySystem if (args.Handled || !args.CanReach || args.Target == null) return; - UseHypospray(entity, args.Target.Value, args.User); - args.Handled = true; + args.Handled = TryUseHypospray(entity, args.Target.Value, args.User); } public void OnAttack(Entity entity, ref MeleeHitEvent args) @@ -150,12 +148,12 @@ public sealed class HypospraySystem : SharedHypospraySystem return true; } - private void TryDraw(Entity entity, Entity target, Entity targetSolution, EntityUid user) + private bool TryDraw(Entity entity, Entity target, Entity targetSolution, EntityUid user) { if (!_solutionContainers.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution) || solution.AvailableVolume == 0) { - return; + return false; } // Get transfer amount. May be smaller than _transferAmount if not enough room, also make sure there's room in the injector @@ -168,19 +166,20 @@ public sealed class HypospraySystem : SharedHypospraySystem Loc.GetString("injector-component-target-is-empty-message", ("target", Identity.Entity(target, EntityManager))), entity.Owner, user); - return; + return false; } var removedSolution = _solutionContainers.Draw(target.Owner, targetSolution, realTransferAmount); if (!_solutionContainers.TryAddSolution(soln.Value, removedSolution)) { - return; + return false; } _popup.PopupEntity(Loc.GetString("injector-component-draw-success-message", ("amount", removedSolution.Volume), ("target", Identity.Entity(target, EntityManager))), entity.Owner, user); + return true; } private bool EligibleEntity(EntityUid entity, IEntityManager entMan, HyposprayComponent component) diff --git a/Content.Server/Chemistry/EntitySystems/InjectorSystem.cs b/Content.Server/Chemistry/EntitySystems/InjectorSystem.cs index 77c8620ea4..aac171371f 100644 --- a/Content.Server/Chemistry/EntitySystems/InjectorSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/InjectorSystem.cs @@ -29,50 +29,43 @@ public sealed class InjectorSystem : SharedInjectorSystem SubscribeLocalEvent(OnInjectorAfterInteract); } - private void UseInjector(Entity injector, EntityUid target, EntityUid user) + private bool TryUseInjector(Entity injector, EntityUid target, EntityUid user) { // Handle injecting/drawing for solutions if (injector.Comp.ToggleState == InjectorToggleMode.Inject) { if (SolutionContainers.TryGetInjectableSolution(target, out var injectableSolution, out _)) - { - TryInject(injector, target, injectableSolution.Value, user, false); - } - else if (SolutionContainers.TryGetRefillableSolution(target, out var refillableSolution, out _)) - { - TryInject(injector, target, refillableSolution.Value, user, true); - } - else if (TryComp(target, out var bloodstream)) - { - TryInjectIntoBloodstream(injector, (target, bloodstream), user); - } - else - { - Popup.PopupEntity(Loc.GetString("injector-component-cannot-transfer-message", - ("target", Identity.Entity(target, EntityManager))), injector, user); - } + return TryInject(injector, target, injectableSolution.Value, user, false); + + if (SolutionContainers.TryGetRefillableSolution(target, out var refillableSolution, out _)) + return TryInject(injector, target, refillableSolution.Value, user, true); + + if (TryComp(target, out var bloodstream)) + return TryInjectIntoBloodstream(injector, (target, bloodstream), user); + + Popup.PopupEntity(Loc.GetString("injector-component-cannot-transfer-message", + ("target", Identity.Entity(target, EntityManager))), injector, user); + return false; } - else if (injector.Comp.ToggleState == InjectorToggleMode.Draw) + + if (injector.Comp.ToggleState == InjectorToggleMode.Draw) { // Draw from a bloodstream, if the target has that if (TryComp(target, out var stream) && SolutionContainers.ResolveSolution(target, stream.BloodSolutionName, ref stream.BloodSolution)) { - TryDraw(injector, (target, stream), stream.BloodSolution.Value, user); - return; + return TryDraw(injector, (target, stream), stream.BloodSolution.Value, user); } // Draw from an object (food, beaker, etc) if (SolutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _)) - { - TryDraw(injector, target, drawableSolution.Value, user); - } - else - { - Popup.PopupEntity(Loc.GetString("injector-component-cannot-draw-message", - ("target", Identity.Entity(target, EntityManager))), injector.Owner, user); - } + return TryDraw(injector, target, drawableSolution.Value, user); + + Popup.PopupEntity(Loc.GetString("injector-component-cannot-draw-message", + ("target", Identity.Entity(target, EntityManager))), injector.Owner, user); + return false; } + return false; } private void OnInjectDoAfter(Entity entity, ref InjectorDoAfterEvent args) @@ -80,8 +73,7 @@ public sealed class InjectorSystem : SharedInjectorSystem if (args.Cancelled || args.Handled || args.Args.Target == null) return; - UseInjector(entity, args.Args.Target.Value, args.Args.User); - args.Handled = true; + args.Handled = TryUseInjector(entity, args.Args.Target.Value, args.Args.User); } private void OnInjectorAfterInteract(Entity entity, ref AfterInteractEvent args) @@ -105,8 +97,7 @@ public sealed class InjectorSystem : SharedInjectorSystem return; } - UseInjector(entity, target, args.User); - args.Handled = true; + args.Handled = TryUseInjector(entity, target, args.User); } /// @@ -214,7 +205,7 @@ public sealed class InjectorSystem : SharedInjectorSystem }); } - private void TryInjectIntoBloodstream(Entity injector, Entity target, + private bool TryInjectIntoBloodstream(Entity injector, Entity target, EntityUid user) { // Get transfer amount. May be smaller than _transferAmount if not enough room @@ -224,7 +215,7 @@ public sealed class InjectorSystem : SharedInjectorSystem Popup.PopupEntity( Loc.GetString("injector-component-cannot-inject-message", ("target", Identity.Entity(target, EntityManager))), injector.Owner, user); - return; + return false; } var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, chemSolution.AvailableVolume); @@ -233,7 +224,7 @@ public sealed class InjectorSystem : SharedInjectorSystem Popup.PopupEntity( Loc.GetString("injector-component-cannot-inject-message", ("target", Identity.Entity(target, EntityManager))), injector.Owner, user); - return; + return false; } // Move units from attackSolution to targetSolution @@ -249,14 +240,15 @@ public sealed class InjectorSystem : SharedInjectorSystem Dirty(injector); AfterInject(injector, target); + return true; } - private void TryInject(Entity injector, EntityUid targetEntity, + private bool TryInject(Entity injector, EntityUid targetEntity, Entity targetSolution, EntityUid user, bool asRefill) { if (!SolutionContainers.TryGetSolution(injector.Owner, injector.Comp.SolutionName, out var soln, out var solution) || solution.Volume == 0) - return; + return false; // Get transfer amount. May be smaller than _transferAmount if not enough room var realTransferAmount = @@ -268,7 +260,7 @@ public sealed class InjectorSystem : SharedInjectorSystem Loc.GetString("injector-component-target-already-full-message", ("target", Identity.Entity(targetEntity, EntityManager))), injector.Owner, user); - return; + return false; } // Move units from attackSolution to targetSolution @@ -291,6 +283,7 @@ public sealed class InjectorSystem : SharedInjectorSystem Dirty(injector); AfterInject(injector, targetEntity); + return true; } private void AfterInject(Entity injector, EntityUid target) @@ -321,13 +314,13 @@ public sealed class InjectorSystem : SharedInjectorSystem RaiseLocalEvent(target, ref ev); } - private void TryDraw(Entity injector, Entity target, + private bool TryDraw(Entity injector, Entity target, Entity targetSolution, EntityUid user) { if (!SolutionContainers.TryGetSolution(injector.Owner, injector.Comp.SolutionName, out var soln, out var solution) || solution.AvailableVolume == 0) { - return; + return false; } // Get transfer amount. May be smaller than _transferAmount if not enough room, also make sure there's room in the injector @@ -340,14 +333,14 @@ public sealed class InjectorSystem : SharedInjectorSystem Loc.GetString("injector-component-target-is-empty-message", ("target", Identity.Entity(target, EntityManager))), injector.Owner, user); - return; + return false; } // We have some snowflaked behavior for streams. if (target.Comp != null) { DrawFromBlood(injector, (target.Owner, target.Comp), soln.Value, realTransferAmount, user); - return; + return true; } // Move units from attackSolution to targetSolution @@ -355,7 +348,7 @@ public sealed class InjectorSystem : SharedInjectorSystem if (!SolutionContainers.TryAddSolution(soln.Value, removedSolution)) { - return; + return false; } Popup.PopupEntity(Loc.GetString("injector-component-draw-success-message", @@ -364,6 +357,7 @@ public sealed class InjectorSystem : SharedInjectorSystem Dirty(injector); AfterDraw(injector, target); + return true; } private void DrawFromBlood(Entity injector, Entity target,