Client LuaCsForBarotrauma
CharacterAbilityModifyStatToFlooding.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  private readonly StatTypes statType;
6  private readonly float maxValue;
7  private float lastValue = 0f;
8  public override bool AllowClientSimulation => true;
9 
10  public CharacterAbilityModifyStatToFlooding(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
11  {
12  statType = CharacterAbilityGroup.ParseStatType(abilityElement.GetAttributeString("stattype", ""), CharacterTalent.DebugIdentifier);
13  maxValue = abilityElement.GetAttributeFloat("maxvalue", 0f);
14  }
15 
16  protected override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
17  {
18  Character.ChangeStat(statType, -lastValue);
19 
20  if (conditionsMatched && Character.IsInFriendlySub)
21  {
22  float waterVolume = 0.0f, totalVolume = 0.0f;
23  foreach (Hull hull in Hull.HullList)
24  {
25  if (hull.Submarine != Character.Submarine) { continue; }
26  waterVolume += hull.WaterVolume;
27  totalVolume += hull.Volume;
28  }
29  lastValue = (totalVolume == 0.0f ? 1.0f : waterVolume / totalVolume) * maxValue;
30  Character.ChangeStat(statType, lastValue);
31  }
32  else
33  {
34  lastValue = 0f;
35  }
36  }
37  }
38 }
static StatTypes ParseStatType(string statTypeString, string debugIdentifier)
override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
CharacterAbilityModifyStatToFlooding(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
void ChangeStat(StatTypes statType, float value)
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
Submarine Submarine
Definition: Entity.cs:53
static readonly List< Hull > HullList
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:195