Client LuaCsForBarotrauma
CharacterAbilityIncreaseSkill.cs
2 
3 namespace Barotrauma.Abilities
4 {
6  {
7  public override bool AppliesEffectOnIntervalUpdate => true;
8 
9  private readonly Identifier skillIdentifier;
10  private readonly float skillIncrease;
11 
12  public CharacterAbilityIncreaseSkill(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
13  {
14  skillIdentifier = abilityElement.GetAttributeIdentifier("skillidentifier", "");
15  skillIncrease = abilityElement.GetAttributeFloat("skillincrease", 0f);
16 
17  if (skillIdentifier.IsEmpty)
18  {
19  DebugConsole.ThrowError($"Error in talent \"{characterAbilityGroup.CharacterTalent.DebugIdentifier}\" - skill identifier not defined in CharacterAbilityIncreaseSkill.",
20  contentPackage: abilityElement.ContentPackage);
21  }
22  if (MathUtils.NearlyEqual(skillIncrease, 0))
23  {
24  DebugConsole.AddWarning($"Possible error in talent \"{characterAbilityGroup.CharacterTalent.DebugIdentifier}\" - skill increase set to 0.",
25  contentPackage: abilityElement.ContentPackage);
26  }
27  }
28 
29  protected override void ApplyEffect()
30  {
31  ApplyEffectSpecific(Character);
32  }
33 
34  protected override void ApplyEffect(AbilityObject abilityObject)
35  {
36  if ((abilityObject as IAbilityCharacter)?.Character is Character character)
37  {
38  ApplyEffectSpecific(character);
39  }
40  else
41  {
42  ApplyEffectSpecific(Character);
43  }
44  }
45 
46  private void ApplyEffectSpecific(Character character)
47  {
48  if (skillIdentifier == "random")
49  {
50  var skill = character.Info?.Job?.GetSkills()?.GetRandomUnsynced();
51  if (skill == null) { return; }
52  character.Info?.IncreaseSkillLevel(skill.Identifier, skillIncrease, gainedFromAbility: true);
53  }
54  else
55  {
56  character.Info?.IncreaseSkillLevel(skillIdentifier, skillIncrease, gainedFromAbility: true);
57  }
58  }
59  }
60 }
CharacterAbilityIncreaseSkill(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
override void ApplyEffect(AbilityObject abilityObject)
void IncreaseSkillLevel(Identifier skillIdentifier, float increase, bool gainedFromAbility=false, bool forceNotification=false)
Increase the skill by a specific amount. Talents may affect the actual, final skill increase.
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
Identifier GetAttributeIdentifier(string key, string def)
IEnumerable< Skill > GetSkills()
Definition: Job.cs:84