mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-02 17:17:25 +00:00
* Fix the sensor monitoring console forcing a GC every 3 seconds (#38146) * Optimize sensor monitoring window graph drawing * Add shared static Vector2 pool for all GraphView instances * Address requested changes * remove lock * Update submodule to 264.0.0 (#38629) * Toy/Plushie Inhands and Wearables (#38514) * Fixed dependency injection and some other issues in a few places. * More issue fixes * patchfor broken NetworkConfiguratorLinkMenu (#38632) fix * Fix solutions flickering when transferring contents (#34838) * Use Solution clones when applying SolutionComponent states * Revert "Use Solution clones when applying SolutionComponent states" This reverts commit 013fd111cf92b22562e00f98a7aaa49bc4b4ed62. * Make Solution implement ICloneable and rename Clone method. * Copy CanReact value when cloning a Solution * Convert to IRobustCloneable * Fix typos in guidebook: Buisness → Business (#38636) * Fix typo in `MinorAntagonists.xml` Buisness → Business * Fix typo in `YourFirstCharacter.xml` Buisness → Business * Various Headphones Fixes and Tweaks (#38479) * sprites, wearables * neck * icon-on sprite * Cleanup prototype instantiation in `DamageTest` (#38639) Cleanup prototype instantiation in DamageTest * Cleanup prototype instantiation in `ExplosionSystem` (#38642) Cleanup prototype instantiation in ExplosionSystem * AddBodyPartCommand localization. (#38612) commit * fix ItemSlotsSystem debug assert (#38655) * Allow the Command & Super door remotes to use the access of their user. (Re-creation of PR due to changes to game balance) (#35536) * Added directional beacons (#38284) * Added directional beacons Signed-off-by: Nox38 <nebulousnox38@gmail.com> * Fixed names Signed-off-by: Nox38 <nebulousnox38@gmail.com> --------- Signed-off-by: Nox38 <nebulousnox38@gmail.com> * Power stat and nuke codes commands get some LEC love. (#38585) * commit * requested changes. * Dsay Dirty and Follow commands converted to LEC and localized. (#38666) * commit * whoopwhoopwhoop * Retro laser sprite fix (#38676) * Fixed everything except the icon Signed-off-by: Nox38 <nebulousnox38@gmail.com> * fixed icon Signed-off-by: Nox38 <nebulousnox38@gmail.com> --------- Signed-off-by: Nox38 <nebulousnox38@gmail.com> * fix water coolers (#38681) * Monochromacy typo fix (#38686) * fixes the typo * Fixed cloning looking for the trait, not the component, RE https://github.com/space-wizards/space-station-14/pull/38686#issuecomment-3025093504 * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Validate `CloningSettingsPrototype`s (#38688) * Validate CloningSettingsPrototypes * Update Content.IntegrationTests/Tests/Cloning/CloningSettingsPrototypeTest.cs Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Check EventComponents too --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Add test of objective-related console commands (#36400) * Add test of objective add/list/remove commands * Not sure why we're validating test prototypes, but sure * We don't need a map * Improvements and fixups for New Status Effect API (#38660) * 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 * Healing and bloodstream prediction fixes. * Resolving Wizard casting recall on nuke disk making it impossible to disarm (#38661) * Resolving Wizard Recall on Nuke disk making it impossible to disarm - Adding a DisarmBomb case to nuke status update loop - Changing a few methods and parameters to properly follow formatting standards - Updating some names to follow camelCase * Updating missed tag * Reverting DataField change Should prevent this preventative bugfix being a breaking change. * Switch HSV to the default colorspace for character customization (#38434) * Made HSV default for character editor * Adds/fixes comments to HSV defaulting * Added dropbox fix, potentially cursed * Revert "Added dropbox fix, potentially cursed" This reverts commit a709883366fbee813e839742125e70844672af29. --------- Co-authored-by: TrixxedHeart <46364955+TrixxedBit@users.noreply.github.com> * Fix: Don't deploy foldables when clicking on items inside containers (#38709) * Fix * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Pressure Relief Valve (#36708) * initial system (this math is probably WRONG) * General code cleanup and OnExamined support (holy moly this code sucks) * UICode and related events foundation TODO: - Actually write the XAML UI and the underlying system - Un-shitcode the entire thing - Actually test everything... * Working UI code TODO: Make predicted, as this certainly isn't predicted. Even though I said it was. It isn't. * Remove one TODO for unshitcoding the examine code * Add reminder yea * Make predicted (defenitely isn't) (also defenitely isn't a copypaste from pressure pump code) * It's predicted! TODO: - Give it snazzy predicted visuals! - Have a different field for pressure entry, lest it gets bulldozed every UI update. * Improve gas pressure relief valve UI TODO: Reminder to reduce amount of dirties using deltafields * Implement DirtyField prediction * Entity<T> cleanup A lot of Entity<T> conversions and lukewarm cleanup. Also got caught copy pasting code in 4K UHD but it's not like you couldn't tell. * More cleanup and comments * Remove TODO comment on bulldozing window title * """refactoring""" - Move appearance out of shared and finally fix it. Pointless to predict appearance in this instance. - More Entity<T> conversions because I like them. - Move UI creation handling over entirely to the ActivatableUI system. - Fix a hardcoded locale string (why????). * Add visuals * Revert debugging variable replacememt yea * Revert skissue * Remove unused using directives and remove TODO * Localize, cleanup, document * Fix adminlogging discrepancy * Add ability to construct, add guidebook entry * Clear up comment * Add guidebook tooltip to valve * Convert GasPressureReliefValveBoundUserInterface declaration into primary constructor * Adds more input handling and adds autofill on open * Un-deepfry input validator shitcode Genuinely what was I smoking * improve visuals logic * Refactor again - Update math to the correct implementation - Moved code that could be re-used in the future into a helper method under AtmosphereSystem.Gases.cs * I'm sorry but I hate warnings * Remove unused using directive in AtmosphereSystem.Gases.cs * Review and cleanup * Lukewarm UI glossup * Maintainer for the upstream project btw * Remove redundant state sets and messy logic * Unduplicate valve updater code * Redo UI (im sorry Slarti) * run tests * Test refactored UI messaging * Second round of UI improvements - God please find a way to improve this system. Feels bad. * Update loop implementation * Further predict UI * Clear up SetToCurrentThreshold * cleanup * Update to master + pipe layers and bug fixes want to run tests * fixes * Deploy rename pipebomb * Documentation and requested changes * Rename the method that wiggled away * Undo rounding changes * Fix comment * Rename and cleanup * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Fix TextLinkTag (#32203) * Adjust uplink buy button to be under item icon (#38596) * Adjusted uplink buy button to be under item icon * Put the discount subtext under the icon * Indent fixes, added margin --------- Co-authored-by: TrixxedHeart <46364955+TrixxedBit@users.noreply.github.com> * Scurrets - Audio Improvements (#38482) * Scurret audio tuning * Add new sfx * Update sneezing sfx * YAML support * Rename a folder * make telesci wreck easier (#37569) rel * Validate `ShaderPrototype` IDs (#38728) * Convert all shader prototype string literals to protoids in overlays * Convert more shader prototype literal strings to protoids * Convert ValidatePrototypeId to ProtoId * Later * [BUGFIX] Fixed revenant malfunction ability not working properly only MediBots and Stasis bed (#38664) * fixed * clean up * orks fix smart * review fix 1 * more requested changes * less cursed * more descriptive description * better wording * Tiny Tiny Cleanup of the EyeClosingSystem. (#38734) Update EyeClosingSystem.cs * Fix human skin tone distribution (#38701) * fix: Use PredictedQueueDel for gib spell (#38729) * fix: don't default to uncharged sprite state for cells (#38730) * Fix Hristov description - remove inaccurate technical specs (#38746) - Removes inaccurate 'armor piercing 14.5mm shells' reference - Replaces it with a more funny description, matching the style of the other snipers and guns - Keeps ammunition type '.60 anti-materiel ammo' specification - Fixes issue #38590 Co-authored-by: Arthur Fiorese de Andrade <aandrade@cmcxs.gov.br> * feat: allow mopping evaporating puddles (#38743) * Validate remaining `ProtoId` strings (#38747) Validate remaining ProtoId strings * Validate `ProtoId`s in tests (#38745) * Convert string literals to protoids in Content.Tests * Convert string literals to protoids or consts in Content.IntegrationTests * Fix linter failures Tricksy static using misled me * Cleanup warning in StomachSystem (#38748) you did not see this * Vox scars (#38592) * Added vox scars n'stuff, renamed vox_tattoos.ftl to just vox.ftl * Revert "Added vox scars n'stuff, renamed vox_tattoos.ftl to just vox.ftl" This reverts commit c73da55ba3b39ddf93b493aecd85604c54dd8a15. * locale key fix * Changed top surgery scar names to be more generalized * Adjusted face scars * Formatting fixes --------- Co-authored-by: TrixxedHeart <46364955+TrixxedBit@users.noreply.github.com> * UnlockNode command to LEC. (#38751) * commit * Update UnlockNodeCommand.cs * commit * move command locale to its own file. * Update Content.Server/Xenoarchaeology/Artifact/UnlockNodeCommand.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Typofixes for figurine dialogue (#38737) * Typofixes for figurine dialogue * Forgot two * Janitor Tool: Wire Brush (#38667) * Wow! It's -brush- * spacing. * Update Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * fixed changes --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Minor escape menu UX improvements (#38650) * fix: spellbooks can have infinite charges (#38376) * fix: spellbooks can have infinite charges * refactor: indicate infinite spellbook charges with null Not sure if I like this much better...
514 lines
23 KiB
C#
514 lines
23 KiB
C#
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.Random.Helpers;
|
|
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.AdjustedUpdateInterval;
|
|
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.AdjustedUpdateInterval.TotalSeconds * 2,
|
|
applySlur: false);
|
|
_stutteringSystem.DoStutter(uid, bloodstream.AdjustedUpdateInterval * 2, refresh: false);
|
|
|
|
// storing the drunk and stutter time so we can remove it independently from other effects additions
|
|
bloodstream.StatusTime += bloodstream.AdjustedUpdateInterval * 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.AdjustedUpdateInterval;
|
|
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 = SharedRandomExtensions.HashCodeCombine(new() { (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)
|
|
{
|
|
ent.Comp.UpdateIntervalMultiplier = args.Multiplier;
|
|
DirtyField(ent, ent.Comp, nameof(BloodstreamComponent.UpdateIntervalMultiplier));
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|