Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Items/Components/Holdable/IdCard.cs
1 using Microsoft.Xna.Framework;
2 using System.Collections.Immutable;
3 
5 {
6  partial class IdCard : Pickable
7  {
8  [Serialize(CharacterTeamType.None, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
10  {
11  get;
12  set;
13  }
14 
15  [Serialize(0, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
17  {
18  get;
19  set;
20  }
21 
22  [Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
23  public string OwnerTags
24  {
25  get => string.Join(',', OwnerTagSet);
26  set => OwnerTagSet = value.Split(',').ToIdentifiers().ToImmutableHashSet();
27  }
28 
29  [Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
30  public string Description
31  {
32  get;
33  set;
34  }
35 
36  public ImmutableHashSet<Identifier> OwnerTagSet { get; set; }
37 
38  [Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
39  public string OwnerName { get; set; }
40 
41  private string ownerNameLocalized;
42  [Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
43  public string OwnerNameLocalized
44  {
45  get { return ownerNameLocalized; }
46  set
47  {
48  if (value.IsNullOrWhiteSpace()) { return; }
49  ownerNameLocalized = value;
50  OwnerName = TextManager.Get(value).Fallback(value).Value;
51  }
52  }
53 
54  [Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
55  public Identifier OwnerJobId { get; set; }
56 
57  public JobPrefab OwnerJob => JobPrefab.Prefabs.TryGet(OwnerJobId, out var prefab) ? prefab : null;
58 
59  [Serialize(-1, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
60  public int OwnerHairIndex { get; set; }
61 
62  [Serialize(-1, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
63  public int OwnerBeardIndex { get; set; }
64 
65  [Serialize(-1, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
66  public int OwnerMoustacheIndex { get; set; }
67 
68  [Serialize(-1, IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
69  public int OwnerFaceAttachmentIndex { get; set; }
70 
71  [Serialize("#ffffff", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
72  public Color OwnerHairColor { get; set; }
73 
74  [Serialize("#ffffff", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
75  public Color OwnerFacialHairColor { get; set; }
76 
77  [Serialize("#ffffff", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
78  public Color OwnerSkinColor { get; set; }
79 
80  [Serialize("0,0", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
81  public Vector2 OwnerSheetIndex { get; set; }
82 
83  public IdCard(Item item, ContentXElement element) : base(item, element) { }
84 
85  public void Initialize(WayPoint spawnPoint, Character character)
86  {
87  item.AddTag("name:" + character.Name);
88 
89  CharacterInfo info = character.Info;
90  if (info == null) { return; }
91 
92  if (spawnPoint != null)
93  {
94  foreach (string s in spawnPoint.IdCardTags)
95  {
96  item.AddTag(s);
97  }
98  if (!string.IsNullOrWhiteSpace(spawnPoint.IdCardDesc))
99  {
100  item.Description = Description = spawnPoint.IdCardDesc;
101  }
102  }
103 
104  TeamID = info.TeamID;
105 
106  var head = info.Head;
107  if (head == null) { return; }
108 
109  OwnerName = info.Name;
110  OwnerJobId = info.Job?.Prefab.Identifier ?? Identifier.Empty;
111  item.AddTag($"jobid:{OwnerJobId}");
112  OwnerTagSet = info.Head.Preset.TagSet;
113  OwnerHairIndex = head.HairIndex;
114  OwnerBeardIndex = head.BeardIndex;
115  OwnerMoustacheIndex = head.MoustacheIndex;
116  OwnerFaceAttachmentIndex = head.FaceAttachmentIndex;
117  OwnerHairColor = head.HairColor;
118  OwnerFacialHairColor = head.FacialHairColor;
119  OwnerSkinColor = head.SkinColor;
120  OwnerSheetIndex = head.SheetIndex;
121  }
122 
123  public override void Equip(Character character)
124  {
125  base.Equip(character);
126  character.Info?.CheckDisguiseStatus(true, this);
127  }
128 
129  public override void Unequip(Character character)
130  {
131  base.Unequip(character);
132  character.Info?.CheckDisguiseStatus(true, this);
133  }
134  public override void OnItemLoaded()
135  {
136  if (!string.IsNullOrEmpty(Description))
137  {
139  }
140  }
141  }
142 }
Stores information about the Character that is needed between rounds in the menu etc....
void CheckDisguiseStatus(bool handleBuff, IdCard idCard=null)
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
JobPrefab Prefab
Definition: Job.cs:18
static readonly PrefabCollection< JobPrefab > Prefabs
readonly Identifier Identifier
Definition: Prefab.cs:34