Client LuaCsForBarotrauma
SkillPrefab.cs
1 using System.Globalization;
2 
3 namespace Barotrauma
4 {
5  class SkillPrefab
6  {
7  public readonly Identifier Identifier;
8 
9  private readonly Range<float> levelRange;
10  private readonly Range<float> levelRangePvP;
11 
15  public readonly float PriceMultiplier;
16 
17  public bool IsPrimarySkill { get; }
18 
19  public SkillPrefab(ContentXElement element)
20  {
21  Identifier = element.GetAttributeIdentifier("identifier", "");
22  PriceMultiplier = element.GetAttributeFloat("pricemultiplier", 25.0f);
23  levelRange = GetSkillRange("level", element, defaultValue: new Range<float>(0, 0));
24  levelRangePvP = GetSkillRange("pvplevel", element, defaultValue: levelRange);
25  IsPrimarySkill = element.GetAttributeBool("primary", false);
26 
27  static Range<float> GetSkillRange(string attributeName, ContentXElement element, Range<float> defaultValue)
28  {
29  string levelString = element.GetAttributeString(attributeName, string.Empty);
30  if (levelString.Contains(','))
31  {
32  var rangeVector2 = XMLExtensions.ParseVector2(levelString, false);
33  return new Range<float>(rangeVector2.X, rangeVector2.Y);
34  }
35  else if (float.TryParse(levelString, NumberStyles.Any, CultureInfo.InvariantCulture, out float skillLevel))
36  {
37  return new Range<float>(skillLevel, skillLevel);
38  }
39  else
40  {
41  return defaultValue;
42  }
43  }
44  }
45 
46  public Range<float> GetLevelRange(bool isPvP)
47  {
48  return isPvP ? levelRangePvP : levelRange;
49  }
50  }
51 }
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
bool GetAttributeBool(string key, bool def)
Identifier GetAttributeIdentifier(string key, string def)
readonly float PriceMultiplier
How much this skill affects characters' hiring cost
Definition: SkillPrefab.cs:15
SkillPrefab(ContentXElement element)
Definition: SkillPrefab.cs:19
readonly Identifier Identifier
Definition: SkillPrefab.cs:7
Range< float > GetLevelRange(bool isPvP)
Definition: SkillPrefab.cs:46