Client LuaCsForBarotrauma
CharacterAbilityModifyStatToSkill.cs
1 using System.Linq;
2 
3 namespace Barotrauma.Abilities
4 {
6  {
7  private readonly StatTypes statType;
8  private readonly float maxValue;
9  private readonly Identifier skillIdentifier;
10  private readonly bool useAll;
11  private float lastValue = 0f;
12  public override bool AllowClientSimulation => true;
13 
14  public CharacterAbilityModifyStatToSkill(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
15  {
16  statType = CharacterAbilityGroup.ParseStatType(abilityElement.GetAttributeString("stattype", ""), CharacterTalent.DebugIdentifier);
17  maxValue = abilityElement.GetAttributeFloat("maxvalue", 0f);
18  skillIdentifier = abilityElement.GetAttributeIdentifier("skillidentifier", Identifier.Empty);
19  useAll = skillIdentifier == "all";
20  }
21 
22  protected override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
23  {
24  Character.ChangeStat(statType, -lastValue);
25 
26  if (conditionsMatched)
27  {
28  float skillTotal = 0f;
29 
30  if (useAll && Character.Info?.Job != null)
31  {
32  var skills = Character.Info.Job.GetSkills();
33  foreach (Skill skill in skills)
34  {
35  skillTotal += Character.GetSkillLevel(skill.Identifier);
36  }
37  skillTotal /= skills.Count();
38  }
39  else
40  {
41  skillTotal = Character.GetSkillLevel(skillIdentifier);
42  }
43 
44  lastValue = skillTotal / 100f * maxValue;
45  Character.ChangeStat(statType, lastValue);
46  }
47  else
48  {
49  lastValue = 0f;
50  }
51  }
52  }
53 }
static StatTypes ParseStatType(string statTypeString, string debugIdentifier)
override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
CharacterAbilityModifyStatToSkill(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
float GetSkillLevel(Identifier skillIdentifier)
Get the character's current skill level, taking into account any temporary boosts from wearables and ...
void ChangeStat(StatTypes statType, float value)
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
Identifier GetAttributeIdentifier(string key, string def)
IEnumerable< Skill > GetSkills()
Definition: Job.cs:84
readonly Identifier Identifier
Definition: Skill.cs:7
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:195