Client LuaCsForBarotrauma
CharacterAbilityGiveMoney.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  public override bool AppliesEffectOnIntervalUpdate => true;
6 
7  private readonly int amount;
8  private readonly Identifier scalingStatIdentifier;
9 
10  public CharacterAbilityGiveMoney(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
11  {
12  amount = abilityElement.GetAttributeInt("amount", 0);
13  scalingStatIdentifier = abilityElement.GetAttributeIdentifier("scalingstatidentifier", Identifier.Empty);
14 
15  if (amount == 0)
16  {
17  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier}, CharacterAbilityGiveMoney - amount of money set to 0.",
18  contentPackage: abilityElement.ContentPackage);
19  }
20  }
21 
22  private void ApplyEffectSpecific(Character targetCharacter)
23  {
24  float multiplier = 1f;
25  if (!scalingStatIdentifier.IsEmpty)
26  {
27  multiplier = 0 + Character.Info.GetSavedStatValue(StatTypes.None, scalingStatIdentifier);
28  }
29 
30  int totalAmount = (int)(multiplier * amount);
31  targetCharacter.GiveMoney(totalAmount);
32  GameAnalyticsManager.AddMoneyGainedEvent(totalAmount, GameAnalyticsManager.MoneySource.Ability, CharacterTalent.Prefab.Identifier.Value);
33  }
34 
35  protected override void ApplyEffect(AbilityObject abilityObject)
36  {
37  if ((abilityObject as IAbilityCharacter)?.Character is Character targetCharacter)
38  {
39  ApplyEffectSpecific(targetCharacter);
40  }
41  else
42  {
43  ApplyEffectSpecific(Character);
44  }
45  }
46 
47  protected override void ApplyEffect()
48  {
49  ApplyEffectSpecific(Character);
50  }
51  }
52 }
override void ApplyEffect(AbilityObject abilityObject)
CharacterAbilityGiveMoney(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
void GiveMoney(int amount)
Shows visual notification of money gained by the specific player. Useful for mid-mission monetary gai...
readonly TalentPrefab Prefab
ContentPackage? ContentPackage
int GetAttributeInt(string key, int def)
Identifier GetAttributeIdentifier(string key, string def)
readonly Identifier Identifier
Definition: Prefab.cs:34
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:195