Predict healing and bloodstream (#38690)
* initial commit * reapply 38126 * fix rootable * someone missed an important minus sign here * try this * fix * fix * reenable crit hits * cleanup * fix status time dirtying * fix * camelCase
This commit is contained in:
5
Content.Client/Body/Systems/BloodStreamSystem.cs
Normal file
5
Content.Client/Body/Systems/BloodStreamSystem.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using Content.Shared.Body.Systems;
|
||||
|
||||
namespace Content.Client.Body.Systems;
|
||||
|
||||
public sealed class BloodstreamSystem : SharedBloodstreamSystem;
|
||||
@@ -273,7 +273,7 @@ public sealed partial class AdminVerbSystem
|
||||
Icon = new SpriteSpecifier.Rsi(new ("/Textures/Fluids/tomato_splat.rsi"), "puddle-1"),
|
||||
Act = () =>
|
||||
{
|
||||
_bloodstreamSystem.SpillAllSolutions(args.Target, bloodstream);
|
||||
_bloodstreamSystem.SpillAllSolutions((args.Target, bloodstream));
|
||||
var xform = Transform(args.Target);
|
||||
_popupSystem.PopupEntity(Loc.GetString("admin-smite-remove-blood-self"), args.Target,
|
||||
args.Target, PopupType.LargeCaution);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Rotting;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Physics.Components;
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.Body.Components
|
||||
{
|
||||
[RegisterComponent, Access(typeof(BloodstreamSystem), typeof(ReactionMixerSystem))]
|
||||
public sealed partial class BloodstreamComponent : Component
|
||||
{
|
||||
public static string DefaultChemicalsSolutionName = "chemicals";
|
||||
public static string DefaultBloodSolutionName = "bloodstream";
|
||||
public static string DefaultBloodTemporarySolutionName = "bloodstreamTemporary";
|
||||
|
||||
/// <summary>
|
||||
/// The next time that blood level will be updated and bloodloss damage dealt.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan NextUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// The interval at which this component updates.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(3);
|
||||
|
||||
/// <summary>
|
||||
/// How much is this entity currently bleeding?
|
||||
/// Higher numbers mean more blood lost every tick.
|
||||
///
|
||||
/// Goes down slowly over time, and items like bandages
|
||||
/// or clotting reagents can lower bleeding.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This generally corresponds to an amount of damage and can't go above 100.
|
||||
/// </remarks>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BleedAmount;
|
||||
|
||||
/// <summary>
|
||||
/// How much should bleeding be reduced every update interval?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float BleedReductionAmount = 0.33f;
|
||||
|
||||
/// <summary>
|
||||
/// How high can <see cref="BleedAmount"/> go?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float MaxBleedAmount = 10.0f;
|
||||
|
||||
/// <summary>
|
||||
/// What percentage of current blood is necessary to avoid dealing blood loss damage?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float BloodlossThreshold = 0.9f;
|
||||
|
||||
/// <summary>
|
||||
/// The base bloodloss damage to be incurred if below <see cref="BloodlossThreshold"/>
|
||||
/// The default values are defined per mob/species in YML.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public DamageSpecifier BloodlossDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// The base bloodloss damage to be healed if above <see cref="BloodlossThreshold"/>
|
||||
/// The default values are defined per mob/species in YML.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public DamageSpecifier BloodlossHealDamage = new();
|
||||
|
||||
// TODO shouldn't be hardcoded, should just use some organ simulation like bone marrow or smth.
|
||||
/// <summary>
|
||||
/// How much reagent of blood should be restored each update interval?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 BloodRefreshAmount = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How much blood needs to be in the temporary solution in order to create a puddle?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 BleedPuddleThreshold = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// A modifier set prototype ID corresponding to how damage should be modified
|
||||
/// before taking it into account for bloodloss.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For example, piercing damage is increased while poison damage is nullified entirely.
|
||||
/// </remarks>
|
||||
[DataField]
|
||||
public ProtoId<DamageModifierSetPrototype> DamageBleedModifiers = "BloodlossHuman";
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a weapon instantly deals blood loss damage.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier InstantBloodSound = new SoundCollectionSpecifier("blood");
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when some damage actually heals bleeding rather than starting it.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier BloodHealedSound = new SoundPathSpecifier("/Audio/Effects/lightburn.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The minimum amount damage reduction needed to play the healing sound/popup.
|
||||
/// This prevents tiny amounts of heat damage from spamming the sound, e.g. spacing.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float BloodHealedSoundThreshold = -0.1f;
|
||||
|
||||
// TODO probably damage bleed thresholds.
|
||||
|
||||
/// <summary>
|
||||
/// Max volume of internal chemical solution storage
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 ChemicalMaxVolume = FixedPoint2.New(250);
|
||||
|
||||
/// <summary>
|
||||
/// Max volume of internal blood storage,
|
||||
/// and starting level of blood.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 BloodMaxVolume = FixedPoint2.New(300);
|
||||
|
||||
/// <summary>
|
||||
/// Which reagent is considered this entities 'blood'?
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Slime-people might use slime as their blood or something like that.
|
||||
/// </remarks>
|
||||
[DataField]
|
||||
public ProtoId<ReagentPrototype> BloodReagent = "Blood";
|
||||
|
||||
/// <summary>Name/Key that <see cref="BloodSolution"/> is indexed by.</summary>
|
||||
[DataField]
|
||||
public string BloodSolutionName = DefaultBloodSolutionName;
|
||||
|
||||
/// <summary>Name/Key that <see cref="ChemicalSolution"/> is indexed by.</summary>
|
||||
[DataField]
|
||||
public string ChemicalSolutionName = DefaultChemicalsSolutionName;
|
||||
|
||||
/// <summary>Name/Key that <see cref="TemporarySolution"/> is indexed by.</summary>
|
||||
[DataField]
|
||||
public string BloodTemporarySolutionName = DefaultBloodTemporarySolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Internal solution for blood storage
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? BloodSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Internal solution for reagent storage
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? ChemicalSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Temporary blood solution.
|
||||
/// When blood is lost, it goes to this solution, and when this
|
||||
/// solution hits a certain cap, the blood is actually spilled as a puddle.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? TemporarySolution;
|
||||
|
||||
/// <summary>
|
||||
/// Variable that stores the amount of status time added by having a low blood level.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan StatusTime;
|
||||
|
||||
[DataField]
|
||||
public ProtoId<AlertPrototype> BleedingAlert = "Bleed";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Body.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
@@ -1,189 +1,32 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Systems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Drunk;
|
||||
using Content.Shared.EntityEffects.Effects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Forensics;
|
||||
using Content.Shared.Forensics.Components;
|
||||
using Content.Shared.HealthExaminable;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Body.Systems;
|
||||
|
||||
public sealed class BloodstreamSystem : EntitySystem
|
||||
public sealed class BloodstreamSystem : SharedBloodstreamSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly PuddleSystem _puddleSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
[Dependency] private readonly SharedDrunkSystem _drunkSystem = default!;
|
||||
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly SharedStutteringSystem _stutteringSystem = default!;
|
||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BloodstreamComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<BloodstreamComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<BloodstreamComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||
SubscribeLocalEvent<BloodstreamComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
SubscribeLocalEvent<BloodstreamComponent, HealthBeingExaminedEvent>(OnHealthBeingExamined);
|
||||
SubscribeLocalEvent<BloodstreamComponent, BeingGibbedEvent>(OnBeingGibbed);
|
||||
SubscribeLocalEvent<BloodstreamComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
|
||||
SubscribeLocalEvent<BloodstreamComponent, ReactionAttemptEvent>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<BloodstreamComponent, SolutionRelayEvent<ReactionAttemptEvent>>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<BloodstreamComponent, RejuvenateEvent>(OnRejuvenate);
|
||||
SubscribeLocalEvent<BloodstreamComponent, GenerateDnaEvent>(OnDnaGenerated);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<BloodstreamComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.NextUpdate = _gameTiming.CurTime + ent.Comp.UpdateInterval;
|
||||
}
|
||||
|
||||
private void OnUnpaused(Entity<BloodstreamComponent> ent, ref EntityUnpausedEvent args)
|
||||
{
|
||||
ent.Comp.NextUpdate += args.PausedTime;
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(Entity<BloodstreamComponent> entity, ref ReactionAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
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.Cancelled = true;
|
||||
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.
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(Entity<BloodstreamComponent> entity, ref SolutionRelayEvent<ReactionAttemptEvent> args)
|
||||
{
|
||||
if (args.Name != entity.Comp.BloodSolutionName
|
||||
&& args.Name != entity.Comp.ChemicalSolutionName
|
||||
&& args.Name != entity.Comp.BloodTemporarySolutionName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnReactionAttempt(entity, ref args.Event);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<BloodstreamComponent>();
|
||||
while (query.MoveNext(out var uid, out var bloodstream))
|
||||
{
|
||||
if (_gameTiming.CurTime < bloodstream.NextUpdate)
|
||||
continue;
|
||||
|
||||
bloodstream.NextUpdate += bloodstream.UpdateInterval;
|
||||
|
||||
if (!_solutionContainerSystem.ResolveSolution(uid, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution))
|
||||
continue;
|
||||
|
||||
// Adds blood to their blood level if it is below the maximum; Blood regeneration. Must be alive.
|
||||
if (bloodSolution.Volume < bloodSolution.MaxVolume && !_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
TryModifyBloodLevel(uid, bloodstream.BloodRefreshAmount, bloodstream);
|
||||
}
|
||||
|
||||
// Removes blood from the bloodstream based on bleed amount (bleed rate)
|
||||
// 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);
|
||||
}
|
||||
|
||||
// deal bloodloss damage if their blood level is below a threshold.
|
||||
var bloodPercentage = GetBloodLevelPercentage(uid, bloodstream);
|
||||
if (bloodPercentage < bloodstream.BloodlossThreshold && !_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
// bloodloss damage is based on the base value, and modified by how low your blood level is.
|
||||
var amt = bloodstream.BloodlossDamage / (0.1f + bloodPercentage);
|
||||
|
||||
_damageableSystem.TryChangeDamage(uid, amt,
|
||||
ignoreResistances: false, interruptsDoAfters: false);
|
||||
|
||||
// Apply dizziness as a symptom of bloodloss.
|
||||
// The effect is applied in a way that it will never be cleared without being healthy.
|
||||
// Multiplying by 2 is arbitrary but works for this case, it just prevents the time from running out
|
||||
_drunkSystem.TryApplyDrunkenness(
|
||||
uid,
|
||||
(float) bloodstream.UpdateInterval.TotalSeconds * 2,
|
||||
applySlur: false);
|
||||
_stutteringSystem.DoStutter(uid, bloodstream.UpdateInterval * 2, refresh: false);
|
||||
|
||||
// storing the drunk and stutter time so we can remove it independently from other effects additions
|
||||
bloodstream.StatusTime += bloodstream.UpdateInterval * 2;
|
||||
}
|
||||
else if (!_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
// If they're healthy, we'll try and heal some bloodloss instead.
|
||||
_damageableSystem.TryChangeDamage(
|
||||
uid,
|
||||
bloodstream.BloodlossHealDamage * bloodPercentage,
|
||||
ignoreResistances: true, interruptsDoAfters: false);
|
||||
|
||||
// Remove the drunk effect when healthy. Should only remove the amount of drunk and stutter added by low blood level
|
||||
_drunkSystem.TryRemoveDrunkenessTime(uid, bloodstream.StatusTime.TotalSeconds);
|
||||
_stutteringSystem.DoRemoveStutterTime(uid, bloodstream.StatusTime.TotalSeconds);
|
||||
// Reset the drunk and stutter time to zero
|
||||
bloodstream.StatusTime = TimeSpan.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not sure if we can move this to shared or not
|
||||
// it would certainly help if SolutionContainer was documented
|
||||
// but since we usually don't add the component dynamically to entities we can keep this unpredicted for now
|
||||
private void OnComponentInit(Entity<BloodstreamComponent> entity, ref ComponentInit args)
|
||||
{
|
||||
if (!_solutionContainerSystem.EnsureSolution(entity.Owner,
|
||||
if (!SolutionContainer.EnsureSolution(entity.Owner,
|
||||
entity.Comp.ChemicalSolutionName,
|
||||
out var chemicalSolution) ||
|
||||
!_solutionContainerSystem.EnsureSolution(entity.Owner,
|
||||
!SolutionContainer.EnsureSolution(entity.Owner,
|
||||
entity.Comp.BloodSolutionName,
|
||||
out var bloodSolution) ||
|
||||
!_solutionContainerSystem.EnsureSolution(entity.Owner,
|
||||
!SolutionContainer.EnsureSolution(entity.Owner,
|
||||
entity.Comp.BloodTemporarySolutionName,
|
||||
out var tempSolution))
|
||||
return;
|
||||
@@ -197,298 +40,10 @@ public sealed class BloodstreamSystem : EntitySystem
|
||||
bloodSolution.AddReagent(new ReagentId(entity.Comp.BloodReagent, GetEntityBloodData(entity.Owner)), entity.Comp.BloodMaxVolume - bloodSolution.Volume);
|
||||
}
|
||||
|
||||
private void OnDamageChanged(Entity<BloodstreamComponent> ent, ref DamageChangedEvent args)
|
||||
{
|
||||
if (args.DamageDelta is null || !args.DamageIncreased)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO probably cache this or something. humans get hurt a lot
|
||||
if (!_prototypeManager.TryIndex(ent.Comp.DamageBleedModifiers, out var modifiers))
|
||||
return;
|
||||
|
||||
// some reagents may deal and heal different damage types in the same tick, which means DamageIncreased will be true
|
||||
// but we only want to consider the dealt damage when causing bleeding
|
||||
var damage = DamageSpecifier.GetPositive(args.DamageDelta);
|
||||
var bloodloss = DamageSpecifier.ApplyModifierSet(damage, modifiers);
|
||||
|
||||
if (bloodloss.Empty)
|
||||
return;
|
||||
|
||||
// Does the calculation of how much bleed rate should be added/removed, then applies it
|
||||
var oldBleedAmount = ent.Comp.BleedAmount;
|
||||
var total = bloodloss.GetTotal();
|
||||
var totalFloat = total.Float();
|
||||
TryModifyBleedAmount(ent, totalFloat, ent);
|
||||
|
||||
/// <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(ent, -total / 5, ent);
|
||||
_audio.PlayPvs(ent.Comp.InstantBloodSound, ent);
|
||||
}
|
||||
|
||||
// Heat damage will cauterize, causing the bleed rate to be reduced.
|
||||
else if (totalFloat <= ent.Comp.BloodHealedSoundThreshold && 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(ent.Comp.BloodHealedSound, ent);
|
||||
_popupSystem.PopupEntity(Loc.GetString("bloodstream-component-wounds-cauterized"), ent,
|
||||
ent, PopupType.Medium);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Shows text on health examine, based on bleed rate and blood level.
|
||||
/// </summary>
|
||||
private void OnHealthBeingExamined(Entity<BloodstreamComponent> ent, ref HealthBeingExaminedEvent args)
|
||||
{
|
||||
// Shows massively bleeding at 0.75x the max bleed rate.
|
||||
if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.75f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-massive-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding above half the max rate, but less than massively.
|
||||
else if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.5f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-strong-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding above 0.25x the max rate, but less than half the max.
|
||||
else if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.25f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding below 0.25x the max cap
|
||||
else if (ent.Comp.BleedAmount > 0)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-slight-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
|
||||
// If the mob's blood level is below the damage threshhold, the pale message is added.
|
||||
if (GetBloodLevelPercentage(ent, ent) < ent.Comp.BloodlossThreshold)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-looks-pale", ("target", ent.Owner)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBeingGibbed(Entity<BloodstreamComponent> ent, ref BeingGibbedEvent args)
|
||||
{
|
||||
SpillAllSolutions(ent, ent);
|
||||
}
|
||||
|
||||
private void OnApplyMetabolicMultiplier(
|
||||
Entity<BloodstreamComponent> ent,
|
||||
ref ApplyMetabolicMultiplierEvent args)
|
||||
{
|
||||
// TODO REFACTOR THIS
|
||||
// This will slowly drift over time due to floating point errors.
|
||||
// Instead, raise an event with the base rates and allow modifiers to get applied to it.
|
||||
if (args.Apply)
|
||||
{
|
||||
ent.Comp.UpdateInterval *= args.Multiplier;
|
||||
return;
|
||||
}
|
||||
ent.Comp.UpdateInterval /= args.Multiplier;
|
||||
}
|
||||
|
||||
private void OnRejuvenate(Entity<BloodstreamComponent> entity, ref RejuvenateEvent args)
|
||||
{
|
||||
TryModifyBleedAmount(entity.Owner, -entity.Comp.BleedAmount, entity.Comp);
|
||||
|
||||
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.BloodSolutionName, ref entity.Comp.BloodSolution, out var bloodSolution))
|
||||
TryModifyBloodLevel(entity.Owner, bloodSolution.AvailableVolume, entity.Comp);
|
||||
|
||||
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.ChemicalSolutionName, ref entity.Comp.ChemicalSolution))
|
||||
_solutionContainerSystem.RemoveAllSolution(entity.Comp.ChemicalSolution.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to transfer provided solution to internal solution.
|
||||
/// </summary>
|
||||
public bool TryAddToChemicals(EntityUid uid, Solution solution, BloodstreamComponent? component = null)
|
||||
{
|
||||
return Resolve(uid, ref component, logMissing: false)
|
||||
&& _solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution)
|
||||
&& _solutionContainerSystem.TryAddSolution(component.ChemicalSolution.Value, solution);
|
||||
}
|
||||
|
||||
public bool FlushChemicals(EntityUid uid, string excludedReagentID, FixedPoint2 quantity, BloodstreamComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, logMissing: false)
|
||||
|| !_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution, out var chemSolution))
|
||||
return false;
|
||||
|
||||
for (var i = chemSolution.Contents.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var (reagentId, _) = chemSolution.Contents[i];
|
||||
if (reagentId.Prototype != excludedReagentID)
|
||||
{
|
||||
_solutionContainerSystem.RemoveReagent(component.ChemicalSolution.Value, reagentId, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public float GetBloodLevelPercentage(EntityUid uid, BloodstreamComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component)
|
||||
|| !_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return 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, logMissing: false)
|
||||
|| !_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (amount >= 0)
|
||||
return _solutionContainerSystem.TryAddReagent(component.BloodSolution.Value, component.BloodReagent, amount, null, GetEntityBloodData(uid));
|
||||
|
||||
// Removal is more involved,
|
||||
// since we also wanna handle moving it to the temporary solution
|
||||
// and then spilling it if necessary.
|
||||
var newSol = _solutionContainerSystem.SplitSolution(component.BloodSolution.Value, -amount);
|
||||
|
||||
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodTemporarySolutionName, ref component.TemporarySolution, out var tempSolution))
|
||||
return true;
|
||||
|
||||
tempSolution.AddSolution(newSol, _prototypeManager);
|
||||
|
||||
if (tempSolution.Volume > component.BleedPuddleThreshold)
|
||||
{
|
||||
// Pass some of the chemstream into the spilled blood.
|
||||
if (_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution))
|
||||
{
|
||||
var temp = _solutionContainerSystem.SplitSolution(component.ChemicalSolution.Value, tempSolution.Volume / 10);
|
||||
tempSolution.AddSolution(temp, _prototypeManager);
|
||||
}
|
||||
|
||||
_puddleSystem.TrySpillAt(uid, tempSolution, out var puddleUid, sound: false);
|
||||
|
||||
tempSolution.RemoveAllSolution();
|
||||
}
|
||||
|
||||
_solutionContainerSystem.UpdateChemicals(component.TemporarySolution.Value);
|
||||
|
||||
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, logMissing: false))
|
||||
return false;
|
||||
|
||||
component.BleedAmount += amount;
|
||||
component.BleedAmount = Math.Clamp(component.BleedAmount, 0, component.MaxBleedAmount);
|
||||
|
||||
if (component.BleedAmount == 0)
|
||||
_alertsSystem.ClearAlert(uid, component.BleedingAlert);
|
||||
else
|
||||
{
|
||||
var severity = (short) Math.Clamp(Math.Round(component.BleedAmount, MidpointRounding.ToZero), 0, 10);
|
||||
_alertsSystem.ShowAlert(uid, component.BleedingAlert, severity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BLOOD FOR THE BLOOD GOD
|
||||
/// </summary>
|
||||
public void SpillAllSolutions(EntityUid uid, BloodstreamComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
var tempSol = new Solution();
|
||||
|
||||
if (_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
tempSol.MaxVolume += bloodSolution.MaxVolume;
|
||||
tempSol.AddSolution(bloodSolution, _prototypeManager);
|
||||
_solutionContainerSystem.RemoveAllSolution(component.BloodSolution.Value);
|
||||
}
|
||||
|
||||
if (_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution, out var chemSolution))
|
||||
{
|
||||
tempSol.MaxVolume += chemSolution.MaxVolume;
|
||||
tempSol.AddSolution(chemSolution, _prototypeManager);
|
||||
_solutionContainerSystem.RemoveAllSolution(component.ChemicalSolution.Value);
|
||||
}
|
||||
|
||||
if (_solutionContainerSystem.ResolveSolution(uid, component.BloodTemporarySolutionName, ref component.TemporarySolution, out var tempSolution))
|
||||
{
|
||||
tempSol.MaxVolume += tempSolution.MaxVolume;
|
||||
tempSol.AddSolution(tempSolution, _prototypeManager);
|
||||
_solutionContainerSystem.RemoveAllSolution(component.TemporarySolution.Value);
|
||||
}
|
||||
|
||||
_puddleSystem.TrySpillAt(uid, tempSol, out var puddleUid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change what someone's blood is made of, on the fly.
|
||||
/// </summary>
|
||||
public void ChangeBloodReagent(EntityUid uid, string reagent, BloodstreamComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, logMissing: false)
|
||||
|| reagent == component.BloodReagent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
component.BloodReagent = reagent;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentVolume = bloodSolution.RemoveReagent(component.BloodReagent, bloodSolution.Volume, ignoreReagentData: true);
|
||||
|
||||
component.BloodReagent = reagent;
|
||||
|
||||
if (currentVolume > 0)
|
||||
_solutionContainerSystem.TryAddReagent(component.BloodSolution.Value, component.BloodReagent, currentVolume, null, GetEntityBloodData(uid));
|
||||
}
|
||||
|
||||
// forensics is not predicted yet
|
||||
private void OnDnaGenerated(Entity<BloodstreamComponent> entity, ref GenerateDnaEvent args)
|
||||
{
|
||||
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.BloodSolutionName, ref entity.Comp.BloodSolution, out var bloodSolution))
|
||||
if (SolutionContainer.ResolveSolution(entity.Owner, entity.Comp.BloodSolutionName, ref entity.Comp.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
foreach (var reagent in bloodSolution.Contents)
|
||||
{
|
||||
@@ -500,22 +55,4 @@ public sealed class BloodstreamSystem : EntitySystem
|
||||
else
|
||||
Log.Error("Unable to set bloodstream DNA, solution entity could not be resolved");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the reagent data for blood that a specific entity should have.
|
||||
/// </summary>
|
||||
public List<ReagentData> GetEntityBloodData(EntityUid uid)
|
||||
{
|
||||
var bloodData = new List<ReagentData>();
|
||||
var dnaData = new DnaData();
|
||||
|
||||
if (TryComp<DnaComponent>(uid, out var donorComp) && donorComp.DNA != null)
|
||||
dnaData.DNA = donorComp.DNA;
|
||||
else
|
||||
dnaData.DNA = Loc.GetString("forensics-dna-unknown");
|
||||
|
||||
bloodData.Add(dnaData);
|
||||
|
||||
return bloodData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Numerics;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Ghost;
|
||||
using Content.Server.Humanoid;
|
||||
using Content.Shared.Body.Components;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -237,7 +236,7 @@ public sealed class InjectorSystem : SharedInjectorSystem
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = SolutionContainers.SplitSolution(target.Comp.ChemicalSolution.Value, realTransferAmount);
|
||||
|
||||
_blood.TryAddToChemicals(target, removedSolution, target.Comp);
|
||||
_blood.TryAddToChemicals(target.AsNullable(), removedSolution);
|
||||
|
||||
_reactiveSystem.DoEntityReaction(target, removedSolution, ReactionMethod.Injection);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Body.Components;
|
||||
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;
|
||||
@@ -148,7 +148,7 @@ public sealed class SolutionInjectOnCollideSystem : EntitySystem
|
||||
// Take our portion of the adjusted solution for this target
|
||||
var individualInjection = solutionToInject.SplitSolution(volumePerBloodstream);
|
||||
// Inject our portion into the target's bloodstream
|
||||
if (_bloodstream.TryAddToChemicals(targetBloodstream.Owner, individualInjection, targetBloodstream.Comp))
|
||||
if (_bloodstream.TryAddToChemicals(targetBloodstream.AsNullable(), individualInjection))
|
||||
anySuccess = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Devour;
|
||||
using Content.Shared.Devour.Components;
|
||||
|
||||
@@ -22,6 +22,7 @@ using Content.Server.Temperature.Systems;
|
||||
using Content.Server.Traits.Assorted;
|
||||
using Content.Server.Zombies;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Coordinates.Helpers;
|
||||
using Content.Shared.EntityEffects.EffectConditions;
|
||||
using Content.Shared.EntityEffects.Effects.PlantMetabolism;
|
||||
@@ -558,11 +559,11 @@ public sealed class EntityEffectSystem : EntitySystem
|
||||
return;
|
||||
|
||||
cleanseRate *= reagentArgs.Scale.Float();
|
||||
_bloodstream.FlushChemicals(args.Args.TargetEntity, reagentArgs.Reagent.ID, cleanseRate);
|
||||
_bloodstream.FlushChemicals(args.Args.TargetEntity, reagentArgs.Reagent, cleanseRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
_bloodstream.FlushChemicals(args.Args.TargetEntity, "", cleanseRate);
|
||||
_bloodstream.FlushChemicals(args.Args.TargetEntity, null, cleanseRate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,7 +781,7 @@ public sealed class EntityEffectSystem : EntitySystem
|
||||
amt *= reagentArgs.Scale.Float();
|
||||
}
|
||||
|
||||
_bloodstream.TryModifyBleedAmount(args.Args.TargetEntity, amt, blood);
|
||||
_bloodstream.TryModifyBleedAmount((args.Args.TargetEntity, blood), amt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,7 +797,7 @@ public sealed class EntityEffectSystem : EntitySystem
|
||||
amt *= reagentArgs.Scale;
|
||||
}
|
||||
|
||||
_bloodstream.TryModifyBloodLevel(args.Args.TargetEntity, amt, blood);
|
||||
_bloodstream.TryModifyBloodLevel((args.Args.TargetEntity, blood), amt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.EntityEffects.Effects;
|
||||
using Content.Server.Spreader;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
@@ -288,7 +288,7 @@ public sealed class SmokeSystem : EntitySystem
|
||||
if (blockIngestion)
|
||||
return;
|
||||
|
||||
if (_blood.TryAddToChemicals(entity, transferSolution, bloodstream))
|
||||
if (_blood.TryAddToChemicals((entity, bloodstream), transferSolution))
|
||||
{
|
||||
// Log solution addition by smoke
|
||||
_logger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(entity):target} ingested smoke {SharedSolutionContainerSystem.ToPrettyString(transferSolution)}");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Forensics.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Implants.Components;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Numerics;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Botany.Components;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Materials;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Climbing.Events;
|
||||
@@ -30,7 +30,6 @@ using Robust.Server.Player;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Medical.BiomassReclaimer
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Server.Medical.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies a damage change to the target when used in an interaction.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class HealingComponent : Component
|
||||
{
|
||||
[DataField("damage", required: true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
/// <remarks>
|
||||
/// This should generally be negative,
|
||||
/// since you're, like, trying to heal damage.
|
||||
/// </remarks>
|
||||
[DataField("bloodlossModifier")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BloodlossModifier = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Restore missing blood.
|
||||
/// </summary>
|
||||
[DataField("ModifyBloodLevel")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ModifyBloodLevel = 0.0f;
|
||||
|
||||
/// <remarks>
|
||||
/// The supported damage types are specified using a <see cref="DamageContainerPrototype"/>s. For a
|
||||
/// HealingComponent this filters what damage container type this component should work on. If null,
|
||||
/// all damage container types are supported.
|
||||
/// </remarks>
|
||||
[DataField("damageContainers", customTypeSerializer: typeof(PrototypeIdListSerializer<DamageContainerPrototype>))]
|
||||
public List<string>? DamageContainers;
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to apply the damage.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("delay")]
|
||||
public float Delay = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Delay multiplier when healing yourself.
|
||||
/// </summary>
|
||||
[DataField("selfHealPenaltyMultiplier")]
|
||||
public float SelfHealPenaltyMultiplier = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Sound played on healing begin
|
||||
/// </summary>
|
||||
[DataField("healingBeginSound")]
|
||||
public SoundSpecifier? HealingBeginSound = null;
|
||||
|
||||
/// <summary>
|
||||
/// Sound played on healing end
|
||||
/// </summary>
|
||||
[DataField("healingEndSound")]
|
||||
public SoundSpecifier? HealingEndSound = null;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ using Content.Server.Administration.Logs;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Atmos.Piping.Components;
|
||||
using Content.Server.Atmos.Piping.Unary.EntitySystems;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Medical.Components;
|
||||
using Content.Server.NodeContainer.EntitySystems;
|
||||
@@ -10,6 +9,7 @@ using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
@@ -116,7 +116,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
|
||||
}
|
||||
|
||||
var solutionToInject = _solutionContainerSystem.SplitSolution(containerSolution.Value, cryoPod.BeakerTransferAmount);
|
||||
_bloodstreamSystem.TryAddToChemicals(patient.Value, solutionToInject, bloodstream);
|
||||
_bloodstreamSystem.TryAddToChemicals((patient.Value, bloodstream), solutionToInject);
|
||||
_reactiveSystem.DoEntityReaction(patient.Value, solutionToInject, ReactionMethod.Injection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Medical.Components;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Traits.Assorted;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
@@ -14,6 +13,7 @@ using Content.Shared.Item.ItemToggle.Components;
|
||||
using Content.Shared.MedicalScanner;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Traits.Assorted;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Forensics;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Tag;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Server.Forensics;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -17,7 +16,6 @@ using Content.Shared.Temperature;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using System.Linq;
|
||||
using Content.Shared.Atmos;
|
||||
|
||||
namespace Content.Server.Nutrition.EntitySystems
|
||||
@@ -159,7 +157,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
}
|
||||
|
||||
_reactiveSystem.DoEntityReaction(containerManager.Owner, inhaledSolution, ReactionMethod.Ingestion);
|
||||
_bloodstreamSystem.TryAddToChemicals(containerManager.Owner, inhaledSolution, bloodstream);
|
||||
_bloodstreamSystem.TryAddToChemicals((containerManager.Owner, bloodstream), inhaledSolution);
|
||||
}
|
||||
|
||||
_timer -= UpdateTimer;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
@@ -12,6 +12,7 @@ using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Rootable;
|
||||
|
||||
// TODO: Move all of this to shared
|
||||
/// <summary>
|
||||
/// Adds an action to toggle rooting to the ground, primarily for the Diona species.
|
||||
/// </summary>
|
||||
@@ -68,7 +69,7 @@ public sealed class RootableSystem : SharedRootableSystem
|
||||
|
||||
_reactive.DoEntityReaction(entity, transferSolution, ReactionMethod.Ingestion);
|
||||
|
||||
if (_blood.TryAddToChemicals(entity, transferSolution, entity.Comp2))
|
||||
if (_blood.TryAddToChemicals((entity, entity.Comp2), transferSolution))
|
||||
{
|
||||
// Log solution addition by puddle
|
||||
_logger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(entity):target} absorbed puddle {SharedSolutionContainerSystem.ToPrettyString(transferSolution)}");
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Content.Server.Actions;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
@@ -13,6 +13,7 @@ using Content.Server.NPC.HTN;
|
||||
using Content.Server.NPC.Systems;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.CombatMode.Pacification;
|
||||
using Content.Shared.Damage;
|
||||
|
||||
200
Content.Shared/Body/Components/BloodstreamComponent.cs
Normal file
200
Content.Shared/Body/Components/BloodstreamComponent.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Body.Systems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Body.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Gives an entity a bloodstream.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent,]
|
||||
[AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause]
|
||||
[Access(typeof(SharedBloodstreamSystem))]
|
||||
public sealed partial class BloodstreamComponent : Component
|
||||
{
|
||||
public const string DefaultChemicalsSolutionName = "chemicals";
|
||||
public const string DefaultBloodSolutionName = "bloodstream";
|
||||
public const string DefaultBloodTemporarySolutionName = "bloodstreamTemporary";
|
||||
|
||||
/// <summary>
|
||||
/// The next time that blood level will be updated and bloodloss damage dealt.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
[AutoNetworkedField, AutoPausedField]
|
||||
public TimeSpan NextUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// The interval at which this component updates.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(3);
|
||||
|
||||
/// <summary>
|
||||
/// How much is this entity currently bleeding?
|
||||
/// Higher numbers mean more blood lost every tick.
|
||||
///
|
||||
/// Goes down slowly over time, and items like bandages
|
||||
/// or clotting reagents can lower bleeding.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This generally corresponds to an amount of damage and can't go above 100.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float BleedAmount;
|
||||
|
||||
/// <summary>
|
||||
/// How much should bleeding be reduced every update interval?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float BleedReductionAmount = 0.33f;
|
||||
|
||||
/// <summary>
|
||||
/// How high can <see cref="BleedAmount"/> go?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float MaxBleedAmount = 10.0f;
|
||||
|
||||
/// <summary>
|
||||
/// What percentage of current blood is necessary to avoid dealing blood loss damage?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float BloodlossThreshold = 0.9f;
|
||||
|
||||
/// <summary>
|
||||
/// The base bloodloss damage to be incurred if below <see cref="BloodlossThreshold"/>
|
||||
/// The default values are defined per mob/species in YML.
|
||||
/// </summary>
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public DamageSpecifier BloodlossDamage = new();
|
||||
|
||||
/// <summary>
|
||||
/// The base bloodloss damage to be healed if above <see cref="BloodlossThreshold"/>
|
||||
/// The default values are defined per mob/species in YML.
|
||||
/// </summary>
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public DamageSpecifier BloodlossHealDamage = new();
|
||||
|
||||
// TODO shouldn't be hardcoded, should just use some organ simulation like bone marrow or smth.
|
||||
/// <summary>
|
||||
/// How much reagent of blood should be restored each update interval?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public FixedPoint2 BloodRefreshAmount = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// How much blood needs to be in the temporary solution in order to create a puddle?
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public FixedPoint2 BleedPuddleThreshold = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// A modifier set prototype ID corresponding to how damage should be modified
|
||||
/// before taking it into account for bloodloss.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For example, piercing damage is increased while poison damage is nullified entirely.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<DamageModifierSetPrototype> DamageBleedModifiers = "BloodlossHuman";
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a weapon instantly deals blood loss damage.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public SoundSpecifier InstantBloodSound = new SoundCollectionSpecifier("blood");
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when some damage actually heals bleeding rather than starting it.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier BloodHealedSound = new SoundPathSpecifier("/Audio/Effects/lightburn.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The minimum amount damage reduction needed to play the healing sound/popup.
|
||||
/// This prevents tiny amounts of heat damage from spamming the sound, e.g. spacing.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float BloodHealedSoundThreshold = -0.1f;
|
||||
|
||||
// TODO probably damage bleed thresholds.
|
||||
|
||||
/// <summary>
|
||||
/// Max volume of internal chemical solution storage
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 ChemicalMaxVolume = FixedPoint2.New(250);
|
||||
|
||||
/// <summary>
|
||||
/// Max volume of internal blood storage,
|
||||
/// and starting level of blood.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public FixedPoint2 BloodMaxVolume = FixedPoint2.New(300);
|
||||
|
||||
/// <summary>
|
||||
/// Which reagent is considered this entities 'blood'?
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Slime-people might use slime as their blood or something like that.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<ReagentPrototype> BloodReagent = "Blood";
|
||||
|
||||
/// <summary>
|
||||
/// Name/Key that <see cref="BloodSolution"/> is indexed by.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string BloodSolutionName = DefaultBloodSolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Name/Key that <see cref="ChemicalSolution"/> is indexed by.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string ChemicalSolutionName = DefaultChemicalsSolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Name/Key that <see cref="TemporarySolution"/> is indexed by.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string BloodTemporarySolutionName = DefaultBloodTemporarySolutionName;
|
||||
|
||||
/// <summary>
|
||||
/// Internal solution for blood storage
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? BloodSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Internal solution for reagent storage
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? ChemicalSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Temporary blood solution.
|
||||
/// When blood is lost, it goes to this solution, and when this
|
||||
/// solution hits a certain cap, the blood is actually spilled as a puddle.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Entity<SolutionComponent>? TemporarySolution;
|
||||
|
||||
/// <summary>
|
||||
/// Variable that stores the amount of status time added by having a low blood level.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public TimeSpan StatusTime;
|
||||
|
||||
/// <summary>
|
||||
/// Alert to show when bleeding.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public ProtoId<AlertPrototype> BleedingAlert = "Bleed";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Content.Shared.Body.Events;
|
||||
namespace Content.Shared.Body.Events;
|
||||
|
||||
// TODO REFACTOR THIS
|
||||
// This will cause rates to slowly drift over time due to floating point errors.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Content.Server.Body.Components;
|
||||
namespace Content.Shared.Body.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a body gets gibbed, before it is deleted.
|
||||
519
Content.Shared/Body/Systems/SharedBloodstreamSystem.cs
Normal file
519
Content.Shared/Body/Systems/SharedBloodstreamSystem.cs
Normal file
@@ -0,0 +1,519 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Drunk;
|
||||
using Content.Shared.EntityEffects.Effects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Forensics.Components;
|
||||
using Content.Shared.HealthExaminable;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Body.Systems;
|
||||
|
||||
public abstract class SharedBloodstreamSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly SharedSolutionContainerSystem SolutionContainer = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedPuddleSystem _puddle = default!;
|
||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly SharedDrunkSystem _drunkSystem = default!;
|
||||
[Dependency] private readonly SharedStutteringSystem _stutteringSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BloodstreamComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<BloodstreamComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
SubscribeLocalEvent<BloodstreamComponent, ReactionAttemptEvent>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<BloodstreamComponent, SolutionRelayEvent<ReactionAttemptEvent>>(OnReactionAttempt);
|
||||
SubscribeLocalEvent<BloodstreamComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
SubscribeLocalEvent<BloodstreamComponent, HealthBeingExaminedEvent>(OnHealthBeingExamined);
|
||||
SubscribeLocalEvent<BloodstreamComponent, BeingGibbedEvent>(OnBeingGibbed);
|
||||
SubscribeLocalEvent<BloodstreamComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
|
||||
SubscribeLocalEvent<BloodstreamComponent, RejuvenateEvent>(OnRejuvenate);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var curTime = _timing.CurTime;
|
||||
var query = EntityQueryEnumerator<BloodstreamComponent>();
|
||||
while (query.MoveNext(out var uid, out var bloodstream))
|
||||
{
|
||||
if (curTime < bloodstream.NextUpdate)
|
||||
continue;
|
||||
|
||||
bloodstream.NextUpdate += bloodstream.UpdateInterval;
|
||||
DirtyField(uid, bloodstream, nameof(BloodstreamComponent.NextUpdate)); // needs to be dirtied on the client so it can be rerolled during prediction
|
||||
|
||||
if (!SolutionContainer.ResolveSolution(uid, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution))
|
||||
continue;
|
||||
|
||||
// Adds blood to their blood level if it is below the maximum; Blood regeneration. Must be alive.
|
||||
if (bloodSolution.Volume < bloodSolution.MaxVolume && !_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
TryModifyBloodLevel((uid, bloodstream), bloodstream.BloodRefreshAmount);
|
||||
}
|
||||
|
||||
// Removes blood from the bloodstream based on bleed amount (bleed rate)
|
||||
// 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), -bloodstream.BleedAmount);
|
||||
// Bleed rate is reduced by the bleed reduction amount in the bloodstream component.
|
||||
TryModifyBleedAmount((uid, bloodstream), -bloodstream.BleedReductionAmount);
|
||||
}
|
||||
|
||||
// deal bloodloss damage if their blood level is below a threshold.
|
||||
var bloodPercentage = GetBloodLevelPercentage((uid, bloodstream));
|
||||
if (bloodPercentage < bloodstream.BloodlossThreshold && !_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
// bloodloss damage is based on the base value, and modified by how low your blood level is.
|
||||
var amt = bloodstream.BloodlossDamage / (0.1f + bloodPercentage);
|
||||
|
||||
_damageableSystem.TryChangeDamage(uid, amt,
|
||||
ignoreResistances: false, interruptsDoAfters: false);
|
||||
|
||||
// Apply dizziness as a symptom of bloodloss.
|
||||
// The effect is applied in a way that it will never be cleared without being healthy.
|
||||
// Multiplying by 2 is arbitrary but works for this case, it just prevents the time from running out
|
||||
_drunkSystem.TryApplyDrunkenness(
|
||||
uid,
|
||||
(float)bloodstream.UpdateInterval.TotalSeconds * 2,
|
||||
applySlur: false);
|
||||
_stutteringSystem.DoStutter(uid, bloodstream.UpdateInterval * 2, refresh: false);
|
||||
|
||||
// storing the drunk and stutter time so we can remove it independently from other effects additions
|
||||
bloodstream.StatusTime += bloodstream.UpdateInterval * 2;
|
||||
DirtyField(uid, bloodstream, nameof(BloodstreamComponent.StatusTime));
|
||||
}
|
||||
else if (!_mobStateSystem.IsDead(uid))
|
||||
{
|
||||
// If they're healthy, we'll try and heal some bloodloss instead.
|
||||
_damageableSystem.TryChangeDamage(
|
||||
uid,
|
||||
bloodstream.BloodlossHealDamage * bloodPercentage,
|
||||
ignoreResistances: true, interruptsDoAfters: false);
|
||||
|
||||
// Remove the drunk effect when healthy. Should only remove the amount of drunk and stutter added by low blood level
|
||||
_drunkSystem.TryRemoveDrunkenessTime(uid, bloodstream.StatusTime.TotalSeconds);
|
||||
_stutteringSystem.DoRemoveStutterTime(uid, bloodstream.StatusTime.TotalSeconds);
|
||||
// Reset the drunk and stutter time to zero
|
||||
bloodstream.StatusTime = TimeSpan.Zero;
|
||||
DirtyField(uid, bloodstream, nameof(BloodstreamComponent.StatusTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<BloodstreamComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.NextUpdate = _timing.CurTime + ent.Comp.UpdateInterval;
|
||||
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.NextUpdate));
|
||||
}
|
||||
|
||||
// prevent the infamous UdderSystem debug assert, see https://github.com/space-wizards/space-station-14/pull/35314
|
||||
// TODO: find a better solution than copy pasting this into every shared system that caches solution entities
|
||||
private void OnEntRemoved(Entity<BloodstreamComponent> entity, ref EntRemovedFromContainerMessage args)
|
||||
{
|
||||
// Make sure the removed entity was our contained solution and set it to null
|
||||
if (args.Entity == entity.Comp.BloodSolution?.Owner)
|
||||
entity.Comp.BloodSolution = null;
|
||||
|
||||
if (args.Entity == entity.Comp.ChemicalSolution?.Owner)
|
||||
entity.Comp.ChemicalSolution = null;
|
||||
|
||||
if (args.Entity == entity.Comp.TemporarySolution?.Owner)
|
||||
entity.Comp.TemporarySolution = null;
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(Entity<BloodstreamComponent> ent, ref ReactionAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
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.Cancelled = true;
|
||||
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.
|
||||
}
|
||||
|
||||
private void OnReactionAttempt(Entity<BloodstreamComponent> ent, ref SolutionRelayEvent<ReactionAttemptEvent> args)
|
||||
{
|
||||
if (args.Name != ent.Comp.BloodSolutionName
|
||||
&& args.Name != ent.Comp.ChemicalSolutionName
|
||||
&& args.Name != ent.Comp.BloodTemporarySolutionName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnReactionAttempt(ent, ref args.Event);
|
||||
}
|
||||
|
||||
private void OnDamageChanged(Entity<BloodstreamComponent> ent, ref DamageChangedEvent args)
|
||||
{
|
||||
// The incoming state from the server raises a DamageChangedEvent as well.
|
||||
// But the changes to the bloodstream have also been dirtied,
|
||||
// so we prevent applying them twice.
|
||||
if (_timing.ApplyingState)
|
||||
return;
|
||||
|
||||
if (args.DamageDelta is null || !args.DamageIncreased)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO probably cache this or something. humans get hurt a lot
|
||||
if (!_prototypeManager.TryIndex(ent.Comp.DamageBleedModifiers, out var modifiers))
|
||||
return;
|
||||
|
||||
// some reagents may deal and heal different damage types in the same tick, which means DamageIncreased will be true
|
||||
// but we only want to consider the dealt damage when causing bleeding
|
||||
var damage = DamageSpecifier.GetPositive(args.DamageDelta);
|
||||
var bloodloss = DamageSpecifier.ApplyModifierSet(damage, modifiers);
|
||||
|
||||
if (bloodloss.Empty)
|
||||
return;
|
||||
|
||||
// Does the calculation of how much bleed rate should be added/removed, then applies it
|
||||
var oldBleedAmount = ent.Comp.BleedAmount;
|
||||
var total = bloodloss.GetTotal();
|
||||
var totalFloat = total.Float();
|
||||
TryModifyBleedAmount(ent.AsNullable(), totalFloat);
|
||||
|
||||
/// 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!
|
||||
|
||||
// TODO: Replace with RandomPredicted once the engine PR is merged
|
||||
// Use both the receiver and the damage causing entity for the seed so that we have different results for multiple attacks in the same tick
|
||||
var seed = HashCode.Combine((int)_timing.CurTick.Value, GetNetEntity(ent).Id, GetNetEntity(args.Origin)?.Id ?? 0);
|
||||
var rand = new System.Random(seed);
|
||||
var prob = Math.Clamp(totalFloat / 25, 0, 1);
|
||||
if (totalFloat > 0 && rand.Prob(prob))
|
||||
{
|
||||
TryModifyBloodLevel(ent.AsNullable(), -total / 5);
|
||||
_audio.PlayPredicted(ent.Comp.InstantBloodSound, ent, args.Origin);
|
||||
}
|
||||
|
||||
// Heat damage will cauterize, causing the bleed rate to be reduced.
|
||||
else if (totalFloat <= ent.Comp.BloodHealedSoundThreshold && 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.
|
||||
_popup.PopupEntity(Loc.GetString("bloodstream-component-wounds-cauterized"), ent,
|
||||
ent, PopupType.Medium); // only the burned entity can see this
|
||||
_audio.PlayPredicted(ent.Comp.BloodHealedSound, ent, args.Origin);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows text on health examine, based on bleed rate and blood level.
|
||||
/// </summary>
|
||||
private void OnHealthBeingExamined(Entity<BloodstreamComponent> ent, ref HealthBeingExaminedEvent args)
|
||||
{
|
||||
// Shows massively bleeding at 0.75x the max bleed rate.
|
||||
if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.75f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-massive-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding above half the max rate, but less than massively.
|
||||
else if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.5f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-strong-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding above 0.25x the max rate, but less than half the max.
|
||||
else if (ent.Comp.BleedAmount > ent.Comp.MaxBleedAmount * 0.25f)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
// Shows bleeding message when bleeding below 0.25x the max cap
|
||||
else if (ent.Comp.BleedAmount > 0)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-slight-bleeding", ("target", ent.Owner)));
|
||||
}
|
||||
|
||||
// If the mob's blood level is below the damage threshhold, the pale message is added.
|
||||
if (GetBloodLevelPercentage(ent.AsNullable()) < ent.Comp.BloodlossThreshold)
|
||||
{
|
||||
args.Message.PushNewline();
|
||||
args.Message.AddMarkupOrThrow(Loc.GetString("bloodstream-component-looks-pale", ("target", ent.Owner)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBeingGibbed(Entity<BloodstreamComponent> ent, ref BeingGibbedEvent args)
|
||||
{
|
||||
SpillAllSolutions(ent.AsNullable());
|
||||
}
|
||||
|
||||
private void OnApplyMetabolicMultiplier(Entity<BloodstreamComponent> ent, ref ApplyMetabolicMultiplierEvent args)
|
||||
{
|
||||
// TODO REFACTOR THIS
|
||||
// This will slowly drift over time due to floating point errors.
|
||||
// Instead, raise an event with the base rates and allow modifiers to get applied to it.
|
||||
if (args.Apply)
|
||||
ent.Comp.UpdateInterval *= args.Multiplier;
|
||||
else
|
||||
ent.Comp.UpdateInterval /= args.Multiplier;
|
||||
|
||||
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.UpdateInterval));
|
||||
}
|
||||
|
||||
private void OnRejuvenate(Entity<BloodstreamComponent> ent, ref RejuvenateEvent args)
|
||||
{
|
||||
TryModifyBleedAmount(ent.AsNullable(), -ent.Comp.BleedAmount);
|
||||
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodSolutionName, ref ent.Comp.BloodSolution, out var bloodSolution))
|
||||
TryModifyBloodLevel(ent.AsNullable(), bloodSolution.AvailableVolume);
|
||||
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.ChemicalSolutionName, ref ent.Comp.ChemicalSolution))
|
||||
SolutionContainer.RemoveAllSolution(ent.Comp.ChemicalSolution.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current blood level as a percentage (between 0 and 1).
|
||||
/// </summary>
|
||||
public float GetBloodLevelPercentage(Entity<BloodstreamComponent?> ent)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp)
|
||||
|| !SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodSolutionName, ref ent.Comp.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return bloodSolution.FillFraction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setter for the BloodlossThreshold datafield.
|
||||
/// </summary>
|
||||
public void SetBloodLossThreshold(Entity<BloodstreamComponent?> ent, float threshold)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
|
||||
ent.Comp.BloodlossThreshold = threshold;
|
||||
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.BloodlossThreshold));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to transfer a provided solution to internal solution.
|
||||
/// </summary>
|
||||
public bool TryAddToChemicals(Entity<BloodstreamComponent?> ent, Solution solution)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, logMissing: false)
|
||||
|| !SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.ChemicalSolutionName, ref ent.Comp.ChemicalSolution))
|
||||
return false;
|
||||
|
||||
if (SolutionContainer.TryAddSolution(ent.Comp.ChemicalSolution.Value, solution))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a certain amount of all reagents except of a single excluded one from the bloodstream.
|
||||
/// </summary>
|
||||
public bool FlushChemicals(Entity<BloodstreamComponent?> ent, ProtoId<ReagentPrototype>? excludedReagentID, FixedPoint2 quantity)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, logMissing: false)
|
||||
|| !SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.ChemicalSolutionName, ref ent.Comp.ChemicalSolution, out var chemSolution))
|
||||
return false;
|
||||
|
||||
for (var i = chemSolution.Contents.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var (reagentId, _) = chemSolution.Contents[i];
|
||||
if (reagentId.Prototype != excludedReagentID)
|
||||
{
|
||||
SolutionContainer.RemoveReagent(ent.Comp.ChemicalSolution.Value, reagentId, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to modify the blood level of this entity directly.
|
||||
/// </summary>
|
||||
public bool TryModifyBloodLevel(Entity<BloodstreamComponent?> ent, FixedPoint2 amount)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, logMissing: false)
|
||||
|| !SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodSolutionName, ref ent.Comp.BloodSolution))
|
||||
return false;
|
||||
|
||||
if (amount >= 0)
|
||||
return SolutionContainer.TryAddReagent(ent.Comp.BloodSolution.Value, ent.Comp.BloodReagent, amount, null, GetEntityBloodData(ent));
|
||||
|
||||
// Removal is more involved,
|
||||
// since we also wanna handle moving it to the temporary solution
|
||||
// and then spilling it if necessary.
|
||||
var newSol = SolutionContainer.SplitSolution(ent.Comp.BloodSolution.Value, -amount);
|
||||
|
||||
if (!SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodTemporarySolutionName, ref ent.Comp.TemporarySolution, out var tempSolution))
|
||||
return true;
|
||||
|
||||
tempSolution.AddSolution(newSol, _prototypeManager);
|
||||
|
||||
if (tempSolution.Volume > ent.Comp.BleedPuddleThreshold)
|
||||
{
|
||||
// Pass some of the chemstream into the spilled blood.
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.ChemicalSolutionName, ref ent.Comp.ChemicalSolution))
|
||||
{
|
||||
var temp = SolutionContainer.SplitSolution(ent.Comp.ChemicalSolution.Value, tempSolution.Volume / 10);
|
||||
tempSolution.AddSolution(temp, _prototypeManager);
|
||||
}
|
||||
|
||||
_puddle.TrySpillAt(ent.Owner, tempSolution, out _, sound: false);
|
||||
|
||||
tempSolution.RemoveAllSolution();
|
||||
}
|
||||
|
||||
SolutionContainer.UpdateChemicals(ent.Comp.TemporarySolution.Value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to make an entity bleed more or less.
|
||||
/// </summary>
|
||||
public bool TryModifyBleedAmount(Entity<BloodstreamComponent?> ent, float amount)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, logMissing: false))
|
||||
return false;
|
||||
|
||||
ent.Comp.BleedAmount += amount;
|
||||
ent.Comp.BleedAmount = Math.Clamp(ent.Comp.BleedAmount, 0, ent.Comp.MaxBleedAmount);
|
||||
|
||||
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.BleedAmount));
|
||||
|
||||
if (ent.Comp.BleedAmount == 0)
|
||||
_alertsSystem.ClearAlert(ent, ent.Comp.BleedingAlert);
|
||||
else
|
||||
{
|
||||
var severity = (short)Math.Clamp(Math.Round(ent.Comp.BleedAmount, MidpointRounding.ToZero), 0, 10);
|
||||
_alertsSystem.ShowAlert(ent, ent.Comp.BleedingAlert, severity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spill all bloodstream solutions into a puddle.
|
||||
/// BLOOD FOR THE BLOOD GOD
|
||||
/// </summary>
|
||||
public void SpillAllSolutions(Entity<BloodstreamComponent?> ent)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
|
||||
var tempSol = new Solution();
|
||||
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodSolutionName, ref ent.Comp.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
tempSol.MaxVolume += bloodSolution.MaxVolume;
|
||||
tempSol.AddSolution(bloodSolution, _prototypeManager);
|
||||
SolutionContainer.RemoveAllSolution(ent.Comp.BloodSolution.Value);
|
||||
}
|
||||
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.ChemicalSolutionName, ref ent.Comp.ChemicalSolution, out var chemSolution))
|
||||
{
|
||||
tempSol.MaxVolume += chemSolution.MaxVolume;
|
||||
tempSol.AddSolution(chemSolution, _prototypeManager);
|
||||
SolutionContainer.RemoveAllSolution(ent.Comp.ChemicalSolution.Value);
|
||||
}
|
||||
|
||||
if (SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodTemporarySolutionName, ref ent.Comp.TemporarySolution, out var tempSolution))
|
||||
{
|
||||
tempSol.MaxVolume += tempSolution.MaxVolume;
|
||||
tempSol.AddSolution(tempSolution, _prototypeManager);
|
||||
SolutionContainer.RemoveAllSolution(ent.Comp.TemporarySolution.Value);
|
||||
}
|
||||
|
||||
_puddle.TrySpillAt(ent, tempSol, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change what someone's blood is made of, on the fly.
|
||||
/// </summary>
|
||||
public void ChangeBloodReagent(Entity<BloodstreamComponent?> ent, ProtoId<ReagentPrototype> reagent)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, logMissing: false)
|
||||
|| reagent == ent.Comp.BloodReagent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SolutionContainer.ResolveSolution(ent.Owner, ent.Comp.BloodSolutionName, ref ent.Comp.BloodSolution, out var bloodSolution))
|
||||
{
|
||||
ent.Comp.BloodReagent = reagent;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentVolume = bloodSolution.RemoveReagent(ent.Comp.BloodReagent, bloodSolution.Volume, ignoreReagentData: true);
|
||||
|
||||
ent.Comp.BloodReagent = reagent;
|
||||
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.BloodReagent));
|
||||
|
||||
if (currentVolume > 0)
|
||||
SolutionContainer.TryAddReagent(ent.Comp.BloodSolution.Value, ent.Comp.BloodReagent, currentVolume, null, GetEntityBloodData(ent));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the reagent data for blood that a specific entity should have.
|
||||
/// </summary>
|
||||
public List<ReagentData> GetEntityBloodData(EntityUid uid)
|
||||
{
|
||||
var bloodData = new List<ReagentData>();
|
||||
var dnaData = new DnaData();
|
||||
|
||||
if (TryComp<DnaComponent>(uid, out var donorComp) && donorComp.DNA != null)
|
||||
dnaData.DNA = donorComp.DNA;
|
||||
else
|
||||
dnaData.DNA = Loc.GetString("forensics-dna-unknown");
|
||||
|
||||
bloodData.Add(dnaData);
|
||||
|
||||
return bloodData;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Body.Organ;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.Hypospray.Events;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -77,6 +78,11 @@ namespace Content.Shared.Damage
|
||||
[JsonIgnore]
|
||||
public bool Empty => DamageDict.Count == 0;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "DamageSpecifier(" + string.Join("; ", DamageDict.Select(x => x.Key + ":" + x.Value)) + ")";
|
||||
}
|
||||
|
||||
#region constructors
|
||||
/// <summary>
|
||||
/// Constructor that just results in an empty dictionary.
|
||||
|
||||
@@ -353,7 +353,7 @@ namespace Content.Shared.Damage
|
||||
|
||||
// Has the damage actually changed?
|
||||
DamageSpecifier newDamage = new() { DamageDict = new(state.DamageDict) };
|
||||
var delta = component.Damage - newDamage;
|
||||
var delta = newDamage - component.Damage;
|
||||
delta.TrimZeros();
|
||||
|
||||
if (!delta.Empty)
|
||||
|
||||
65
Content.Shared/Medical/Healing/HealingComponent.cs
Normal file
65
Content.Shared/Medical/Healing/HealingComponent.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Medical.Healing;
|
||||
|
||||
/// <summary>
|
||||
/// Applies a damage change to the target when used in an interaction.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class HealingComponent : Component
|
||||
{
|
||||
/// <remarks>
|
||||
/// The amount of damage to heal per use.
|
||||
/// </remarks>
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
/// <remarks>
|
||||
/// This should generally be negative,
|
||||
/// since you're, like, trying to heal damage.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float BloodlossModifier = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Restore missing blood.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float ModifyBloodLevel = 0.0f;
|
||||
|
||||
/// <remarks>
|
||||
/// The supported damage types are specified using a <see cref="DamageContainerPrototype"/>s. For a
|
||||
/// HealingComponent this filters what damage container type this component should work on. If null,
|
||||
/// all damage container types are supported.
|
||||
/// </remarks>
|
||||
[DataField, AutoNetworkedField]
|
||||
public List<ProtoId<DamageContainerPrototype>>? DamageContainers;
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to apply the damage.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float Delay = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Delay multiplier when healing yourself.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float SelfHealPenaltyMultiplier = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Sound played on healing begin.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? HealingBeginSound = null;
|
||||
|
||||
/// <summary>
|
||||
/// Sound played on healing end.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? HealingEndSound = null;
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Medical.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Systems;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
@@ -12,77 +9,74 @@ using Content.Shared.FixedPoint;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Medical;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Stacks;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Medical;
|
||||
namespace Content.Shared.Medical.Healing;
|
||||
|
||||
public sealed class HealingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
||||
[Dependency] private readonly SharedBloodstreamSystem _bloodstreamSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly StackSystem _stacks = default!;
|
||||
[Dependency] private readonly SharedStackSystem _stacks = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HealingComponent, UseInHandEvent>(OnHealingUse);
|
||||
SubscribeLocalEvent<HealingComponent, AfterInteractEvent>(OnHealingAfterInteract);
|
||||
SubscribeLocalEvent<DamageableComponent, HealingDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
private void OnDoAfter(Entity<DamageableComponent> entity, ref HealingDoAfterEvent args)
|
||||
private void OnDoAfter(Entity<DamageableComponent> target, ref HealingDoAfterEvent args)
|
||||
{
|
||||
var dontRepeat = false;
|
||||
|
||||
if (!TryComp(args.Used, out HealingComponent? healing))
|
||||
return;
|
||||
|
||||
if (args.Handled || args.Cancelled)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Used, out HealingComponent? healing))
|
||||
return;
|
||||
|
||||
if (healing.DamageContainers is not null &&
|
||||
entity.Comp.DamageContainerID is not null &&
|
||||
!healing.DamageContainers.Contains(entity.Comp.DamageContainerID))
|
||||
target.Comp.DamageContainerID is not null &&
|
||||
!healing.DamageContainers.Contains(target.Comp.DamageContainerID.Value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryComp<BloodstreamComponent>(target, out var bloodstream);
|
||||
|
||||
// Heal some bloodloss damage.
|
||||
if (healing.BloodlossModifier != 0)
|
||||
if (healing.BloodlossModifier != 0 && bloodstream != null)
|
||||
{
|
||||
if (!TryComp<BloodstreamComponent>(entity, out var bloodstream))
|
||||
return;
|
||||
var isBleeding = bloodstream.BleedAmount > 0;
|
||||
_bloodstreamSystem.TryModifyBleedAmount(entity.Owner, healing.BloodlossModifier);
|
||||
_bloodstreamSystem.TryModifyBleedAmount((target.Owner, bloodstream), healing.BloodlossModifier);
|
||||
if (isBleeding != bloodstream.BleedAmount > 0)
|
||||
{
|
||||
var popup = (args.User == entity.Owner)
|
||||
var popup = (args.User == target.Owner)
|
||||
? Loc.GetString("medical-item-stop-bleeding-self")
|
||||
: Loc.GetString("medical-item-stop-bleeding", ("target", Identity.Entity(entity.Owner, EntityManager)));
|
||||
_popupSystem.PopupEntity(popup, entity, args.User);
|
||||
: Loc.GetString("medical-item-stop-bleeding", ("target", Identity.Entity(target.Owner, EntityManager)));
|
||||
_popupSystem.PopupClient(popup, target, args.User);
|
||||
}
|
||||
}
|
||||
|
||||
// Restores missing blood
|
||||
if (healing.ModifyBloodLevel != 0)
|
||||
_bloodstreamSystem.TryModifyBloodLevel(entity.Owner, healing.ModifyBloodLevel);
|
||||
if (healing.ModifyBloodLevel != 0 && bloodstream != null)
|
||||
_bloodstreamSystem.TryModifyBloodLevel((target.Owner, bloodstream), healing.ModifyBloodLevel);
|
||||
|
||||
var healed = _damageable.TryChangeDamage(entity.Owner, healing.Damage * _damageable.UniversalTopicalsHealModifier, true, origin: args.Args.User);
|
||||
var healed = _damageable.TryChangeDamage(target.Owner, healing.Damage * _damageable.UniversalTopicalsHealModifier, true, origin: args.Args.User);
|
||||
|
||||
if (healed == null && healing.BloodlossModifier != 0)
|
||||
return;
|
||||
@@ -90,7 +84,7 @@ public sealed class HealingSystem : EntitySystem
|
||||
var total = healed?.GetTotal() ?? FixedPoint2.Zero;
|
||||
|
||||
// Re-verify that we can heal the damage.
|
||||
|
||||
var dontRepeat = false;
|
||||
if (TryComp<StackComponent>(args.Used.Value, out var stackComp))
|
||||
{
|
||||
_stacks.Use(args.Used.Value, 1, stackComp);
|
||||
@@ -100,13 +94,13 @@ public sealed class HealingSystem : EntitySystem
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueDel(args.Used.Value);
|
||||
PredictedQueueDel(args.Used.Value);
|
||||
}
|
||||
|
||||
if (entity.Owner != args.User)
|
||||
if (target.Owner != args.User)
|
||||
{
|
||||
_adminLogger.Add(LogType.Healed,
|
||||
$"{ToPrettyString(args.User):user} healed {ToPrettyString(entity.Owner):target} for {total:damage} damage");
|
||||
$"{ToPrettyString(args.User):user} healed {ToPrettyString(target.Owner):target} for {total:damage} damage");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -114,19 +108,19 @@ public sealed class HealingSystem : EntitySystem
|
||||
$"{ToPrettyString(args.User):user} healed themselves for {total:damage} damage");
|
||||
}
|
||||
|
||||
_audio.PlayPvs(healing.HealingEndSound, entity.Owner);
|
||||
_audio.PlayPredicted(healing.HealingEndSound, target.Owner, args.User);
|
||||
|
||||
// Logic to determine the whether or not to repeat the healing action
|
||||
args.Repeat = (HasDamage(entity, healing) && !dontRepeat);
|
||||
args.Repeat = HasDamage((args.Used.Value, healing), target) && !dontRepeat;
|
||||
if (!args.Repeat && !dontRepeat)
|
||||
_popupSystem.PopupEntity(Loc.GetString("medical-item-finished-using", ("item", args.Used)), entity.Owner, args.User);
|
||||
_popupSystem.PopupClient(Loc.GetString("medical-item-finished-using", ("item", args.Used)), target.Owner, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private bool HasDamage(Entity<DamageableComponent> ent, HealingComponent healing)
|
||||
private bool HasDamage(Entity<HealingComponent> healing, Entity<DamageableComponent> target)
|
||||
{
|
||||
var damageableDict = ent.Comp.Damage.DamageDict;
|
||||
var healingDict = healing.Damage.DamageDict;
|
||||
var damageableDict = target.Comp.Damage.DamageDict;
|
||||
var healingDict = healing.Comp.Damage.DamageDict;
|
||||
foreach (var type in healingDict)
|
||||
{
|
||||
if (damageableDict[type.Key].Value > 0)
|
||||
@@ -135,18 +129,18 @@ public sealed class HealingSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
if (TryComp<BloodstreamComponent>(ent, out var bloodstream))
|
||||
if (TryComp<BloodstreamComponent>(target, out var bloodstream))
|
||||
{
|
||||
// Is ent missing blood that we can restore?
|
||||
if (healing.ModifyBloodLevel > 0
|
||||
&& _solutionContainerSystem.ResolveSolution(ent.Owner, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
|
||||
if (healing.Comp.ModifyBloodLevel > 0
|
||||
&& _solutionContainerSystem.ResolveSolution(target.Owner, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
|
||||
&& bloodSolution.Volume < bloodSolution.MaxVolume)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is ent bleeding and can we stop it?
|
||||
if (healing.BloodlossModifier < 0 && bloodstream.BleedAmount > 0)
|
||||
if (healing.Comp.BloodlossModifier < 0 && bloodstream.BleedAmount > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -155,64 +149,64 @@ public sealed class HealingSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnHealingUse(Entity<HealingComponent> entity, ref UseInHandEvent args)
|
||||
private void OnHealingUse(Entity<HealingComponent> healing, ref UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (TryHeal(entity, args.User, args.User, entity.Comp))
|
||||
if (TryHeal(healing, args.User, args.User))
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnHealingAfterInteract(Entity<HealingComponent> entity, ref AfterInteractEvent args)
|
||||
private void OnHealingAfterInteract(Entity<HealingComponent> healing, ref AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach || args.Target == null)
|
||||
return;
|
||||
|
||||
if (TryHeal(entity, args.User, args.Target.Value, entity.Comp))
|
||||
if (TryHeal(healing, args.Target.Value, args.User))
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private bool TryHeal(EntityUid uid, EntityUid user, EntityUid target, HealingComponent component)
|
||||
private bool TryHeal(Entity<HealingComponent> healing, Entity<DamageableComponent?> target, EntityUid user)
|
||||
{
|
||||
if (!TryComp<DamageableComponent>(target, out var targetDamage))
|
||||
if (!Resolve(target, ref target.Comp, false))
|
||||
return false;
|
||||
|
||||
if (component.DamageContainers is not null &&
|
||||
targetDamage.DamageContainerID is not null &&
|
||||
!component.DamageContainers.Contains(targetDamage.DamageContainerID))
|
||||
if (healing.Comp.DamageContainers is not null &&
|
||||
target.Comp.DamageContainerID is not null &&
|
||||
!healing.Comp.DamageContainers.Contains(target.Comp.DamageContainerID.Value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user != target && !_interactionSystem.InRangeUnobstructed(user, target, popup: true))
|
||||
if (user != target.Owner && !_interactionSystem.InRangeUnobstructed(user, target.Owner, popup: true))
|
||||
return false;
|
||||
|
||||
if (TryComp<StackComponent>(uid, out var stack) && stack.Count < 1)
|
||||
if (TryComp<StackComponent>(healing, out var stack) && stack.Count < 1)
|
||||
return false;
|
||||
|
||||
if (!HasDamage((target, targetDamage), component))
|
||||
if (!HasDamage(healing, target!))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use", ("item", uid)), uid, user);
|
||||
_popupSystem.PopupClient(Loc.GetString("medical-item-cant-use", ("item", healing.Owner)), healing, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
_audio.PlayPvs(component.HealingBeginSound, uid);
|
||||
_audio.PlayPredicted(healing.Comp.HealingBeginSound, healing, user);
|
||||
|
||||
var isNotSelf = user != target;
|
||||
var isNotSelf = user != target.Owner;
|
||||
|
||||
if (isNotSelf)
|
||||
{
|
||||
var msg = Loc.GetString("medical-item-popup-target", ("user", Identity.Entity(user, EntityManager)), ("item", uid));
|
||||
var msg = Loc.GetString("medical-item-popup-target", ("user", Identity.Entity(user, EntityManager)), ("item", healing.Owner));
|
||||
_popupSystem.PopupEntity(msg, target, target, PopupType.Medium);
|
||||
}
|
||||
|
||||
var delay = isNotSelf
|
||||
? component.Delay
|
||||
: component.Delay * GetScaledHealingPenalty(user, component);
|
||||
? healing.Comp.Delay
|
||||
: healing.Comp.Delay * GetScaledHealingPenalty(healing);
|
||||
|
||||
var doAfterEventArgs =
|
||||
new DoAfterArgs(EntityManager, user, delay, new HealingDoAfterEvent(), target, target: target, used: uid)
|
||||
new DoAfterArgs(EntityManager, user, delay, new HealingDoAfterEvent(), target, target: target, used: healing)
|
||||
{
|
||||
// Didn't break on damage as they may be trying to prevent it and
|
||||
// not being able to heal your own ticking damage would be frustrating.
|
||||
@@ -231,18 +225,18 @@ public sealed class HealingSystem : EntitySystem
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="component"></param>
|
||||
/// <returns></returns>
|
||||
public float GetScaledHealingPenalty(EntityUid uid, HealingComponent component)
|
||||
public float GetScaledHealingPenalty(Entity<HealingComponent> healing)
|
||||
{
|
||||
var output = component.Delay;
|
||||
if (!TryComp<MobThresholdsComponent>(uid, out var mobThreshold) ||
|
||||
!TryComp<DamageableComponent>(uid, out var damageable))
|
||||
var output = healing.Comp.Delay;
|
||||
if (!TryComp<MobThresholdsComponent>(healing, out var mobThreshold) ||
|
||||
!TryComp<DamageableComponent>(healing, out var damageable))
|
||||
return output;
|
||||
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var amount, mobThreshold))
|
||||
if (!_mobThresholdSystem.TryGetThresholdForState(healing, MobState.Critical, out var amount, mobThreshold))
|
||||
return 1;
|
||||
|
||||
var percentDamage = (float) (damageable.TotalDamage / amount);
|
||||
var percentDamage = (float)(damageable.TotalDamage / amount);
|
||||
//basically make it scale from 1 to the multiplier.
|
||||
var modifier = percentDamage * (component.SelfHealPenaltyMultiplier - 1) + 1;
|
||||
var modifier = percentDamage * (healing.Comp.SelfHealPenaltyMultiplier - 1) + 1;
|
||||
return Math.Max(modifier, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
medical-item-finished-using = You have finished healing with the {$item}
|
||||
medical-item-cant-use = There is no damage you can heal with the {$item}
|
||||
medical-item-stop-bleeding = {CAPITALIZE($target)} has stopped bleeding
|
||||
medical-item-stop-bleeding-self = You have stopped bleeding
|
||||
medical-item-finished-using = You have finished healing with the {$item}.
|
||||
medical-item-cant-use = There is no damage you can heal with the {$item}.
|
||||
medical-item-stop-bleeding = {CAPITALIZE($target)} has stopped bleeding.
|
||||
medical-item-stop-bleeding-self = You have stopped bleeding.
|
||||
medical-item-popup-target = {CAPITALIZE(THE($user))} is trying to heal you with the {$item}!
|
||||
|
||||
@@ -257,7 +257,7 @@
|
||||
damage:
|
||||
types:
|
||||
Bloodloss: -0.5 #lowers bloodloss damage
|
||||
ModifyBloodLevel: 15 #restores about 5% blood per use on standard humanoids.
|
||||
modifyBloodLevel: 15 #restores about 5% blood per use on standard humanoids.
|
||||
healingBeginSound:
|
||||
path: "/Audio/Items/Medical/brutepack_begin.ogg"
|
||||
params:
|
||||
|
||||
Reference in New Issue
Block a user