Files
tbd-station-14/Content.Server/Chemistry/EntitySystems/SolutionInjectOnEventSystem.cs
pathetic meowmeow 8894eca118 Offbrand medical (#3366)
* Offbrand medical

* what if we regrade

* zombies are mostly there thats it thats a wrap xd

* here's changeling

* some bonus gut punches

* start working on the guidebook

* fix rsi and yaml lints

* my agrichem so fits

* we stay rejuvenated

* my china so laked

* debrute

* fix suicide

* fix the suicide tests

* my surgery so requires laying down

* the guidebook continues

* READ KEB PAGES

* keb vascular recoupler

* read keb medicine

* fix yaml lint

* fix the EntityRemoveConstructionGraphStep

* fix overlay init

* scalpels are not a food tool

* return of the programmer art

* my line so nieuw

* boxes deserve veins too

* mrrrp yaml

* what if we redid brain damage alerts

* bloot pressure

* kill mannitol drowsiness

* get licensed

* my read so me

* get feedbacked nerd

* fine-tune the heart stoppage conditions

* cryostasis adjustments, guidebook adjustments, fix negative strain issues

* my surgery so table

* fix heart surgery and guidebook

* medicine & defibrillator pass

* iv bags and stands

* prefills

* janet gets very sidetracked

* mostly finished iv stuff

* what if we fixed the guidebook

* halve decapoid cryostasis

* my medicines so IV

* finetune cryostasis

* less logspam

* metabolism-aware iv stands and cryopods

* give people painkillers

* yaml lint real

* fix blood build

* finish rebase

* tidy up localization

* clean up my yaml beasties...

* soft curve after exceeding maximum damage

* husks/bonedeaths

Grabbag of Offmed fixes & improvements (#3461)

* CPR moment

* Mob AI fix

* Fix brain oxygenation not updating on regeneration

* sorry gamers you cannot resist the pull

* Troll combat abilities more in softcrit

praying rn (#3467)

dont have CPR be 50% (#3468)

Make offbrand murder easier to contend with (#3473)

* e

* disrupt people in softcrit when attacking them

* ok gamers we're gaming

* forgor

Hopefully final pass before Offbrand merge (#3475)

First pass of Offbrand adjustments (#3477)

Swap blood pressure values in health analyzer (#3476)

Systolic over diastolic

Co-authored-by: Kip <32859367+kipdotnet@users.noreply.github.com>

Offbrand pass 2: Mostly bugfixes (#3480)

Fix zeds causing PVS reloads (#3482)

Offbrand pass 3: I hate surgery I hate surgery I hate surgery I (#3481)

* set up surgery ui

* test fail real

Pain/braingasps (#3487)

Offmed bundle 5 - the evil one (#3489)

* Evil cavity surgery

* les borgues

* nicotine moment

* epinephrine RNG

* legalese

* test fail real

* ok jamers cope with c4

Pass 6
2025-09-27 22:36:57 -04:00

165 lines
7.4 KiB
C#

using Content.Server.Body.Systems;
using Content.Server.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Events;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Collections;
using Robust.Shared.Prototypes;
namespace Content.Server.Chemistry.EntitySystems;
/// <summary>
/// System for handling the different inheritors of <see cref="BaseSolutionInjectOnEventComponent"/>.
/// Subscribes to relevent events and performs solution injections when they are raised.
/// </summary>
public sealed class SolutionInjectOnCollideSystem : EntitySystem
{
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly TagSystem _tag = default!;
private static readonly ProtoId<TagPrototype> HardsuitTag = "Hardsuit";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SolutionInjectOnProjectileHitComponent, ProjectileHitEvent>(HandleProjectileHit);
SubscribeLocalEvent<SolutionInjectOnEmbedComponent, EmbedEvent>(HandleEmbed);
SubscribeLocalEvent<MeleeChemicalInjectorComponent, MeleeHitEvent>(HandleMeleeHit);
SubscribeLocalEvent<SolutionInjectWhileEmbeddedComponent, InjectOverTimeEvent>(OnInjectOverTime);
}
private void HandleProjectileHit(Entity<SolutionInjectOnProjectileHitComponent> entity, ref ProjectileHitEvent args)
{
DoInjection((entity.Owner, entity.Comp), args.Target, args.Shooter);
}
private void HandleEmbed(Entity<SolutionInjectOnEmbedComponent> entity, ref EmbedEvent args)
{
DoInjection((entity.Owner, entity.Comp), args.Embedded, args.Shooter);
}
private void HandleMeleeHit(Entity<MeleeChemicalInjectorComponent> entity, ref MeleeHitEvent args)
{
// MeleeHitEvent is weird, so we have to filter to make sure we actually
// hit something and aren't just examining the weapon.
if (args.IsHit)
TryInjectTargets((entity.Owner, entity.Comp), args.HitEntities, args.User);
}
private void OnInjectOverTime(Entity<SolutionInjectWhileEmbeddedComponent> entity, ref InjectOverTimeEvent args)
{
DoInjection((entity.Owner, entity.Comp), args.EmbeddedIntoUid);
}
private void DoInjection(Entity<BaseSolutionInjectOnEventComponent> injectorEntity, EntityUid target, EntityUid? source = null)
{
TryInjectTargets(injectorEntity, [target], source);
}
/// <summary>
/// Filters <paramref name="targets"/> for valid targets and tries to inject a portion of <see cref="BaseSolutionInjectOnEventComponent.Solution"/> into
/// each valid target's bloodstream.
/// </summary>
/// <remarks>
/// Targets are invalid if any of the following are true:
/// <list type="bullet">
/// <item>The target does not have a bloodstream.</item>
/// <item><see cref="BaseSolutionInjectOnEventComponent.PierceArmor"/> is false and the target is wearing a hardsuit.</item>
/// <item><see cref="BaseSolutionInjectOnEventComponent.BlockSlots"/> is not NONE and the target has an item equipped in any of the specified slots.</item>
/// </list>
/// </remarks>
/// <returns>true if at least one target was successfully injected, otherwise false</returns>
private bool TryInjectTargets(Entity<BaseSolutionInjectOnEventComponent> injector, IReadOnlyList<EntityUid> targets, EntityUid? source = null)
{
// Make sure we have at least one target
if (targets.Count == 0)
return false;
// Get the solution to inject
if (!_solutionContainer.TryGetSolution(injector.Owner, injector.Comp.Solution, out var injectorSolution))
return false;
// Build a list of bloodstreams to inject into
var targetBloodstreams = new ValueList<Entity<BloodstreamComponent>>();
foreach (var target in targets)
{
if (Deleted(target))
continue;
// Yuck, this is way to hardcodey for my tastes
// TODO blocking injection with a hardsuit should probably done with a cancellable event or something
if (!injector.Comp.PierceArmor && _inventory.TryGetSlotEntity(target, "outerClothing", out var suit) && _tag.HasTag(suit.Value, HardsuitTag))
{
// Only show popup to attacker
if (source != null)
_popup.PopupEntity(Loc.GetString(injector.Comp.BlockedByHardsuitPopupMessage, ("weapon", injector.Owner), ("target", target)), target, source.Value, PopupType.SmallCaution);
continue;
}
// Check if the target has anything equipped in a slot that would block injection
if (injector.Comp.BlockSlots != SlotFlags.NONE)
{
var blocked = false;
var containerEnumerator = _inventory.GetSlotEnumerator(target, injector.Comp.BlockSlots);
while (containerEnumerator.MoveNext(out var container))
{
if (container.ContainedEntity != null)
{
blocked = true;
break;
}
}
if (blocked)
continue;
}
// Make sure the target has a bloodstream
if (!TryComp<BloodstreamComponent>(target, out var bloodstream))
continue;
// Checks passed; add this target's bloodstream to the list
targetBloodstreams.Add((target, bloodstream));
}
// Make sure we got at least one bloodstream
if (targetBloodstreams.Count == 0)
return false;
// Extract total needed solution from the injector
var removedSolution = _solutionContainer.SplitSolution(injectorSolution.Value, injector.Comp.TransferAmount * targetBloodstreams.Count);
// Adjust solution amount based on transfer efficiency
var solutionToInject = removedSolution.SplitSolution(removedSolution.Volume * injector.Comp.TransferEfficiency);
// Calculate how much of the adjusted solution each target will get
var volumePerBloodstream = solutionToInject.Volume * (1f / targetBloodstreams.Count);
var anySuccess = false;
foreach (var targetBloodstream in targetBloodstreams)
{
// Begin Offbrand
var beforeInject = new Content.Shared._Offbrand.Chemistry.BeforeInjectOnEventEvent { InjectionAmount = volumePerBloodstream };
RaiseLocalEvent(targetBloodstream, ref beforeInject);
if (beforeInject.InjectionAmount < 0)
continue;
// End Offbrand
// Take our portion of the adjusted solution for this target
var individualInjection = solutionToInject.SplitSolution(beforeInject.InjectionAmount); // Offbrand
// Inject our portion into the target's bloodstream
if (_bloodstream.TryAddToChemicals(targetBloodstream.AsNullable(), individualInjection))
anySuccess = true;
}
// Huzzah!
return anySuccess;
}
}