Client LuaCsForBarotrauma
CharacterAbilityGroupInterval.cs
1 using System.Collections.Generic;
2 
3 namespace Barotrauma.Abilities
4 {
6  {
7  private readonly float interval;
8  public float TimeSinceLastUpdate { get; private set; }
9 
10  private readonly float effectDelay;
11  private float effectDelayTimer;
12 
13 
14  public CharacterAbilityGroupInterval(AbilityEffectType abilityEffectType, CharacterTalent characterTalent, ContentXElement abilityElementGroup) :
15  base(abilityEffectType, characterTalent, abilityElementGroup)
16  {
17  // too many overlapping intervals could cause hitching? maybe randomize a little
18  interval = abilityElementGroup.GetAttributeFloat("interval", 0f);
19  effectDelay = abilityElementGroup.GetAttributeFloat("effectdelay", 0f);
20  }
21 
22  public void UpdateAbilityGroup(float deltaTime)
23  {
24  if (!IsActive) { return; }
25 
26  TimeSinceLastUpdate += deltaTime;
27  if (TimeSinceLastUpdate < interval) { return; }
28 
29  bool conditionsMatched;
30 
31  if (AllConditionsMatched())
32  {
33  effectDelayTimer += TimeSinceLastUpdate;
34  bool shouldApplyDelayedEffect = effectDelayTimer >= effectDelay;
35  conditionsMatched = shouldApplyDelayedEffect;
36  }
37  else
38  {
39  effectDelayTimer = 0f;
40  conditionsMatched = false;
41  }
42 
43  bool hasFallbacks = fallbackAbilities.Count > 0;
44 
45  List<CharacterAbility> abilitiesToRun =
46  !conditionsMatched && hasFallbacks
47  ? fallbackAbilities
49 
50  if (hasFallbacks)
51  {
52  conditionsMatched = true;
53  }
54 
55  foreach (var characterAbility in abilitiesToRun)
56  {
57  if (!characterAbility.IsViable()) { continue; }
58 
59  characterAbility.UpdateCharacterAbility(conditionsMatched, TimeSinceLastUpdate);
60  }
61 
62  if (conditionsMatched)
63  {
65  }
66 
68  }
69 
70  private bool AllConditionsMatched()
71  {
72  if (timesTriggered >= maxTriggerCount) { return false; }
73 
74  foreach (var abilityCondition in abilityConditions)
75  {
76  if (!abilityCondition.MatchesCondition()) { return false; }
77  }
78 
79  return true;
80  }
81  }
82 }
readonly List< AbilityCondition > abilityConditions
readonly List< CharacterAbility > characterAbilities
List of abilities that are triggered by this group. Fallback abilities are triggered if the condition...
CharacterAbilityGroupInterval(AbilityEffectType abilityEffectType, CharacterTalent characterTalent, ContentXElement abilityElementGroup)
float GetAttributeFloat(string key, float def)
AbilityEffectType
Definition: Enums.cs:140