|
| 1 | +using Content.Shared.FixedPoint; |
1 | 2 | using Content.Shared.Traits;
|
2 | 3 | using JetBrains.Annotations;
|
3 | 4 | using Robust.Shared.Prototypes;
|
|
11 | 12 | using Content.Shared.Mood;
|
12 | 13 | using Content.Shared.Traits.Assorted.Components;
|
13 | 14 | using Content.Shared.Damage;
|
| 15 | +using Content.Shared.Damage.Components; |
14 | 16 | using Content.Shared.Chemistry.Components;
|
15 | 17 | using Content.Shared.Chemistry.EntitySystems;
|
16 | 18 | using Content.Shared.Mobs.Components;
|
@@ -547,3 +549,39 @@ public override void OnPlayerSpawn(EntityUid uid,
|
547 | 549 | staminaComponent.Cooldown += CooldownModifier;
|
548 | 550 | }
|
549 | 551 | }
|
| 552 | + |
| 553 | +/// <summary> |
| 554 | +/// Used for traits that modify SlowOnDamageComponent. |
| 555 | +/// </summary> |
| 556 | +[UsedImplicitly] |
| 557 | +public sealed partial class TraitModifySlowOnDamage : TraitFunction |
| 558 | +{ |
| 559 | + // <summary> |
| 560 | + // A flat modifier to add to all damage threshold keys. |
| 561 | + // </summary> |
| 562 | + [DataField, AlwaysPushInheritance] |
| 563 | + public float DamageThresholdsModifier; |
| 564 | + |
| 565 | + // <summary> |
| 566 | + // A multiplier applied to all speed modifier values. |
| 567 | + // The higher the multiplier, the stronger the slowdown. |
| 568 | + // </summary> |
| 569 | + [DataField, AlwaysPushInheritance] |
| 570 | + public float SpeedModifierMultiplier = 1f; |
| 571 | + |
| 572 | + public override void OnPlayerSpawn(EntityUid uid, |
| 573 | + IComponentFactory factory, |
| 574 | + IEntityManager entityManager, |
| 575 | + ISerializationManager serializationManager) |
| 576 | + { |
| 577 | + if (!entityManager.TryGetComponent<SlowOnDamageComponent>(uid, out var slowOnDamage)) |
| 578 | + return; |
| 579 | + |
| 580 | + var newSpeedModifierThresholds = new Dictionary<FixedPoint2, float>(); |
| 581 | + |
| 582 | + foreach (var (damageThreshold, speedModifier) in slowOnDamage.SpeedModifierThresholds) |
| 583 | + newSpeedModifierThresholds[damageThreshold + DamageThresholdsModifier] = 1 - (1 - speedModifier) * SpeedModifierMultiplier; |
| 584 | + |
| 585 | + slowOnDamage.SpeedModifierThresholds = newSpeedModifierThresholds; |
| 586 | + } |
| 587 | +} |
0 commit comments