* Removed arbitrary modifier scaling. The bleed amount is now 1-1 in units. * Added some comments to explain the blood and bleed code * added some comments * added some comments * profusely bleeding message scales with max bleed rate * Added some comments * Added some comments (tm) * Halved the speed bleed rate heals. * Changed the wording of a comment to make the function of the values more clear * Changed bleed rate values, made heat heal more bleed rate * doubled crit chance, since damage types were reduced * Made iron restore more blood, 2->4u per 1u * Starting to add the blood pack * add bloodlevel to healingcomponent * Created code support in the healing system for restoring blood * first test of blood pack prototype * More pack testing, and defining the yml stack * yml syntax fix * adds bloodpack tag * Successfully added the item, but the effect and deletion after using the item is not working yet. * the blood regen worksgit add -A! * blood pack is entirely functioning * Removed bleed rate healing from brute pack * Comment correction * I tried * Removed bleed stats from corrupted corgi, they inherit same stats from basemob * Removed bleed stats from xeno, they inherit same stats from a base mob * Removed bleed stats from diona, they inherit same stats from a base mob * Removed bleed stats from slimes, they inherit same stats from a base mob * All mobs now heal bloodloss damage at a rate of 1 instead of 0.25 when healthy * The cautery now closes bleed wounds * Nerf blood pack bleed rate heal * Added 2 blood packs to medicine locker * Added 2 blood packs to wall medicine locker * Minor YML fix to chemistry locker, no changes in game * Added tag to medical belt for blood pack, added 2 blood packs to medical belt * Added 1 gauze to medical belt * 5 blood packs addded to nanomed plus * nanomed inventory change * 2 blood packs added to medical supplies crate from cargo * Moved 1 gauze from med kit to advanced med kit * Moved 1 tricord pill from advanced med kit to basic med kit * added 2 ointment to burn kit * Moved ina syringe from burn treatment to oxygen kit * Removed one gauze from brute kit * Added one bloodpack to brute med kit * Moved tranex acid syringe from advanced first aid to brute kit * Poison medipen moved from advanced first aid kit to toxin kit * Removed health analyzer from advanced first aid kit * removed one brute pack from advanced aid kit * added one ointment to advanced aid kit * Added one blood pack to advanced aid kit * Added 2 blood packs to combat med kit * Starting with adding the license for the tg sprite * Adds the blood pack sprite and meta.json code * I forgor to actually code the sprite in * Advanced med kit missing one blood pack * Replaced tricord pill with emergency medipen in cobat kit * Removed emergency pen from combat kit, there's no space for it * Revert "I tried" This reverts commit 94c2e28df3200993d3f09b72ecabc838ea5ae5c0. * Trying to fix yml test fail * Try again * attempt number 3 * Restock crate price was too low * fixing merge conflict without making a HUGE mess this time * ??? * again * again * Can I add the newline now maybe??? * Revert "Can I add the newline now maybe???" This reverts commit 22d26706a65a24633f7da1dea6315012e2d3ac6f. * Adds the doafter fix code from Keron to the blood level healing * minor typo fix * Feedback from Emisse and sloth; Removed chance based feedback on cauterizing * comment fix
366 lines
16 KiB
C#
366 lines
16 KiB
C#
using Content.Server.Body.Components;
|
|
using Content.Server.Chemistry.EntitySystems;
|
|
using Content.Server.Chemistry.ReactionEffects;
|
|
using Content.Server.Fluids.EntitySystems;
|
|
using Content.Server.Forensics;
|
|
using Content.Server.HealthExaminable;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Reaction;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Damage.Prototypes;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Drunk;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Rejuvenate;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Body.Systems;
|
|
|
|
public sealed class BloodstreamSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
|
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
[Dependency] private readonly AudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedDrunkSystem _drunkSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BloodstreamComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<BloodstreamComponent, DamageChangedEvent>(OnDamageChanged);
|
|
SubscribeLocalEvent<BloodstreamComponent, HealthBeingExaminedEvent>(OnHealthBeingExamined);
|
|
SubscribeLocalEvent<BloodstreamComponent, BeingGibbedEvent>(OnBeingGibbed);
|
|
SubscribeLocalEvent<BloodstreamComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
|
|
SubscribeLocalEvent<BloodstreamComponent, ReactionAttemptEvent>(OnReactionAttempt);
|
|
SubscribeLocalEvent<BloodstreamComponent, RejuvenateEvent>(OnRejuvenate);
|
|
}
|
|
|
|
private void OnReactionAttempt(EntityUid uid, BloodstreamComponent component, ReactionAttemptEvent args)
|
|
{
|
|
if (args.Solution.Name != BloodstreamComponent.DefaultBloodSolutionName
|
|
&& args.Solution.Name != BloodstreamComponent.DefaultChemicalsSolutionName
|
|
&& args.Solution.Name != BloodstreamComponent.DefaultBloodTemporarySolutionName)
|
|
return;
|
|
|
|
foreach (var effect in args.Reaction.Effects)
|
|
{
|
|
switch (effect)
|
|
{
|
|
case CreateEntityReactionEffect: // Prevent entities from spawning in the bloodstream
|
|
case AreaReactionEffect: // No spontaneous smoke or foam leaking out of blood vessels.
|
|
args.Cancel();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// The area-reaction effect canceling is part of avoiding smoke-fork-bombs (create two smoke bombs, that when
|
|
// ingested by mobs create more smoke). This also used to act as a rapid chemical-purge, because all the
|
|
// reagents would get carried away by the smoke/foam. This does still work for the stomach (I guess people vomit
|
|
// up the smoke or spawned entities?).
|
|
|
|
// TODO apply organ damage instead of just blocking the reaction?
|
|
// Having cheese-clots form in your veins can't be good for you.
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<BloodstreamComponent>();
|
|
while (query.MoveNext(out var uid, out var bloodstream))
|
|
{
|
|
bloodstream.AccumulatedFrametime += frameTime;
|
|
|
|
if (bloodstream.AccumulatedFrametime < bloodstream.UpdateInterval)
|
|
continue;
|
|
|
|
bloodstream.AccumulatedFrametime -= bloodstream.UpdateInterval;
|
|
|
|
if (TryComp<MobStateComponent>(uid, out var state) && _mobStateSystem.IsDead(uid, state))
|
|
continue;
|
|
|
|
// First, let's refresh their blood if possible.
|
|
if (bloodstream.BloodSolution.Volume < bloodstream.BloodSolution.MaxVolume)
|
|
TryModifyBloodLevel(uid, bloodstream.BloodRefreshAmount, bloodstream);
|
|
|
|
// Next, let's remove some blood from them according to their bleed level.
|
|
// as well as stop their bleeding to a certain extent.
|
|
if (bloodstream.BleedAmount > 0)
|
|
{
|
|
// Blood is removed from the bloodstream at a 1-1 rate with the bleed amount
|
|
TryModifyBloodLevel(uid, (-bloodstream.BleedAmount), bloodstream);
|
|
// Bleed rate is reduced by the bleed reduction amount in the bloodstream component.
|
|
TryModifyBleedAmount(uid, -bloodstream.BleedReductionAmount, bloodstream);
|
|
}
|
|
|
|
// Next, we'll deal some bloodloss damage if their blood level is below a threshold.
|
|
var bloodPercentage = GetBloodLevelPercentage(uid, bloodstream);
|
|
if (bloodPercentage < bloodstream.BloodlossThreshold)
|
|
{
|
|
// TODO use a better method for determining this.
|
|
var amt = bloodstream.BloodlossDamage / (0.1f + bloodPercentage);
|
|
|
|
_damageableSystem.TryChangeDamage(uid, amt, true, false);
|
|
|
|
// Apply dizziness as a symptom of bloodloss.
|
|
// So, threshold is 0.9, you have 0.85 percent blood, it adds (5 * 1.05) or 5.25 seconds of drunkenness.
|
|
// So, it'd max at 1.9 by default with 0% blood.
|
|
_drunkSystem.TryApplyDrunkenness(uid, bloodstream.UpdateInterval * (1 + (bloodstream.BloodlossThreshold - bloodPercentage)), false);
|
|
}
|
|
else
|
|
{
|
|
// If they're healthy, we'll try and heal some bloodloss instead.
|
|
_damageableSystem.TryChangeDamage(uid, bloodstream.BloodlossHealDamage * bloodPercentage, true, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnComponentInit(EntityUid uid, BloodstreamComponent component, ComponentInit args)
|
|
{
|
|
component.ChemicalSolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultChemicalsSolutionName);
|
|
component.BloodSolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultBloodSolutionName);
|
|
component.BloodTemporarySolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultBloodTemporarySolutionName);
|
|
|
|
component.ChemicalSolution.MaxVolume = component.ChemicalMaxVolume;
|
|
component.BloodSolution.MaxVolume = component.BloodMaxVolume;
|
|
component.BloodTemporarySolution.MaxVolume = component.BleedPuddleThreshold * 4; // give some leeway, for chemstream as well
|
|
|
|
// Fill blood solution with BLOOD
|
|
_solutionContainerSystem.TryAddReagent(uid, component.BloodSolution, component.BloodReagent,
|
|
component.BloodMaxVolume, out _);
|
|
}
|
|
|
|
private void OnDamageChanged(EntityUid uid, BloodstreamComponent component, DamageChangedEvent args)
|
|
{
|
|
if (args.DamageDelta is null)
|
|
return;
|
|
|
|
// definitely don't make them bleed if they got healed
|
|
if (!args.DamageIncreased)
|
|
return;
|
|
|
|
// TODO probably cache this or something. humans get hurt a lot
|
|
if (!_prototypeManager.TryIndex<DamageModifierSetPrototype>(component.DamageBleedModifiers, out var modifiers))
|
|
return;
|
|
|
|
var bloodloss = DamageSpecifier.ApplyModifierSet(args.DamageDelta, modifiers);
|
|
|
|
if (bloodloss.Empty)
|
|
return;
|
|
|
|
// Does the calculation of how much bleed rate should be added/removed, then applies it
|
|
var oldBleedAmount = component.BleedAmount;
|
|
var total = bloodloss.Total;
|
|
var totalFloat = total.Float();
|
|
TryModifyBleedAmount(uid, totalFloat, component);
|
|
|
|
/// <summary>
|
|
/// Critical hit. Causes target to lose blood, using the bleed rate modifier of the weapon, currently divided by 5
|
|
/// The crit chance is currently the bleed rate modifier divided by 25.
|
|
/// Higher damage weapons have a higher chance to crit!
|
|
/// </summary>
|
|
var prob = Math.Clamp(totalFloat / 25, 0, 1);
|
|
if (totalFloat > 0 && _robustRandom.Prob(prob))
|
|
{
|
|
TryModifyBloodLevel(uid, (-total) / 5, component);
|
|
_audio.PlayPvs(component.InstantBloodSound, uid);
|
|
}
|
|
|
|
// Heat damage will cauterize, causing the bleed rate to be reduced.
|
|
else if (totalFloat < 0 && oldBleedAmount > 0)
|
|
{
|
|
// Magically, this damage has healed some bleeding, likely
|
|
// because it's burn damage that cauterized their wounds.
|
|
|
|
// We'll play a special sound and popup for feedback.
|
|
_audio.PlayPvs(component.BloodHealedSound, uid);
|
|
_popupSystem.PopupEntity(Loc.GetString("bloodstream-component-wounds-cauterized"), uid,
|
|
uid, PopupType.Medium);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Shows text on health examine, based on bleed rate and blood level.
|
|
/// </summary>
|
|
private void OnHealthBeingExamined(EntityUid uid, BloodstreamComponent component, HealthBeingExaminedEvent args)
|
|
{
|
|
// Shows profusely bleeding at half the max bleed rate.
|
|
if (component.BleedAmount > component.MaxBleedAmount / 2)
|
|
{
|
|
args.Message.PushNewline();
|
|
args.Message.AddMarkup(Loc.GetString("bloodstream-component-profusely-bleeding", ("target", Identity.Entity(uid, EntityManager))));
|
|
}
|
|
// Shows bleeding message when bleeding, but less than profusely.
|
|
else if (component.BleedAmount > 0)
|
|
{
|
|
args.Message.PushNewline();
|
|
args.Message.AddMarkup(Loc.GetString("bloodstream-component-bleeding", ("target", Identity.Entity(uid, EntityManager))));
|
|
}
|
|
|
|
// If the mob's blood level is below the damage threshhold, the pale message is added.
|
|
if (GetBloodLevelPercentage(uid, component) < component.BloodlossThreshold)
|
|
{
|
|
args.Message.PushNewline();
|
|
args.Message.AddMarkup(Loc.GetString("bloodstream-component-looks-pale", ("target", Identity.Entity(uid, EntityManager))));
|
|
}
|
|
}
|
|
|
|
private void OnBeingGibbed(EntityUid uid, BloodstreamComponent component, BeingGibbedEvent args)
|
|
{
|
|
SpillAllSolutions(uid, component);
|
|
}
|
|
|
|
private void OnApplyMetabolicMultiplier(EntityUid uid, BloodstreamComponent component, ApplyMetabolicMultiplierEvent args)
|
|
{
|
|
if (args.Apply)
|
|
{
|
|
component.UpdateInterval *= args.Multiplier;
|
|
return;
|
|
}
|
|
component.UpdateInterval /= args.Multiplier;
|
|
// Reset the accumulator properly
|
|
if (component.AccumulatedFrametime >= component.UpdateInterval)
|
|
component.AccumulatedFrametime = component.UpdateInterval;
|
|
}
|
|
|
|
private void OnRejuvenate(EntityUid uid, BloodstreamComponent component, RejuvenateEvent args)
|
|
{
|
|
TryModifyBleedAmount(uid, -component.BleedAmount, component);
|
|
TryModifyBloodLevel(uid, component.BloodSolution.AvailableVolume, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to transfer provided solution to internal solution.
|
|
/// </summary>
|
|
public bool TryAddToChemicals(EntityUid uid, Solution solution, BloodstreamComponent? component=null)
|
|
{
|
|
if (!Resolve(uid, ref component, false))
|
|
return false;
|
|
|
|
return _solutionContainerSystem.TryAddSolution(uid, component.ChemicalSolution, solution);
|
|
}
|
|
|
|
public bool FlushChemicals(EntityUid uid, string excludedReagentID, FixedPoint2 quantity, BloodstreamComponent? component = null) {
|
|
if (!Resolve(uid, ref component, false))
|
|
return false;
|
|
|
|
for (var i = component.ChemicalSolution.Contents.Count - 1; i >= 0; i--)
|
|
{
|
|
var (reagentId, _) = component.ChemicalSolution.Contents[i];
|
|
if (reagentId != excludedReagentID)
|
|
{
|
|
_solutionContainerSystem.TryRemoveReagent(uid, component.ChemicalSolution, reagentId, quantity);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public float GetBloodLevelPercentage(EntityUid uid, BloodstreamComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return 0.0f;
|
|
|
|
return component.BloodSolution.FillFraction;
|
|
}
|
|
|
|
public void SetBloodLossThreshold(EntityUid uid, float threshold, BloodstreamComponent? comp = null)
|
|
{
|
|
if (!Resolve(uid, ref comp))
|
|
return;
|
|
|
|
comp.BloodlossThreshold = threshold;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to modify the blood level of this entity directly.
|
|
/// </summary>
|
|
public bool TryModifyBloodLevel(EntityUid uid, FixedPoint2 amount, BloodstreamComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component, false))
|
|
return false;
|
|
|
|
if (amount >= 0)
|
|
return _solutionContainerSystem.TryAddReagent(uid, component.BloodSolution, component.BloodReagent, amount, out _);
|
|
|
|
// Removal is more involved,
|
|
// since we also wanna handle moving it to the temporary solution
|
|
// and then spilling it if necessary.
|
|
var newSol = component.BloodSolution.SplitSolution(-amount);
|
|
component.BloodTemporarySolution.AddSolution(newSol, _prototypeManager);
|
|
|
|
if (component.BloodTemporarySolution.Volume > component.BleedPuddleThreshold)
|
|
{
|
|
// Pass some of the chemstream into the spilled blood.
|
|
var temp = component.ChemicalSolution.SplitSolution(component.BloodTemporarySolution.Volume / 10);
|
|
component.BloodTemporarySolution.AddSolution(temp, _prototypeManager);
|
|
var puddle = _spillableSystem.SpillAt(uid, component.BloodTemporarySolution, "PuddleBlood", false);
|
|
if (puddle != null)
|
|
{
|
|
var comp = EnsureComp<ForensicsComponent>(puddle.Owner); //TODO: Get rid of .Owner
|
|
if (TryComp<DnaComponent>(uid, out var dna))
|
|
comp.DNAs.Add(dna.DNA);
|
|
}
|
|
|
|
component.BloodTemporarySolution.RemoveAllSolution();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to make an entity bleed more or less
|
|
/// </summary>
|
|
public bool TryModifyBleedAmount(EntityUid uid, float amount, BloodstreamComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component, false))
|
|
return false;
|
|
|
|
component.BleedAmount += amount;
|
|
component.BleedAmount = Math.Clamp(component.BleedAmount, 0, component.MaxBleedAmount);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// BLOOD FOR THE BLOOD GOD
|
|
/// </summary>
|
|
public void SpillAllSolutions(EntityUid uid, BloodstreamComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
var max = component.BloodSolution.MaxVolume + component.BloodTemporarySolution.MaxVolume +
|
|
component.ChemicalSolution.MaxVolume;
|
|
var tempSol = new Solution() { MaxVolume = max };
|
|
|
|
tempSol.AddSolution(component.BloodSolution, _prototypeManager);
|
|
component.BloodSolution.RemoveAllSolution();
|
|
tempSol.AddSolution(component.BloodTemporarySolution, _prototypeManager);
|
|
component.BloodTemporarySolution.RemoveAllSolution();
|
|
tempSol.AddSolution(component.ChemicalSolution, _prototypeManager);
|
|
component.ChemicalSolution.RemoveAllSolution();
|
|
var puddle = _spillableSystem.SpillAt(uid, tempSol, "PuddleBlood", true);
|
|
|
|
if (puddle != null)
|
|
{
|
|
var comp = EnsureComp<ForensicsComponent>(puddle.Owner); //TODO: Get rid of .Owner
|
|
if (TryComp<DnaComponent>(uid, out var dna))
|
|
comp.DNAs.Add(dna.DNA);
|
|
}
|
|
}
|
|
}
|