Files
OldThink/Content.Server/Medical/VomitSystem.cs

100 lines
4.5 KiB
C#
Raw Normal View History

2022-05-23 19:03:27 -04:00
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Server.Chemistry.Containers.EntitySystems;
2023-05-16 13:26:12 +10:00
using Content.Server.Fluids.EntitySystems;
using Content.Server.Forensics;
2022-05-23 19:03:27 -04:00
using Content.Server.Popups;
using Content.Server.Stunnable;
2023-05-16 13:26:12 +10:00
using Content.Shared.Chemistry.Components;
using Content.Shared.IdentityManagement;
2023-04-02 22:42:30 -04:00
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.StatusEffect;
using Robust.Server.Audio;
2022-05-23 19:03:27 -04:00
using Robust.Shared.Audio;
2023-05-16 13:26:12 +10:00
using Robust.Shared.Prototypes;
2022-05-23 19:03:27 -04:00
namespace Content.Server.Medical
{
public sealed class VomitSystem : EntitySystem
{
2023-05-16 13:26:12 +10:00
[Dependency] private readonly IPrototypeManager _proto = default!;
2023-04-02 22:42:30 -04:00
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly BodySystem _body = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly PopupSystem _popup = default!;
2023-05-16 13:26:12 +10:00
[Dependency] private readonly PuddleSystem _puddle = default!;
2023-04-02 22:42:30 -04:00
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly StunSystem _stun = default!;
[Dependency] private readonly ThirstSystem _thirst = default!;
[Dependency] private readonly ForensicsSystem _forensics = default!;
2022-05-23 19:03:27 -04:00
/// <summary>
/// Make an entity vomit, if they have a stomach.
/// </summary>
public void Vomit(EntityUid uid, float thirstAdded = -40f, float hungerAdded = -40f)
{
// Main requirement: You have a stomach
2023-04-02 22:42:30 -04:00
var stomachList = _body.GetBodyOrganComponents<StomachComponent>(uid);
2022-05-23 19:03:27 -04:00
if (stomachList.Count == 0)
return;
2023-04-02 22:42:30 -04:00
// Vomiting makes you hungrier and thirstier
2022-05-23 19:03:27 -04:00
if (TryComp<HungerComponent>(uid, out var hunger))
2023-04-02 22:42:30 -04:00
_hunger.ModifyHunger(uid, hungerAdded, hunger);
2022-05-23 19:03:27 -04:00
if (TryComp<ThirstComponent>(uid, out var thirst))
_thirst.ModifyThirst(uid, thirst, thirstAdded);
2022-05-23 19:03:27 -04:00
// It fully empties the stomach, this amount from the chem stream is relatively small
2023-04-02 22:42:30 -04:00
var solutionSize = (MathF.Abs(thirstAdded) + MathF.Abs(hungerAdded)) / 6;
2022-05-23 19:03:27 -04:00
// Apply a bit of slowdown
if (TryComp<StatusEffectsComponent>(uid, out var status))
2023-04-02 22:42:30 -04:00
_stun.TrySlowdown(uid, TimeSpan.FromSeconds(solutionSize), true, 0.5f, 0.5f, status);
2022-05-23 19:03:27 -04:00
2023-05-16 13:26:12 +10:00
// TODO: Need decals
var solution = new Solution();
2022-05-23 19:03:27 -04:00
// Empty the stomach out into it
foreach (var stomach in stomachList)
{
if (_solutionContainer.ResolveSolution(stomach.Comp.Owner, StomachSystem.DefaultSolutionName, ref stomach.Comp.Solution, out var sol))
2023-05-16 13:26:12 +10:00
{
solution.AddSolution(sol, _proto);
sol.RemoveAllSolution();
_solutionContainer.UpdateChemicals(stomach.Comp.Solution.Value);
2023-05-16 13:26:12 +10:00
}
2022-05-23 19:03:27 -04:00
}
// Adds a tiny amount of the chem stream from earlier along with vomit
2022-05-23 19:03:27 -04:00
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("Vomit", vomitAmount); // TODO: Dehardcode vomit prototype
2022-05-23 19:03:27 -04:00
}
2023-05-16 13:26:12 +10:00
if (_puddle.TrySpillAt(uid, solution, out var puddle, false))
{
_forensics.TransferDna(puddle, uid, false);
2023-05-16 13:26:12 +10:00
}
// Force sound to play as spill doesn't work if solution is empty.
_audio.PlayPvs("/Audio/Effects/Fluids/splat.ogg", uid, AudioParams.Default.WithVariation(0.2f).WithVolume(-4f));
_popup.PopupEntity(Loc.GetString("disease-vomit", ("person", Identity.Entity(uid, EntityManager))), uid);
2022-05-23 19:03:27 -04:00
}
}
}