Skip to content

Commit

Permalink
more stuff!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
MightBeNotReal committed Feb 18, 2025
1 parent 765c1be commit 3042dd0
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ private void UpdateBleeding(EntityUid uid, WoundableVisualsComponent comp, Enum
private Color GetBleedsColor(EntityUid body)
{
// return dark red.. If for some reason there is no blood in this entity.
return !TryComp<BloodstreamComponent>(body, out var bloodstream) ? Color.DarkRed : _protoMan.Index(bloodstream.BloodReagent).SubstanceColor;
if (!TryComp<BloodstreamComponent>(body, out var bloodstream))
return Color.DarkRed;

return _protoMan.Index(bloodstream.BloodReagent).SubstanceColor;
}

private FixedPoint2 GetThreshold(FixedPoint2 threshold, WoundableVisualsComponent comp)
Expand Down
30 changes: 24 additions & 6 deletions Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,31 @@ public void Populate(HealthAnalyzerScannedUserMessage msg)

if (!isPart && _entityManager.TryGetComponent<BodyComponent>(_target.Value, out var body) && body.RootContainer.ContainedEntity.HasValue)
{
var total =
_wound.GetAllWoundableChildren(body.RootContainer.ContainedEntity.Value)
.Aggregate((FixedPoint2) 0,
(current, damagedWoundable)
=> current + _wound.GetWoundableSeverityPoint(damagedWoundable.Item1, damagedWoundable.Item2));
var damageGroups = new Dictionary<string, FixedPoint2>();
foreach (var child in _wound.GetAllWoundableChildren(body.RootContainer.ContainedEntity.Value))
{
foreach (var wound in _wound.GetWoundableWounds(child.Item1, child.Item2))
{
var woundGroup = wound.Item2.DamageGroup;
if (woundGroup == null)
continue;

if (!damageGroups.TryAdd(woundGroup, wound.Item2.WoundSeverityPoint))
{
damageGroups[woundGroup] += wound.Item2.WoundSeverityPoint;
}
}
}

var damageSortedGroups =
damageGroups.OrderByDescending(damage => damage.Value)
.ToDictionary(x => x.Key, x => x.Value);

IReadOnlyDictionary<string, FixedPoint2> damagePerType = damageGroups;

DrawDiagnosticGroups(damageSortedGroups, damagePerType);

DamageLabel.Text = total.ToString();
DamageLabel.Text = damageGroups.Values.Sum().ToString();
}

if (_entityManager.TryGetComponent<WoundableComponent>(part, out var woundable))
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Body/Systems/BloodstreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public override void Update(float frameTime)
}
}

if (!_consciousness.SetConsciousnessModifier(uid, nerveSys.Value, -total, type: ConsciousnessModType.Pain))
if (!_consciousness.SetConsciousnessModifier(uid, nerveSys.Value, -total, identifier: "Bleeding", type: ConsciousnessModType.Pain))
{
_consciousness.AddConsciousnessModifier(uid, nerveSys.Value, -total, identifier: "Bleeding", type: ConsciousnessModType.Pain);
}
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Body/Systems/RespiratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ private void StopSuffocation(Entity<RespiratorComponent> ent)
ent,
nerveSys.Value,
modifier.Value.Change + ent.Comp.DamageRecovery.GetTotal(),
identifier: "Suffocation");
identifier: "Suffocation",
type: ConsciousnessModType.Pain);
}

return;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Medical/HealingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ entity.Comp.DamageContainerID is not null &&
bleedStopAbility -= bleeds.BleedingAmount;
}

if (bleedStopAbility != -healing.BloodlossModifier)
if (bleedStopAbility != healing.BloodlossModifier)
{
_popupSystem.PopupEntity(bleedStopAbility > 0
? Loc.GetString("medical-item-stop-bleeding-fully-rebell")
Expand Down Expand Up @@ -235,7 +235,7 @@ entity.Comp.DamageContainerID is not null &&
}
}

if (healedTotal <= 0 && healing.BloodlossModifier != 0)
if (healedTotal <= 0)
{
_popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use-rebell", ("target", ent)), ent, args.User, PopupType.SmallCaution);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Linq;
using Content.Shared.Backmen.Surgery.Body.Events;
using Content.Shared.Backmen.Surgery.Consciousness.Components;
using Content.Shared.Backmen.Surgery.Pain;
using Content.Shared.Backmen.Surgery.Pain.Components;
using Content.Shared.Body.Events;
using Content.Shared.Body.Organ;
using Content.Shared.Body.Systems;
using Content.Shared.Mobs;
using Content.Shared.Rejuvenate;

Expand All @@ -15,10 +12,6 @@ public partial class ConsciousnessSystem
{
private void InitProcess()
{
SubscribeLocalEvent<NerveSystemComponent, PainModifierChangedEvent>(OnPainChanged);
SubscribeLocalEvent<NerveSystemComponent, PainModifierAddedEvent>(OnPainAdded);
SubscribeLocalEvent<NerveSystemComponent, PainModifierRemovedEvent>(OnPainRemoved);

SubscribeLocalEvent<ConsciousnessComponent, MobStateChangedEvent>(OnMobStateChanged);

// To prevent people immediately falling down as rejuvenated
Expand Down Expand Up @@ -54,68 +47,6 @@ private void UpdatePassedOut(float frameTime)
}
}

private void OnPainChanged(EntityUid uid, NerveSystemComponent component, PainModifierChangedEvent args)
{
if (!TryComp<OrganComponent>(args.NerveSystem, out var nerveSysOrgan) || !nerveSysOrgan.Body.HasValue)
return;

if (!SetConsciousnessModifier(nerveSysOrgan.Body.Value,
args.NerveSystem,
-component.Pain,
null,
"Pain",
ConsciousnessModType.Pain))
{
AddConsciousnessModifier(nerveSysOrgan.Body.Value,
args.NerveSystem,
-component.Pain,
null,
"Pain",
ConsciousnessModType.Pain);
}
}

private void OnPainAdded(EntityUid uid, NerveSystemComponent component, PainModifierAddedEvent args)
{
if (!TryComp<OrganComponent>(args.NerveSystem, out var nerveSysOrgan) || !nerveSysOrgan.Body.HasValue)
return;

if (!SetConsciousnessModifier(nerveSysOrgan.Body.Value,
args.NerveSystem,
-component.Pain,
null,
"Pain",
ConsciousnessModType.Pain))
{
AddConsciousnessModifier(nerveSysOrgan.Body.Value,
args.NerveSystem,
-component.Pain,
null,
"Pain",
ConsciousnessModType.Pain);
}
}

private void OnPainRemoved(EntityUid uid, NerveSystemComponent component, PainModifierRemovedEvent args)
{
if (!TryComp<OrganComponent>(args.NerveSystem, out var nerveSysOrgan) || !nerveSysOrgan.Body.HasValue)
return;

if (args.CurrentPain <= 0)
{
RemoveConsciousnessModifer(nerveSysOrgan.Body.Value, args.NerveSystem, "Pain");
}
else
{
SetConsciousnessModifier(nerveSysOrgan.Body.Value,
args.NerveSystem,
-component.Pain,
null,
"Pain",
type: ConsciousnessModType.Pain);
}
}

private void OnMobStateChanged(EntityUid uid, ConsciousnessComponent component, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed partial class NerveSystemComponent : Component
/// How much Pain can this nerve system hold.
/// </summary>
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadOnly)]
public FixedPoint2 PainCap = 100f;
public FixedPoint2 PainCap = 200f;

// Don't change, OR I will break your knees, filled up upon initialization.
public Dictionary<EntityUid, NerveComponent> Nerves = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ public partial class PainSystem
private void InitAffliction()
{
// Pain management hooks.
SubscribeLocalEvent<PainInflicterComponent, WoundAddedEvent>(OnPainAdded);
SubscribeLocalEvent<PainInflicterComponent, WoundRemovedEvent>(OnPainRemoved);
SubscribeLocalEvent<PainInflicterComponent, WoundSeverityPointChangedEvent>(OnPainChanged);
}

private const string PainModifierIdentifier = "Pain";

#region Event Handling

private void OnPainAdded(EntityUid uid, PainInflicterComponent pain, ref WoundAddedEvent args)
private void OnPainChanged(EntityUid uid, PainInflicterComponent pain, WoundSeverityPointChangedEvent args)
{
if (_net.IsClient)
return;

if (!TryComp<BodyPartComponent>(args.Woundable.RootWoundable, out var bodyPart))
if (!TryComp<BodyPartComponent>(args.Component.HoldingWoundable, out var bodyPart))
return;

if (bodyPart.Body == null)
Expand All @@ -33,22 +30,24 @@ private void OnPainAdded(EntityUid uid, PainInflicterComponent pain, ref WoundAd
if (!_consciousness.TryGetNerveSystem(bodyPart.Body.Value, out var nerveSys))
return;

pain.Pain = FixedPoint2.Clamp(
args.Component.WoundSeverityPoint * _painMultipliers[args.Component.WoundSeverity] * pain.PainMultiplier,
0,
100);
// bro how
pain.Pain = FixedPoint2.Clamp(args.NewSeverity * pain.PainMultiplier, 0, 100);
var allPain = (FixedPoint2) 0;

if (!TryChangePainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, pain.Pain))
foreach (var (woundId, _) in _wound.GetWoundableWounds(args.Component.HoldingWoundable))
{
TryAddPainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, pain.Pain);
if (!TryComp<PainInflicterComponent>(woundId, out var painInflicter))
continue;

allPain += painInflicter.Pain;
}

if (!TryAddPainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, allPain))
TryChangePainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, allPain);
}

private void OnPainChanged(EntityUid uid, PainInflicterComponent pain, WoundSeverityPointChangedEvent args)
private void OnPainRemoved(EntityUid uid, PainInflicterComponent pain, WoundRemovedEvent args)
{
if (_net.IsClient)
return;

if (!TryComp<BodyPartComponent>(args.Component.HoldingWoundable, out var bodyPart))
return;

Expand All @@ -63,21 +62,23 @@ private void OnPainChanged(EntityUid uid, PainInflicterComponent pain, WoundSeve
return;

// bro how
pain.Pain = FixedPoint2.Clamp(args.NewSeverity * _painMultipliers[args.Component.WoundSeverity] * pain.PainMultiplier, 0, 100);
var allPain = (FixedPoint2) 0;

foreach (var (_, comp) in _wound.GetAllWoundableChildren(rootPart.Value))
foreach (var (woundId, _) in _wound.GetWoundableWounds(args.Component.HoldingWoundable))
{
foreach (var woundId in comp.Wounds!.ContainedEntities)
{
if (!TryComp<PainInflicterComponent>(woundId, out var painInflicter))
continue;
if (!TryComp<PainInflicterComponent>(woundId, out var painInflicter))
continue;

allPain += painInflicter.Pain;
}
allPain += painInflicter.Pain;
}

TryChangePainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, allPain);
if (allPain <= 0)
{
TryRemovePainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier);
}
else
{
TryChangePainModifier(nerveSys.Value, args.Component.HoldingWoundable, PainModifierIdentifier, allPain);
}
}

#endregion
Expand Down
37 changes: 21 additions & 16 deletions Content.Shared/Backmen/Surgery/Pain/Systems/PainSystem.Damage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.Shared.Backmen.Surgery.Consciousness;
using Content.Shared.Backmen.Surgery.Pain.Components;
using Content.Shared.Backmen.Surgery.Wounds;
using Content.Shared.Body.Organ;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
Expand All @@ -21,20 +21,6 @@ public partial class PainSystem
private const double PainJobTime = 0.005;
private readonly JobQueue _painJobQueue = new(PainJobTime);

#region Data

private readonly Dictionary<WoundSeverity, FixedPoint2> _painMultipliers = new()
{
{ WoundSeverity.Healed, 0.34 },
{ WoundSeverity.Minor, 0.34 },
{ WoundSeverity.Moderate, 0.37 },
{ WoundSeverity.Severe, 0.43 },
{ WoundSeverity.Critical, 0.52 },
{ WoundSeverity.Loss, 0.52 }, // already painful enough
};

#endregion

#region Public API

/// <summary>
Expand Down Expand Up @@ -406,6 +392,9 @@ private void UpdateNerveSystemPain(EntityUid uid, NerveSystemComponent? nerveSys
if (!Resolve(uid, ref nerveSys, false))
return;

if (!TryComp<OrganComponent>(uid, out var organ) || organ.Body == null)
return;

nerveSys.Pain =
FixedPoint2.Clamp(
nerveSys.Modifiers.Aggregate((FixedPoint2) 0,
Expand All @@ -415,6 +404,20 @@ private void UpdateNerveSystemPain(EntityUid uid, NerveSystemComponent? nerveSys
nerveSys.PainCap);

UpdatePainThreshold(uid, nerveSys);
if (!_consciousness.SetConsciousnessModifier(
organ.Body.Value,
uid,
-nerveSys.Pain,
identifier: PainModifierIdentifier,
type: ConsciousnessModType.Pain))
{
_consciousness.AddConsciousnessModifier(
organ.Body.Value,
uid,
-nerveSys.Pain,
identifier: PainModifierIdentifier,
type: ConsciousnessModType.Pain);
}
}

private void CleanupSounds(NerveSystemComponent nerveSys)
Expand Down Expand Up @@ -492,6 +495,7 @@ private void ApplyPainReflexesEffects(EntityUid body, Entity<NerveSystemComponen

// For the funnies :3
_consciousness.ForceConscious(body, nerveSys.Comp.PainShockStunTime);
nerveSys.Comp.LastThresholdType = PainThresholdTypes.None;

break;
case PainThresholdTypes.PainPassout:
Expand All @@ -500,6 +504,8 @@ private void ApplyPainReflexesEffects(EntityUid body, Entity<NerveSystemComponen
_popup.PopupPredicted(Loc.GetString("passes-out-pain", ("entity", body)), body, null, PopupType.MediumCaution);
_consciousness.ForcePassout(body, nerveSys.Comp.ForcePassoutTime);

nerveSys.Comp.LastThresholdType = PainThresholdTypes.None;

break;
case PainThresholdTypes.None:
break;
Expand All @@ -523,7 +529,6 @@ private void UpdatePainThreshold(EntityUid uid, NerveSystemComponent nerveSys)
if (nearestReflex == PainThresholdTypes.None)
return;

// TODO: Might be bad.
if (nerveSys.LastThresholdType == nearestReflex || _timing.CurTime < nerveSys.UpdateTime)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ private void ApplyTraumas(EntityUid target, IEnumerable<TraumaType> traumas, Fix
{
if (!_wound.IsWoundableRoot(target, woundable) && woundable.ParentWoundable.HasValue)
{
_wound.AmputateWoundable(woundable.ParentWoundable.Value, target, woundable);
var bodyPart = Comp<BodyPartComponent>(target);
if (bodyPart.Body.HasValue && _consciousness.TryGetNerveSystem(bodyPart.Body.Value, out var nerveSys))
_pain.TryAddPainModifier(nerveSys.Value, target, "Dismemberment", 20f, time: TimeSpan.FromSeconds(12f));
_pain.TryAddPainModifier(nerveSys.Value, target, "Dismemberment", 25f, time: TimeSpan.FromSeconds(40f));

_wound.AmputateWoundable(woundable.ParentWoundable.Value, target, woundable);
_sawmill.Info( $"A new trauma (Caused by {severity} damage) was created on target: {target}. Type: Dismemberment.");
}
}
Expand Down
Loading

0 comments on commit 3042dd0

Please sign in to comment.