Client LuaCsForBarotrauma
TalentPrefab.cs
1 using System;
2 using System.Collections.Immutable;
3 using System.Xml.Linq;
4 #if CLIENT
5 using Microsoft.Xna.Framework;
6 #endif
7 
8 namespace Barotrauma
9 {
11  {
12  public string OriginalName => Identifier.Value;
13 
14  public LocalizedString DisplayName { get; private set; }
15 
16  public LocalizedString Description { get; private set; }
17 
22 
23  public readonly Sprite Icon;
24 
29  public readonly Option<(Identifier PermanentStatIdentifier, int Max)> TrackedStat;
30 
31 #if CLIENT
32  public readonly Option<Color> ColorOverride;
33 #endif
34 
36 
37  public readonly ImmutableHashSet<TalentMigration> Migrations;
38 
40  {
41  get;
42  private set;
43  }
44 
45  public TalentPrefab(ContentXElement element, TalentsFile file) : base(file, element.GetAttributeIdentifier("identifier", Identifier.Empty))
46  {
47  ConfigElement = element;
48 
49  DisplayName = TextManager.Get($"talentname.{Identifier}").Fallback(Identifier.Value);
50 
51  AbilityEffectsStackWithSameTalent = element.GetAttributeBool("abilityeffectsstackwithsametalent", true);
52 
53  var trackedStat = element.GetAttributeIdentifier("trackedstat", Identifier.Empty);
54  var trackedMax = element.GetAttributeInt("trackedmax", 100);
55  TrackedStat = !trackedStat.IsEmpty
56  ? Option.Some((trackedStat, trackedMax))
57  : Option.None;
58 
59  Identifier nameIdentifier = element.GetAttributeIdentifier("nameidentifier", Identifier.Empty);
60  if (!nameIdentifier.IsEmpty)
61  {
62  DisplayName = TextManager.Get(nameIdentifier).Fallback(Identifier.Value);
63  }
64 
65  Description = string.Empty;
66 
67 #if CLIENT
68  Color colorOverride = element.GetAttributeColor("coloroverride", Color.TransparentBlack);
69 
70  ColorOverride = colorOverride != Color.TransparentBlack
71  ? Option<Color>.Some(colorOverride)
72  : Option<Color>.None();
73 #endif
74 
75  var migrations = ImmutableHashSet.CreateBuilder<TalentMigration>();
76 
77  foreach (var subElement in element.Elements())
78  {
79  switch (subElement.Name.ToString().ToLowerInvariant())
80  {
81  case "icon":
82  Icon = new Sprite(subElement);
83  break;
84  case "description":
85  var tempDescription = Description;
86  TextManager.ConstructDescription(ref tempDescription, subElement);
87  Description = tempDescription;
88  break;
89  case "migrations":
90  foreach (var migrationElement in subElement.Elements())
91  {
92  try
93  {
94  var migration = TalentMigration.FromXML(migrationElement);
95  migrations.Add(migration);
96  }
97  catch (Exception e)
98  {
99  DebugConsole.ThrowError($"Error while loading talent migration for talent \"{Identifier}\".", e,
100  element?.ContentPackage);
101  }
102  }
103  break;
104  }
105  }
106 
107  Migrations = migrations.ToImmutable();
108 
109  if (element.GetAttribute("description") != null)
110  {
111  string description = element.GetAttributeString("description", string.Empty);
112  Description = Description.Fallback(TextManager.Get(description)).Fallback(description);
113  }
114  else
115  {
116  Description = Description.Fallback(TextManager.Get($"talentdescription.{Identifier}")).Fallback(string.Empty);
117  }
118  }
119 
120  public override void Dispose() { }
121  }
122 }
Color GetAttributeColor(string key, in Color def)
bool GetAttributeBool(string key, bool def)
int GetAttributeInt(string key, int def)
Identifier GetAttributeIdentifier(string key, string def)
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.
readonly Identifier Identifier
Definition: Prefab.cs:34
Prefab that has a property serves as a deterministic hash of a prefab's identifier....
readonly Sprite Icon
Definition: TalentPrefab.cs:23
readonly ImmutableHashSet< TalentMigration > Migrations
Definition: TalentPrefab.cs:37
static readonly PrefabCollection< TalentPrefab > TalentPrefabs
Definition: TalentPrefab.cs:35
LocalizedString DisplayName
Definition: TalentPrefab.cs:14
readonly Option<(Identifier PermanentStatIdentifier, int Max)> TrackedStat
When set to a value the talent tooltip will display a text showing the current value of the stat and ...
Definition: TalentPrefab.cs:29
TalentPrefab(ContentXElement element, TalentsFile file)
Definition: TalentPrefab.cs:45
readonly Option< Color > ColorOverride
Definition: TalentPrefab.cs:32
bool AbilityEffectsStackWithSameTalent
When set to false the AbilityEffects of multiple of the same talent will not be checked and only the ...
Definition: TalentPrefab.cs:21
LocalizedString Description
Definition: TalentPrefab.cs:16
override void Dispose()
ContentXElement ConfigElement
Definition: TalentPrefab.cs:40