Files
tbd-station-14/Content.Server/Medical/VomitSystem.cs
M4rchy-S ca29e0a166 Fix radiation vomit for dead mobs (#40020)
* Fix Radiation Vomit for dead mobs

* Update Content.Server/Destructible/Thresholds/Behaviors/VomitBehavior.cs

Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com>

* Fix Radiation Vomit for dead mobs

* Fix Radiation Vomit system for dead mobs

* refactors

* Adding mobStateSystem for validation

* refactor

* Unrelated cleanup

---------

Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com>
Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-09-01 17:07:37 -07:00

113 lines
5.2 KiB
C#

using Content.Server.Body.Systems;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Forensics;
using Content.Server.Popups;
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.IdentityManagement;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Robust.Server.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
namespace Content.Server.Medical
{
public sealed class VomitSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
[Dependency] private readonly BodySystem _body = default!;
[Dependency] private readonly ForensicsSystem _forensics = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly MobStateSystem _mobstate = default!;
[Dependency] private readonly MovementModStatusSystem _movementMod = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly ThirstSystem _thirst = default!;
private static readonly ProtoId<SoundCollectionPrototype> VomitCollection = "Vomit";
private readonly SoundSpecifier _vomitSound = new SoundCollectionSpecifier(VomitCollection,
AudioParams.Default.WithVariation(0.2f).WithVolume(-4f));
/// <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)
{
// Main requirement: You have a stomach
var stomachList = _body.GetBodyOrganEntityComps<StomachComponent>(uid);
if (stomachList.Count == 0)
return;
// Vomit only if entity is alive
// Ignore condition if force was set to true
if (!force && _mobstate.IsDead(uid))
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);
// TODO: Need decals
var solution = new Solution();
// 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))
{
solution.AddSolution(sol, _proto);
sol.RemoveAllSolution();
_solutionContainer.UpdateChemicals(stomach.Comp1.Solution.Value);
}
}
// Adds a tiny amount of the chem stream from earlier along with vomit
if (TryComp<BloodstreamComponent>(uid, out var bloodStream))
{
const float chemMultiplier = 0.1f;
var vomitAmount = solutionSize;
// Takes 10% of the chemicals removed from the chem stream
if (_solutionContainer.ResolveSolution(uid, bloodStream.ChemicalSolutionName, ref bloodStream.ChemicalSolution))
{
var vomitChemstreamAmount = _solutionContainer.SplitSolution(bloodStream.ChemicalSolution.Value, vomitAmount);
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("Vomit", _bloodstream.GetEntityBloodData(uid)), vomitAmount); // TODO: Dehardcode vomit prototype
}
if (_puddle.TrySpillAt(uid, solution, out var puddle, false))
{
_forensics.TransferDna(puddle, uid, false);
}
// 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);
}
}
}