Client LuaCsForBarotrauma
CharacterAbilityApplyStatusEffectsToApprenticeship.cs
1 #nullable enable
2 
3 using System.Collections.Generic;
4 using System.Collections.Immutable;
5 
6 namespace Barotrauma.Abilities
7 {
8  internal sealed class CharacterAbilityApplyStatusEffectsToApprenticeship : CharacterAbilityApplyStatusEffects
9  {
10  private readonly bool invert;
11  private readonly ImmutableHashSet<JobPrefab> jobPrefabList = JobPrefab.Prefabs.ToImmutableHashSet();
12 
13  public CharacterAbilityApplyStatusEffectsToApprenticeship(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
14  {
15  invert = abilityElement.GetAttributeBool("invert", false);
16  }
17 
18  protected override void ApplyEffect()
19  {
20  ApplyEffectSpecific(Character);
21  JobPrefab? apprenticeJob = GetApprenticeJob(Character, jobPrefabList);
22  if (apprenticeJob is null)
23  {
24  DebugConsole.ThrowError($"{nameof(CharacterAbilityUnlockApprenticeshipTalentTree)}: Could not find apprentice job for character {Character.Name}",
25  contentPackage: CharacterTalent.Prefab.ContentPackage);
26  return;
27  }
28 
29  foreach (Character character in GameSession.GetSessionCrewCharacters(CharacterType.Both))
30  {
31  JobPrefab? characterJob = character.Info?.Job?.Prefab;
32  if (characterJob is null) { continue; }
33 
34  switch (characterJob.Identifier == apprenticeJob.Identifier)
35  {
36  case true when invert:
37  continue;
38  case false when !invert:
39  continue;
40  }
41 
42  ApplyEffectSpecific(character);
43  }
44  }
45 
46  protected override void ApplyEffect(AbilityObject abilityObject)
47  {
48  ApplyEffect();
49  }
50 
51  public static JobPrefab? GetApprenticeJob(Character character, IReadOnlyCollection<JobPrefab> jobList)
52  {
53  foreach (JobPrefab prefab in jobList)
54  {
55  if (character.Info.GetSavedStatValue(StatTypes.Apprenticeship, prefab.Identifier) > 0)
56  {
57  return prefab;
58  }
59  }
60 
61  return null;
62  }
63  }
64 }
void ApplyEffectSpecific(Character targetCharacter, Limb targetLimb=null)
readonly TalentPrefab Prefab
ContentPackage? ContentPackage
Definition: Prefab.cs:37
CharacterType
Definition: Enums.cs:685
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:180