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

Whitelist for blood packs #32517

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions Content.Server/Medical/Components/HealingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public sealed partial class HealingComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
public float ModifyBloodLevel = 0.0f;

/// <remarks>
/// Whitelist bloodtypes that this item can restore
/// </remarks>
[DataField("bloodReagentWhitelist")]
insoPL marked this conversation as resolved.
Show resolved Hide resolved
public List<string> BloodReagentWhitelist = new List<string>();
insoPL marked this conversation as resolved.
Show resolved Hide resolved

/// <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,
Expand All @@ -39,14 +45,14 @@ public sealed partial class HealingComponent : Component
public List<string>? DamageContainers;

/// <summary>
/// How long it takes to apply the damage.
/// How long it takes to apply the damage.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("delay")]
public float Delay = 3f;

/// <summary>
/// Delay multiplier when healing yourself.
/// Delay multiplier when healing yourself.
/// </summary>
[DataField("selfHealPenaltyMultiplier")]
public float SelfHealPenaltyMultiplier = 3f;
Expand Down
44 changes: 30 additions & 14 deletions Content.Server/Medical/HealingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,48 @@ 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 = (CanHealingCompomentBeUsed(entity.Owner, healing) && !dontRepeat);
insoPL marked this conversation as resolved.
Show resolved Hide resolved
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 CanHealingCompomentBeUsed(EntityUid targetEntityUid, HealingComponent healingComponent)
insoPL marked this conversation as resolved.
Show resolved Hide resolved
{
var damageableDict = component.Damage.DamageDict;
var healingDict = healing.Damage.DamageDict;
if (!TryComp<DamageableComponent>(targetEntityUid, out var damageableComponent))
return false;

bool thereIsDamageThatCanBeHealed = false;
insoPL marked this conversation as resolved.
Show resolved Hide resolved

var damageableDict = damageableComponent.Damage.DamageDict;
var healingDict = healingComponent.Damage.DamageDict;
foreach (var type in healingDict)
{
if (damageableDict[type.Key].Value > 0)
{
return true;
thereIsDamageThatCanBeHealed = true;
}
}

return false;
if (healingComponent.ModifyBloodLevel > 0) // blood replenishing HealingComponent
{
if (!TryComp<BloodstreamComponent>(targetEntityUid, out var bloodstream)
|| bloodstream is null)
insoPL marked this conversation as resolved.
Show resolved Hide resolved
return false;

if (!_solutionContainerSystem.ResolveSolution(targetEntityUid, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution)
|| bloodSolution is null)
insoPL marked this conversation as resolved.
Show resolved Hide resolved
return false;

bool validBloodType = healingComponent.BloodReagentWhitelist.Contains(bloodstream.BloodReagent) // blood type is whitelisted
|| healingComponent.BloodReagentWhitelist.Count == 0; // there is no whitelist defined

bool isThereSpaceForMoreBlood = bloodSolution.Volume < bloodSolution.MaxVolume;

return validBloodType && (thereIsDamageThatCanBeHealed || isThereSpaceForMoreBlood);
}

return thereIsDamageThatCanBeHealed;
}

private void OnHealingUse(Entity<HealingComponent> entity, ref UseInHandEvent args)
Expand Down Expand Up @@ -172,14 +195,7 @@ 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.

if (!anythingToDo)
if (!CanHealingCompomentBeUsed(target, component))
{
_popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use", ("item", uid)), uid, user);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@
path: "/Audio/Items/Medical/brutepack_begin.ogg"
healingEndSound:
path: "/Audio/Items/Medical/brutepack_end.ogg"
bloodReagentWhitelist:
- Blood
- InsectBlood
- CopperBlood
- Sap
- Sugar
- Slime
- AmmoniaBlood
- type: Stack
stackType: Bloodpack
count: 10
Expand Down
Loading