Client LuaCsForBarotrauma
CharacterAbilityByTheBook.cs
1 using System.Collections.Generic;
2 using System.Linq;
3 
4 namespace Barotrauma.Abilities
5 {
7  {
8  private readonly int moneyAmount;
9  private readonly int experienceAmount;
10  private readonly int max;
11 
12  public CharacterAbilityByTheBook(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
13  {
14  moneyAmount = abilityElement.GetAttributeInt("moneyamount", 0);
15  experienceAmount = abilityElement.GetAttributeInt("experienceamount", 0);
16  max = abilityElement.GetAttributeInt("max", 0);
17  }
18 
19  protected override void ApplyEffect()
20  {
21  IEnumerable<Character> enemyCharacters = Character.CharacterList.Where(c => !Character.IsFriendly(c));
22 
23  int timesGiven = 0;
24  foreach (Character enemyCharacter in enemyCharacters)
25  {
26  if (!enemyCharacter.IsHuman) { continue; }
27  if (enemyCharacter.Submarine == null ||
28  (Submarine.MainSub != null && enemyCharacter.Submarine != Submarine.MainSub))
29  {
30  continue;
31  }
32  if (enemyCharacter.IsDead) { continue; }
33  if (!enemyCharacter.LockHands) { continue; }
34  Character.GiveMoney(moneyAmount);
35  GameAnalyticsManager.AddMoneyGainedEvent(moneyAmount, GameAnalyticsManager.MoneySource.Ability, CharacterTalent.Prefab.Identifier.Value);
36  foreach (Character character in Character.GetFriendlyCrew(Character))
37  {
38  character.Info?.GiveExperience(experienceAmount);
39  }
40  timesGiven++;
41  if (max > 0 && timesGiven >= max) { break; }
42  }
43 
44  }
45  }
46 }
CharacterAbilityByTheBook(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
static IEnumerable< Character > GetFriendlyCrew(Character character)
bool IsFriendly(Character other)
void GiveMoney(int amount)
Shows visual notification of money gained by the specific player. Useful for mid-mission monetary gai...
readonly TalentPrefab Prefab
int GetAttributeInt(string key, int def)
Submarine Submarine
Definition: Entity.cs:53
readonly Identifier Identifier
Definition: Prefab.cs:34
static Submarine MainSub
Note that this can be null in some situations, e.g. editors and missions that don't load a submarine.