Files
ss14-wega/Content.Shared/Medical/VomitSystem.cs
Nikovnik 0e76d4e5ed Metabolizing bloodstream (#35071)
* merged chemical into bloodstream

* changed injectable to bloodstream

* separated bleeding and direct blood removal

* removed blood gain from protein

* reduced blood gain from saline

* rejuvenating fills to reference volume

* fixed blood regulation

* red mead requires stirring to make

* reverted accidental line deletion

* cleared the skeletons from the closet

* additional routing

* field rename for xeno

* removed mention of chemstream and field rename for asteroid mobs

* minor optimizations

* Revert "reduced blood gain from saline"

This reverts commit de26fd1c0d99f3019fe7dd1451a50230cc90f058.

* Revert "removed blood gain from protein"

This reverts commit 7a1648caf39fe26406db73c2a5afa389b82c612f.

* removed unused component fetch

* dead check mini refactor

* eventized blood exclusion

* quick fix

* Pain

* Commit of doom

* COMMIT

* renamed bloodMaxFactor to MaxVolumeFactor

* addressed floating point error

* returned vomiting chemicals

* blood reagent always skips the flush

* no need to mention blood reagent

* fixed passing blood flush

* adadsafasfasfassfasf

* whoops

* merge fixed injectors

* Revert "adadsafasfasfassfasf"

This reverts commit 0a5313a68dd6484d36d28d08930c76851b72ae38.

* simplify reagent removal

* enabled foreign blood transfusion

* Revert "COMMIT"

This reverts commit 19abd679cd7761ebd47bb242bd644176a3006a42.

* simplified reagent removal when modifying blood level

* removed misleading coment since the changes

* documented MetabolismExclusionEvent

* fixed negative negative modification of blood level

* fixed hypervolemia not normalizing

* constrainted blood modification

* returned bloodpack stop on fully healed

* forgot to stage this

* band aid for diona blood

* swapping GetReagent with GetPrototype

* optimize blood filtering

* multiplicative multi reagent blood level calculation

* removed unused stuff

* optimized blood calculation a tiny bit

* added per reagent blood regulation

* optimized (referenceVolume + bloodReagents) into referenceSolution

* polished coded to proper function

* forgot to stage rootable system change

* clean up, unnecessary GetBloodLevel call

* rename method name to TryAddToBloodstream instead of Chemicals

* placed overfill safety

* cleanup and final touches

* final touch

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-12-17 19:21:16 +00:00

144 lines
5.7 KiB
C#

using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Fluids;
using Content.Shared.Forensics.Systems;
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
namespace Content.Shared.Medical;
public sealed class VomitSystem : EntitySystem
{
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly MovementModStatusSystem _movementMod = default!;
[Dependency] private readonly ThirstSystem _thirst = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedBloodstreamSystem _bloodstream = default!;
[Dependency] private readonly SharedBodySystem _body = default!;
[Dependency] private readonly SharedForensicsSystem _forensics = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPuddleSystem _puddle = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BodyComponent, TryVomitEvent>(TryBodyVomitSolution);
}
private const float ChemMultiplier = 0.1f;
private static readonly ProtoId<SoundCollectionPrototype> VomitCollection = "Vomit";
private static readonly ProtoId<ReagentPrototype> VomitPrototype = "Vomit"; // TODO: Dehardcode vomit prototype
private readonly SoundSpecifier _vomitSound = new SoundCollectionSpecifier(VomitCollection,
AudioParams.Default.WithVariation(0.2f).WithVolume(-4f));
private void TryBodyVomitSolution(Entity<BodyComponent> ent, ref TryVomitEvent args)
{
if (args.Handled)
return;
// Main requirement: You have a stomach
var stomachList = _body.GetBodyOrganEntityComps<StomachComponent>((ent, null));
if (stomachList.Count == 0)
return;
// Empty the stomach out into it
foreach (var stomach in stomachList)
{
if (_solutionContainer.ResolveSolution(stomach.Owner, StomachSystem.DefaultSolutionName, ref stomach.Comp1.Solution, out var sol))
_solutionContainer.TryTransferSolution(stomach.Comp1.Solution.Value, args.Sol, sol.AvailableVolume);
}
args.Handled = true;
}
/// <summary>
/// Make an entity vomit, if they have a stomach.
/// </summary>
public void Vomit(EntityUid uid, float thirstAdded = -40f, float hungerAdded = -40f, bool force = false)
{
// Vomit only if entity is alive
// Ignore condition if force was set to true
if (!force && _mobState.IsDead(uid))
return;
// TODO: Need decals
var solution = new Solution();
var ev = new TryVomitEvent(solution, force);
RaiseLocalEvent(uid, ref ev);
if (!ev.Handled)
return;
// Vomiting makes you hungrier and thirstier
if (TryComp<HungerComponent>(uid, out var hunger))
_hunger.ModifyHunger(uid, hungerAdded, hunger);
if (TryComp<ThirstComponent>(uid, out var thirst))
_thirst.ModifyThirst(uid, thirst, thirstAdded);
// It fully empties the stomach, this amount from the chem stream is relatively small
var solutionSize = (MathF.Abs(thirstAdded) + MathF.Abs(hungerAdded)) / 6;
// Apply a bit of slowdown
_movementMod.TryUpdateMovementSpeedModDuration(uid, MovementModStatusSystem.VomitingSlowdown, TimeSpan.FromSeconds(solutionSize), 0.5f);
// Adds a tiny amount of the chem stream from earlier along with vomit
if (TryComp<BloodstreamComponent>(uid, out var bloodStream))
{
var vomitAmount = solutionSize;
// Flushes small portion of the chemicals removed from the bloodstream stream
if (_solutionContainer.ResolveSolution(uid, bloodStream.BloodSolutionName, ref bloodStream.BloodSolution))
{
var vomitChemstreamAmount = _bloodstream.FlushChemicals((uid, bloodStream), vomitAmount);
if (vomitChemstreamAmount != null)
{
vomitChemstreamAmount.ScaleSolution(ChemMultiplier);
solution.AddSolution(vomitChemstreamAmount, _proto);
vomitAmount -= (float)vomitChemstreamAmount.Volume;
}
}
// Makes a vomit solution the size of 90% of the chemicals removed from the chemstream
solution.AddReagent(new ReagentId(VomitPrototype, _bloodstream.GetEntityBloodData(uid)), vomitAmount);
}
if (_puddle.TrySpillAt(uid, solution, out var puddle, false))
{
_forensics.TransferDna(puddle, uid, false);
}
if (!_netManager.IsServer)
return;
// Force sound to play as spill doesn't work if solution is empty.
_audio.PlayPvs(_vomitSound, uid);
_popup.PopupEntity(Loc.GetString("disease-vomit", ("person", Identity.Entity(uid, EntityManager))), uid);
}
}
[ByRefEvent]
public record struct TryVomitEvent(Solution Sol, bool Forced = false, bool Handled = false);