Client LuaCsForBarotrauma
BuffDurationIncrease.cs
1 using Microsoft.Xna.Framework;
2 using System;
3 
4 namespace Barotrauma
5 {
11  {
12  public BuffDurationIncrease(AfflictionPrefab prefab, float strength) : base(prefab, strength)
13  {
14 
15  }
16 
17  public override void Update(CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
18  {
19  base.Update(characterHealth, targetLimb, deltaTime);
20 
21  var afflictions = characterHealth.GetAllAfflictions();
22 
23  if (Strength <= 0)
24  {
25  foreach (Affliction affliction in afflictions)
26  {
27  if (!affliction.Prefab.IsBuff || affliction == this || affliction.StrengthDiminishMultiplier.Source != this) { continue; }
28  affliction.StrengthDiminishMultiplier.Source = null;
29  affliction.StrengthDiminishMultiplier.Value = 1f;
30  }
31  }
32  else
33  {
34  foreach (Affliction affliction in afflictions)
35  {
36  if (!affliction.Prefab.IsBuff || affliction == this) { continue; }
37  float multiplier = GetDiminishMultiplier();
38  if (affliction.StrengthDiminishMultiplier.Value < multiplier && affliction.StrengthDiminishMultiplier.Source != this) { continue; }
39 
40  affliction.StrengthDiminishMultiplier.Source = this;
41  affliction.StrengthDiminishMultiplier.Value = multiplier;
42  }
43  }
44  }
45 
46  private float GetDiminishMultiplier()
47  {
48  if (Strength < Prefab.ActivationThreshold) { return 1.0f; }
49  AfflictionPrefab.Effect currentEffect = GetActiveEffect();
50  if (currentEffect == null) { return 1.0f; }
51 
52  float multiplier = MathHelper.Lerp(
53  currentEffect.MinBuffMultiplier,
54  currentEffect.MaxBuffMultiplier,
55  currentEffect.GetStrengthFactor(this));
56  return 1.0f / Math.Max(multiplier, 0.001f);
57  }
58  }
59 }
virtual float Strength
Definition: Affliction.cs:31
AfflictionPrefab.Effect GetActiveEffect()
Definition: Affliction.cs:160
Character Source
Which character gave this affliction
Definition: Affliction.cs:88
readonly AfflictionPrefab Prefab
Definition: Affliction.cs:12
AfflictionPrefab is a prefab that defines a type of affliction that can be applied to a character....
readonly bool IsBuff
If set to true, the game will recognize this affliction as a buff. This means, among other things,...
A special affliction type that increases the duration of buffs (afflictions of the type "buff")....
override void Update(CharacterHealth characterHealth, Limb targetLimb, float deltaTime)
BuffDurationIncrease(AfflictionPrefab prefab, float strength)