Client LuaCsForBarotrauma
NPCPersonalityTrait.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Xml.Linq;
5 
6 namespace Barotrauma
7 {
9  {
11 
12  public readonly LocalizedString DisplayName;
13 
14  public readonly List<string> AllowedDialogTags;
15 
16  private readonly float commonness;
17  public float Commonness
18  {
19  get { return commonness; }
20  }
21 
22  public NPCPersonalityTrait(XElement element, NPCPersonalityTraitsFile file)
23  : base(file, element.GetAttributeIdentifier("identifier", element.GetAttributeIdentifier("name", Identifier.Empty)))
24  {
25  string name = element.GetAttributeString("name", null);
26  if (name == null)
27  {
28  DisplayName = TextManager.Get("personalitytrait." + Identifier)
29  .Fallback(Identifier.ToString());
30  }
31  else
32  {
33  DisplayName = name;
34  }
35  AllowedDialogTags = new List<string>(element.GetAttributeStringArray("alloweddialogtags", Array.Empty<string>()));
36  commonness = element.GetAttributeFloat("commonness", 1.0f);
37  }
38 
39  public static NPCPersonalityTrait GetRandom(string seed)
40  {
41  var rand = new MTRandom(ToolBox.StringToInt(seed));
42  return ToolBox.SelectWeightedRandom(Traits.OrderBy(t => t.UintIdentifier), t => t.commonness, rand);
43  }
44 
45  public override void Dispose() { }
46  }
47 }
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.
Mersenne Twister based random
Definition: MTRandom.cs:9
readonly List< string > AllowedDialogTags
static readonly PrefabCollection< NPCPersonalityTrait > Traits
NPCPersonalityTrait(XElement element, NPCPersonalityTraitsFile file)
readonly LocalizedString DisplayName
static NPCPersonalityTrait GetRandom(string seed)
readonly Identifier Identifier
Definition: Prefab.cs:34
Prefab that has a property serves as a deterministic hash of a prefab's identifier....