2022-02-07 14:14:45 +11:00
|
|
|
using Content.Server.Administration.Logs;
|
2023-04-23 23:34:18 -05:00
|
|
|
using Content.Server.Body.Components;
|
2022-02-17 15:00:41 -07:00
|
|
|
using Content.Server.Body.Systems;
|
2022-02-07 14:14:45 +11:00
|
|
|
using Content.Server.Medical.Components;
|
|
|
|
|
using Content.Server.Stack;
|
2022-02-27 10:02:00 +03:00
|
|
|
using Content.Shared.Audio;
|
2022-02-07 14:14:45 +11:00
|
|
|
using Content.Shared.Damage;
|
|
|
|
|
using Content.Shared.Database;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.DoAfter;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.FixedPoint;
|
2022-02-07 14:14:45 +11:00
|
|
|
using Content.Shared.Interaction;
|
2022-03-13 01:33:23 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.Medical;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs;
|
|
|
|
|
using Content.Shared.Mobs.Components;
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
2022-02-07 14:14:45 +11:00
|
|
|
using Content.Shared.Stacks;
|
2023-04-23 23:34:18 -05:00
|
|
|
using Content.Server.Popups;
|
2022-09-29 03:12:16 -04:00
|
|
|
using Robust.Shared.Random;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
|
|
|
|
namespace Content.Server.Medical;
|
|
|
|
|
|
|
|
|
|
public sealed class HealingSystem : EntitySystem
|
|
|
|
|
{
|
2022-09-29 03:12:16 -04:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
2022-05-28 23:41:17 -07:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
2022-02-07 14:14:45 +11:00
|
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
2022-02-17 15:00:41 -07:00
|
|
|
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
2023-04-03 13:13:48 +12:00
|
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
2022-09-29 03:12:16 -04:00
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2022-02-07 14:14:45 +11:00
|
|
|
[Dependency] private readonly StackSystem _stacks = default!;
|
2022-02-17 15:40:03 +13:00
|
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
2023-01-13 16:57:10 -08:00
|
|
|
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
2023-04-23 23:34:18 -05:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<HealingComponent, UseInHandEvent>(OnHealingUse);
|
|
|
|
|
SubscribeLocalEvent<HealingComponent, AfterInteractEvent>(OnHealingAfterInteract);
|
2023-04-03 13:13:48 +12:00
|
|
|
SubscribeLocalEvent<DamageableComponent, HealingDoAfterEvent>(OnDoAfter);
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
private void OnDoAfter(EntityUid uid, DamageableComponent component, HealingDoAfterEvent args)
|
2022-02-07 14:14:45 +11:00
|
|
|
{
|
2023-04-23 23:34:18 -05:00
|
|
|
var dontRepeat = false;
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (!TryComp(args.Used, out HealingComponent? healing))
|
2023-02-26 00:33:06 -05:00
|
|
|
return;
|
|
|
|
|
|
2023-05-02 20:10:19 -04:00
|
|
|
if (args.Handled || args.Cancelled)
|
2022-04-16 23:29:31 -07:00
|
|
|
return;
|
|
|
|
|
|
2023-06-03 15:30:20 -04:00
|
|
|
if (healing.DamageContainers is not null &&
|
|
|
|
|
component.DamageContainerID is not null &&
|
|
|
|
|
!healing.DamageContainers.Contains(component.DamageContainerID))
|
|
|
|
|
{
|
2022-09-29 03:12:16 -04:00
|
|
|
return;
|
2023-06-03 15:30:20 -04:00
|
|
|
}
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
// Heal some bloodloss damage.
|
2023-04-03 13:13:48 +12:00
|
|
|
if (healing.BloodlossModifier != 0)
|
2023-04-23 23:34:18 -05:00
|
|
|
{
|
|
|
|
|
if (!TryComp<BloodstreamComponent>(uid, out var bloodstream))
|
|
|
|
|
return;
|
|
|
|
|
var isBleeding = bloodstream.BleedAmount > 0;
|
2023-04-03 13:13:48 +12:00
|
|
|
_bloodstreamSystem.TryModifyBleedAmount(uid, healing.BloodlossModifier);
|
2023-04-23 23:34:18 -05:00
|
|
|
if (isBleeding != bloodstream.BleedAmount > 0)
|
|
|
|
|
{
|
|
|
|
|
dontRepeat = true;
|
2023-07-26 16:05:32 +08:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("medical-item-stop-bleeding"), uid, args.User);
|
2023-04-23 23:34:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-17 15:00:41 -07:00
|
|
|
|
The bleed update (#14814)
* Removed arbitrary modifier scaling. The bleed amount is now 1-1 in units.
* Added some comments to explain the blood and bleed code
* added some comments
* added some comments
* profusely bleeding message scales with max bleed rate
* Added some comments
* Added some comments (tm)
* Halved the speed bleed rate heals.
* Changed the wording of a comment to make the function of the values more clear
* Changed bleed rate values, made heat heal more bleed rate
* doubled crit chance, since damage types were reduced
* Made iron restore more blood, 2->4u per 1u
* Starting to add the blood pack
* add bloodlevel to healingcomponent
* Created code support in the healing system for restoring blood
* first test of blood pack prototype
* More pack testing, and defining the yml stack
* yml syntax fix
* adds bloodpack tag
* Successfully added the item, but the effect and deletion after using the item is not working yet.
* the blood regen worksgit add -A!
* blood pack is entirely functioning
* Removed bleed rate healing from brute pack
* Comment correction
* I tried
* Removed bleed stats from corrupted corgi, they inherit same stats from basemob
* Removed bleed stats from xeno, they inherit same stats from a base mob
* Removed bleed stats from diona, they inherit same stats from a base mob
* Removed bleed stats from slimes, they inherit same stats from a base mob
* All mobs now heal bloodloss damage at a rate of 1 instead of 0.25 when healthy
* The cautery now closes bleed wounds
* Nerf blood pack bleed rate heal
* Added 2 blood packs to medicine locker
* Added 2 blood packs to wall medicine locker
* Minor YML fix to chemistry locker, no changes in game
* Added tag to medical belt for blood pack, added 2 blood packs to medical belt
* Added 1 gauze to medical belt
* 5 blood packs addded to nanomed plus
* nanomed inventory change
* 2 blood packs added to medical supplies crate from cargo
* Moved 1 gauze from med kit to advanced med kit
* Moved 1 tricord pill from advanced med kit to basic med kit
* added 2 ointment to burn kit
* Moved ina syringe from burn treatment to oxygen kit
* Removed one gauze from brute kit
* Added one bloodpack to brute med kit
* Moved tranex acid syringe from advanced first aid to brute kit
* Poison medipen moved from advanced first aid kit to toxin kit
* Removed health analyzer from advanced first aid kit
* removed one brute pack from advanced aid kit
* added one ointment to advanced aid kit
* Added one blood pack to advanced aid kit
* Added 2 blood packs to combat med kit
* Starting with adding the license for the tg sprite
* Adds the blood pack sprite and meta.json code
* I forgor to actually code the sprite in
* Advanced med kit missing one blood pack
* Replaced tricord pill with emergency medipen in cobat kit
* Removed emergency pen from combat kit, there's no space for it
* Revert "I tried"
This reverts commit 94c2e28df3200993d3f09b72ecabc838ea5ae5c0.
* Trying to fix yml test fail
* Try again
* attempt number 3
* Restock crate price was too low
* fixing merge conflict without making a HUGE mess this time
* ???
* again
* again
* Can I add the newline now maybe???
* Revert "Can I add the newline now maybe???"
This reverts commit 22d26706a65a24633f7da1dea6315012e2d3ac6f.
* Adds the doafter fix code from Keron to the blood level healing
* minor typo fix
* Feedback from Emisse and sloth; Removed chance based feedback on cauterizing
* comment fix
2023-04-03 01:59:51 -04:00
|
|
|
// Restores missing blood
|
|
|
|
|
if (healing.ModifyBloodLevel != 0)
|
|
|
|
|
_bloodstreamSystem.TryModifyBloodLevel(uid, healing.ModifyBloodLevel);
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
var healed = _damageable.TryChangeDamage(uid, healing.Damage, true, origin: args.Args.User);
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (healed == null && healing.BloodlossModifier != 0)
|
2022-02-07 14:14:45 +11:00
|
|
|
return;
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
var total = healed?.Total ?? FixedPoint2.Zero;
|
2023-02-24 19:01:25 -05:00
|
|
|
|
2023-04-23 23:34:18 -05:00
|
|
|
// Re-verify that we can heal the damage.
|
2023-04-03 13:13:48 +12:00
|
|
|
_stacks.Use(args.Used.Value, 1);
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
if (_stacks.GetCount(args.Used.Value) <= 0)
|
|
|
|
|
dontRepeat = true;
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (uid != args.User)
|
2023-04-23 23:34:18 -05:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
_adminLogger.Add(LogType.Healed,
|
|
|
|
|
$"{EntityManager.ToPrettyString(args.User):user} healed {EntityManager.ToPrettyString(uid):target} for {total:damage} damage");
|
2023-04-23 23:34:18 -05:00
|
|
|
}
|
2022-02-07 14:14:45 +11:00
|
|
|
else
|
2023-04-23 23:34:18 -05:00
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
_adminLogger.Add(LogType.Healed,
|
|
|
|
|
$"{EntityManager.ToPrettyString(args.User):user} healed themselves for {total:damage} damage");
|
2023-04-23 23:34:18 -05:00
|
|
|
}
|
2022-02-27 10:02:00 +03:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
_audio.PlayPvs(healing.HealingEndSound, uid, AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f));
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-04-23 23:34:18 -05:00
|
|
|
// Logic to determine the whether or not to repeat the healing action
|
|
|
|
|
args.Repeat = (HasDamage(component, healing) && !dontRepeat);
|
|
|
|
|
if (!args.Repeat && !dontRepeat)
|
2023-07-26 16:05:32 +08:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("medical-item-finished-using", ("item", args.Used)), uid, args.User);
|
2023-02-24 19:01:25 -05:00
|
|
|
args.Handled = true;
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|
|
|
|
|
|
2023-04-23 23:34:18 -05:00
|
|
|
private bool HasDamage(DamageableComponent component, HealingComponent healing)
|
|
|
|
|
{
|
|
|
|
|
var damageableDict = component.Damage.DamageDict;
|
|
|
|
|
var healingDict = healing.Damage.DamageDict;
|
|
|
|
|
foreach (var type in healingDict)
|
|
|
|
|
{
|
|
|
|
|
if (damageableDict[type.Key].Value > 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 14:14:45 +11:00
|
|
|
private void OnHealingUse(EntityUid uid, HealingComponent component, UseInHandEvent args)
|
|
|
|
|
{
|
2022-09-29 03:12:16 -04:00
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2022-05-09 16:21:32 +10:00
|
|
|
if (TryHeal(uid, args.User, args.User, component))
|
|
|
|
|
args.Handled = true;
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnHealingAfterInteract(EntityUid uid, HealingComponent component, AfterInteractEvent args)
|
|
|
|
|
{
|
2022-09-29 03:12:16 -04:00
|
|
|
if (args.Handled || !args.CanReach || args.Target == null)
|
|
|
|
|
return;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2022-05-09 16:21:32 +10:00
|
|
|
if (TryHeal(uid, args.User, args.Target.Value, component))
|
|
|
|
|
args.Handled = true;
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|
|
|
|
|
|
2022-05-09 16:21:32 +10:00
|
|
|
private bool TryHeal(EntityUid uid, EntityUid user, EntityUid target, HealingComponent component)
|
2022-02-07 14:14:45 +11:00
|
|
|
{
|
2023-05-02 20:10:19 -04:00
|
|
|
if (!TryComp<DamageableComponent>(target, out var targetDamage))
|
2022-05-09 16:21:32 +10:00
|
|
|
return false;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-06-03 15:30:20 -04:00
|
|
|
if (component.DamageContainers is not null &&
|
|
|
|
|
targetDamage.DamageContainerID is not null &&
|
|
|
|
|
!component.DamageContainers.Contains(targetDamage.DamageContainerID))
|
|
|
|
|
{
|
2022-05-09 16:21:32 +10:00
|
|
|
return false;
|
2023-06-03 15:30:20 -04:00
|
|
|
}
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
if (user != target && !_interactionSystem.InRangeUnobstructed(user, target, popup: true))
|
2022-05-09 16:21:32 +10:00
|
|
|
return false;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-02-24 19:01:25 -05:00
|
|
|
if (!TryComp<StackComponent>(uid, out var stack) || stack.Count < 1)
|
2022-05-09 16:21:32 +10:00
|
|
|
return false;
|
2022-02-07 14:14:45 +11:00
|
|
|
|
2023-04-28 09:01:24 -05:00
|
|
|
if (!TryComp<BloodstreamComponent>(target, out var bloodstream))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!HasDamage(targetDamage, component) && !(bloodstream.BloodSolution.Volume < bloodstream.BloodSolution.MaxVolume && component.ModifyBloodLevel > 0))
|
2023-04-23 23:34:18 -05:00
|
|
|
{
|
2023-07-26 16:05:32 +08:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use", ("item", uid)), uid, user);
|
2023-04-23 23:34:18 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
_audio.PlayPvs(component.HealingBeginSound, uid,
|
2023-04-03 13:13:48 +12:00
|
|
|
AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f));
|
2022-02-27 10:02:00 +03:00
|
|
|
|
2023-02-26 00:33:06 -05:00
|
|
|
var isNotSelf = user != target;
|
|
|
|
|
|
|
|
|
|
var delay = isNotSelf
|
2022-09-29 03:12:16 -04:00
|
|
|
? component.Delay
|
|
|
|
|
: component.Delay * GetScaledHealingPenalty(user, component);
|
2022-07-14 01:24:35 -04:00
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
var doAfterEventArgs =
|
|
|
|
|
new DoAfterArgs(user, delay, new HealingDoAfterEvent(), target, target: target, used: uid)
|
|
|
|
|
{
|
|
|
|
|
//Raise the event on the target if it's not self, otherwise raise it on self.
|
|
|
|
|
BreakOnUserMove = true,
|
|
|
|
|
BreakOnTargetMove = true,
|
|
|
|
|
// 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.
|
|
|
|
|
NeedHand = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_doAfter.TryStartDoAfter(doAfterEventArgs);
|
2022-05-09 16:21:32 +10:00
|
|
|
return true;
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 03:12:16 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Scales the self-heal penalty based on the amount of damage taken
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid"></param>
|
|
|
|
|
/// <param name="component"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public float GetScaledHealingPenalty(EntityUid uid, HealingComponent component)
|
|
|
|
|
{
|
|
|
|
|
var output = component.Delay;
|
2023-04-03 13:13:48 +12:00
|
|
|
if (!TryComp<MobThresholdsComponent>(uid, out var mobThreshold) ||
|
|
|
|
|
!TryComp<DamageableComponent>(uid, out var damageable))
|
2022-09-29 03:12:16 -04:00
|
|
|
return output;
|
2023-02-24 19:01:25 -05:00
|
|
|
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var amount, mobThreshold))
|
2023-01-13 16:57:10 -08:00
|
|
|
return 1;
|
2023-02-24 19:01:25 -05:00
|
|
|
|
2022-09-29 03:12:16 -04:00
|
|
|
var percentDamage = (float) (damageable.TotalDamage / amount);
|
|
|
|
|
//basically make it scale from 1 to the multiplier.
|
|
|
|
|
var modifier = percentDamage * (component.SelfHealPenaltyMultiplier - 1) + 1;
|
|
|
|
|
return Math.Max(modifier, 1);
|
|
|
|
|
}
|
2022-02-07 14:14:45 +11:00
|
|
|
}
|