Skip to content

Commit

Permalink
[Fix] Healing Fixes (space-syndicate#874)
Browse files Browse the repository at this point in the history
* Targeting & Healing Fixes

* Update Content.Server/Medical/HealingSystem.cs

Co-authored-by: gluesniffler <[email protected]>

* Fix Vital Damage

* Update BodyPartComponent.cs

* fix

---------

Co-authored-by: gluesniffler <[email protected]>
  • Loading branch information
2 people authored and TokenStyle committed Oct 31, 2024
1 parent 39b21a0 commit 635ca12
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 41 deletions.
5 changes: 3 additions & 2 deletions Content.Client/Backmen/Targeting/TargetingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Content.Shared.Backmen.Targeting;
using Content.Shared.Input;
using Content.Shared.Targeting;
using Content.Shared.Targeting.Events;
using Robust.Client.Player;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;

namespace Content.Client.Targeting;
namespace Content.Client.Backmen.Targeting;
public sealed class TargetingSystem : SharedTargetingSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand Down Expand Up @@ -91,4 +92,4 @@ private void HandleTargetChange(ICommonSession? session, TargetBodyPart target)

TargetChange?.Invoke(target);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Client.Backmen.UserInterface.Systems.PartStatus.Widgets;
using Content.Client.Gameplay;
using Content.Shared.Targeting;
using Content.Client.Targeting;
using Content.Client.Backmen.Targeting;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Utility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Client.Backmen.UserInterface.Systems.Targeting.Widgets;
using Content.Client.Gameplay;
using Content.Shared.Targeting;
using Content.Client.Targeting;
using Content.Client.Backmen.Targeting;
using Content.Shared.Targeting.Events;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.Player;
Expand Down
8 changes: 3 additions & 5 deletions Content.Server/Backmen/Targeting/TargetingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Content.Shared.Backmen.Targeting;
using Content.Shared.Body.Systems;
using Content.Shared.Mobs;
using Content.Shared.Targeting;
using Content.Shared.Targeting.Events;
using Robust.Server.Audio;
using Robust.Shared.Audio;

namespace Content.Server.Targeting;
namespace Content.Server.Backmen.Targeting;
public sealed class TargetingSystem : SharedTargetingSystem
{
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly SharedBodySystem _bodySystem = default!;

public override void Initialize()
Expand Down Expand Up @@ -54,4 +52,4 @@ private void OnMobStateChange(EntityUid uid, TargetingComponent component, MobSt
RaiseNetworkEvent(new TargetIntegrityChangeEvent(GetNetEntity(uid)), uid);
}
}
}
}
37 changes: 18 additions & 19 deletions Content.Server/Medical/HealingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,6 @@ entity.Comp.DamageContainerID is not null &&
if (healed == null && healing.BloodlossModifier != 0)
return;

/* This is rather shitcodey. Problem is that right now damage is coupled to integrity.
If the body is fully healed, all of the checks on TryChangeDamage stop us from actually healing.
So in this case we add a special check to heal anyway if TryChangeDamage returns null.
*/
if (healed != null && healed.GetTotal() == 0)
{
if (TryComp<TargetingComponent>(args.User, out var user)
&& TryComp<TargetingComponent>(args.Target, out var target)
&& healing.Damage.GetTotal() < 0)
{
// If they are valid, we check for body part presence,
// and integrity, then apply a direct integrity change.
var (type, symmetry) = _bodySystem.ConvertTargetBodyPart(user.Target);
if (_bodySystem.GetBodyChildrenOfType(args.Target.Value, type, symmetry: symmetry).FirstOrDefault() is { } bodyPart
&& bodyPart.Component.Integrity < BodyPartComponent.MaxIntegrity)
_bodySystem.TryChangeIntegrity(bodyPart, healing.Damage.GetTotal().Float(), false, target.Target, out var _);
}
}

var total = healed?.GetTotal() ?? FixedPoint2.Zero;

// Re-verify that we can heal the damage.
Expand All @@ -126,6 +107,24 @@ entity.Comp.DamageContainerID is not null &&
QueueDel(args.Used.Value);
}

// start-backmen: surgery
// This is still pretty shitcodey, but a lot better than previous iteration.
// We are just trying to heal the most damaged body part.
if (healed != null && healed.GetTotal() == 0)
{
var parts = _bodySystem.GetBodyChildren(args.Target).ToList();
// Get the severest body part, selected by taking the one with lowest Integrity.
var severestPart = parts.MinBy(x => x.Component.Integrity);
// Convert this thing into a target
var targetBodyPart = _bodySystem.GetTargetBodyPart(severestPart);

if (targetBodyPart != null)
{
_bodySystem.TryChangeIntegrity(severestPart, healing.Damage.GetTotal().Float(), false, targetBodyPart.Value, out _);
}
}
// end-backmen: surgery

if (entity.Owner != args.User)
{
_adminLogger.Add(LogType.Healed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void TryChangeIntegrity(Entity<BodyPartComponent> partEnt,
RaiseLocalEvent(partEnt, ref ev);
}

if (partEnt.Comp.Integrity != originalIntegrity
if (Math.Abs(partEnt.Comp.Integrity - originalIntegrity) > 0.01
&& _queryTargeting.TryComp(partEnt.Comp.Body, out var targeting)
&& HasComp<MobStateComponent>(partEnt.Comp.Body))
{
Expand Down
11 changes: 2 additions & 9 deletions Content.Shared/Backmen/Targeting/SharedTargetingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
namespace Content.Shared.Targeting;
public abstract class SharedTargetingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
}
namespace Content.Shared.Backmen.Targeting;


}
public abstract class SharedTargetingSystem : EntitySystem;
8 changes: 8 additions & 0 deletions Content.Shared/Body/Part/BodyPartComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Content.Shared.FixedPoint;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
Expand Down Expand Up @@ -36,6 +37,13 @@ public sealed partial class BodyPartComponent : Component, ISurgeryToolComponent
[DataField("vital"), AutoNetworkedField]
public bool IsVital;

/// <summary>
/// Amount of damage to deal when the part gets removed.
/// Only works if IsVital is true.
/// </summary>
[DataField, AutoNetworkedField]
public FixedPoint2 VitalDamage = MaxIntegrity;

[DataField, AutoNetworkedField]
public BodyPartSymmetry Symmetry = BodyPartSymmetry.None;

Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Body/Systems/SharedBodySystem.Parts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ private void PartRemoveDamage(Entity<BodyComponent?> bodyEnt, Entity<BodyPartCom
&& !GetBodyChildrenOfType(bodyEnt, partEnt.Comp.PartType, bodyEnt.Comp).Any()
)
{
var damage = new DamageSpecifier(Prototypes.Index<DamageTypePrototype>("Bloodloss"), 300);
Damageable.TryChangeDamage(bodyEnt, damage);
var damage = new DamageSpecifier(Prototypes.Index<DamageTypePrototype>("Bloodloss"), partEnt.Comp.VitalDamage);
Damageable.TryChangeDamage(bodyEnt, damage, partMultiplier: 0f);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ent-OperatingTable = операционный стол
.desc = Специальный медицинский стол для проведения операций. Впрочем, сейчас это просто бесполезный реквизит.
.desc = Специальный медицинский стол для проведения операций. Смотря на него у вас неожиданно возникает ощущение быстрого течения времени...

0 comments on commit 635ca12

Please sign in to comment.