Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HealingSystem: Check bleeding or restoring blood in HasDamage. #2457

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions Content.Server/Medical/HealingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ entity.Comp.DamageContainerID is not null &&
_audio.PlayPvs(healing.HealingEndSound, entity.Owner, AudioHelpers.WithVariation(0.125f, _random).WithVolume(1f));

// Logic to determine the whether or not to repeat the healing action
args.Repeat = (HasDamage(entity.Comp, healing) && !dontRepeat);
args.Repeat = (HasDamage(entity.Owner, entity.Comp, healing) && !dontRepeat); // Frontier: add entity.Owner
if (!args.Repeat && !dontRepeat)
_popupSystem.PopupEntity(Loc.GetString("medical-item-finished-using", ("item", args.Used)), entity.Owner, args.User);
args.Handled = true;
}

private bool HasDamage(DamageableComponent component, HealingComponent healing)
private bool HasDamage(EntityUid target, DamageableComponent component, HealingComponent healing)
{
var damageableDict = component.Damage.DamageDict;
var healingDict = healing.Damage.DamageDict;
Expand All @@ -133,6 +133,25 @@ private bool HasDamage(DamageableComponent component, HealingComponent healing)
}
}

// Frontier: check if this healing item can restore the target's blood or staunch their bleeding
var hasBloodstream = TryComp<BloodstreamComponent>(target, out var bloodstream);

if (healing.ModifyBloodLevel > 0
&& hasBloodstream
&& _solutionContainerSystem.ResolveSolution(target, bloodstream!.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
&& bloodSolution.Volume < bloodSolution.MaxVolume)
{
return true;
}

if (healing.BloodlossModifier < 0
&& hasBloodstream
&& bloodstream!.BleedAmount > 0)
{
return true;
}
// End Frontier

return false;
}

Expand Down Expand Up @@ -172,14 +191,16 @@ targetDamage.DamageContainerID is not null &&
if (TryComp<StackComponent>(uid, out var stack) && stack.Count < 1)
return false;

var anythingToDo =
HasDamage(targetDamage, component) ||
component.ModifyBloodLevel > 0 // Special case if healing item can restore lost blood...
&& TryComp<BloodstreamComponent>(target, out var bloodstream)
&& _solutionContainerSystem.ResolveSolution(target, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
&& bloodSolution.Volume < bloodSolution.MaxVolume; // ...and there is lost blood to restore.
// Frontier: extra conditions moved into HasDamage
// var anythingToDo =
// HasDamage(targetDamage, component) ||
// component.ModifyBloodLevel > 0 // Special case if healing item can restore lost blood...
// && TryComp<BloodstreamComponent>(target, out var bloodstream)
// && _solutionContainerSystem.ResolveSolution(target, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
// && bloodSolution.Volume < bloodSolution.MaxVolume; // ...and there is lost blood to restore.
// End Frontier

if (!anythingToDo)
if (!HasDamage(target, targetDamage, component)) // Frontier: anythingToDo<!HasDamage
{
_popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use", ("item", uid)), uid, user);
return false;
Expand Down
Loading