Client LuaCsForBarotrauma
AbilityConditionHasPermanentStat.cs
1 using System;
2 
3 namespace Barotrauma.Abilities
4 {
6  {
7  private readonly Identifier statIdentifier;
8  private readonly StatTypes statType;
9  private readonly float min;
10  private readonly PermanentStatPlaceholder placeholder;
11 
13  {
14  statIdentifier = conditionElement.GetAttributeIdentifier("statidentifier", Identifier.Empty);
15  if (statIdentifier.IsEmpty)
16  {
17  DebugConsole.ThrowError($"No stat identifier defined for {this} in talent {characterTalent.DebugIdentifier}!",
18  contentPackage: conditionElement.ContentPackage);
19  }
20  string statTypeName = conditionElement.GetAttributeString("stattype", string.Empty);
21  statType = string.IsNullOrEmpty(statTypeName) ? StatTypes.None : CharacterAbilityGroup.ParseStatType(statTypeName, characterTalent.DebugIdentifier);
22  min = conditionElement.GetAttributeFloat("min", 0f);
23  placeholder = conditionElement.GetAttributeEnum("placeholder", PermanentStatPlaceholder.None);
24  }
25 
26  protected override bool MatchesCharacter(Character character)
27  {
28  if (character?.Info == null)
29  {
30  DebugConsole.AddWarning($"Error in {nameof(AbilityConditionHasPermanentStat.MatchesCharacter)}: character {character} has no CharacterInfo. Are you trying to use the condition on a non-player character?\n{Environment.StackTrace.CleanupStackTrace()}");
31  return false;
32  }
33  Identifier identifier = CharacterAbilityGivePermanentStat.HandlePlaceholders(placeholder, statIdentifier);
34  return character.Info.GetSavedStatValue(statType, identifier) >= min;
35  }
36  }
37 }
AbilityConditionHasPermanentStat(CharacterTalent characterTalent, ContentXElement conditionElement)
static Identifier HandlePlaceholders(PermanentStatPlaceholder placeholder, Identifier original)
static StatTypes ParseStatType(string statTypeString, string debugIdentifier)
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
Identifier GetAttributeIdentifier(string key, string def)
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:180