Fixed hypo and injector entities going into disposal units (#28317)

This commit is contained in:
blueDev2
2024-05-30 00:18:07 -04:00
committed by GitHub
parent 620ce8fb2a
commit 3efd7559b0
2 changed files with 47 additions and 54 deletions

View File

@@ -35,16 +35,16 @@ public sealed class HypospraySystem : SharedHypospraySystem
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
}
private void UseHypospray(Entity<HyposprayComponent> entity, EntityUid target, EntityUid user)
private bool TryUseHypospray(Entity<HyposprayComponent> 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<HyposprayComponent> 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<HyposprayComponent> 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<HyposprayComponent> entity, ref MeleeHitEvent args)
@@ -150,12 +148,12 @@ public sealed class HypospraySystem : SharedHypospraySystem
return true;
}
private void TryDraw(Entity<HyposprayComponent> entity, Entity<BloodstreamComponent?> target, Entity<SolutionComponent> targetSolution, EntityUid user)
private bool TryDraw(Entity<HyposprayComponent> entity, Entity<BloodstreamComponent?> target, Entity<SolutionComponent> 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)

View File

@@ -29,50 +29,43 @@ public sealed class InjectorSystem : SharedInjectorSystem
SubscribeLocalEvent<InjectorComponent, AfterInteractEvent>(OnInjectorAfterInteract);
}
private void UseInjector(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
private bool TryUseInjector(Entity<InjectorComponent> 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<BloodstreamComponent>(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<BloodstreamComponent>(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<BloodstreamComponent>(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<InjectorComponent> 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<InjectorComponent> 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);
}
/// <summary>
@@ -214,7 +205,7 @@ public sealed class InjectorSystem : SharedInjectorSystem
});
}
private void TryInjectIntoBloodstream(Entity<InjectorComponent> injector, Entity<BloodstreamComponent> target,
private bool TryInjectIntoBloodstream(Entity<InjectorComponent> injector, Entity<BloodstreamComponent> 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<InjectorComponent> injector, EntityUid targetEntity,
private bool TryInject(Entity<InjectorComponent> injector, EntityUid targetEntity,
Entity<SolutionComponent> 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<InjectorComponent> injector, EntityUid target)
@@ -321,13 +314,13 @@ public sealed class InjectorSystem : SharedInjectorSystem
RaiseLocalEvent(target, ref ev);
}
private void TryDraw(Entity<InjectorComponent> injector, Entity<BloodstreamComponent?> target,
private bool TryDraw(Entity<InjectorComponent> injector, Entity<BloodstreamComponent?> target,
Entity<SolutionComponent> 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<InjectorComponent> injector, Entity<BloodstreamComponent> target,