Client LuaCsForBarotrauma
ExtraSubmarineInfo.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.Immutable;
4 using System.Xml.Linq;
5 
6 namespace Barotrauma
7 {
9  {
10  public string Name { get; protected set; }
11 
12  public Dictionary<Identifier, SerializableProperty> SerializableProperties { get; protected set; }
13 
15  public float MinLevelDifficulty { get; set; }
16 
17  [Serialize(100.0f, IsPropertySaveable.Yes), Editable]
18  public float MaxLevelDifficulty { get; set; }
19 
20  public ExtraSubmarineInfo(SubmarineInfo submarineInfo, XElement element)
21  {
22  Name = $"{nameof(ExtraSubmarineInfo)} ({submarineInfo.Name})";
24  }
25 
26  public ExtraSubmarineInfo(SubmarineInfo submarineInfo)
27  {
28  Name = $"{nameof(ExtraSubmarineInfo)} ({submarineInfo.Name})";
30  }
31 
33  {
34  Name = original.Name;
35  SerializableProperties = new Dictionary<Identifier, SerializableProperty>();
36  foreach (KeyValuePair<Identifier, SerializableProperty> kvp in original.SerializableProperties)
37  {
38  SerializableProperties.Add(kvp.Key, kvp.Value);
39  if (SerializableProperty.GetSupportedTypeName(kvp.Value.PropertyType) != null)
40  {
41  kvp.Value.TrySetValue(this, kvp.Value.GetValue(original));
42  }
43  }
44  }
45 
46  public virtual void Save(XElement element)
47  {
49  }
50  }
51 
53  {
55  public bool AllowDamagedWalls { get; set; }
56 
58  public bool AllowDamagedDevices { get; set; }
59 
61  public bool AllowDisconnectedWires { get; set; }
62 
64  public Level.PlacementType Placement { get; set; }
65 
66  public BeaconStationInfo(SubmarineInfo submarineInfo, XElement element) : base(submarineInfo, element)
67  {
68  Name = $"{nameof(BeaconStationInfo)} ({submarineInfo.Name})";
69  }
70 
71  public BeaconStationInfo(SubmarineInfo submarineInfo) : base(submarineInfo)
72  {
73  Name = $"{nameof(BeaconStationInfo)} ({submarineInfo.Name})";
74  }
75 
76  public BeaconStationInfo(BeaconStationInfo original) : base(original) { }
77  }
78 
80  {
81  // Unknown -> older submarines before this property was added
82  public enum HasThalamus { Unknown, Yes, No }
83 
85  public HasThalamus WreckContainsThalamus { get; private set; }
86 
87  public WreckInfo(SubmarineInfo submarineInfo, XElement element) : base(submarineInfo, element)
88  {
89  Name = $"{nameof(WreckInfo)} ({submarineInfo.Name})";
90  TryDetermineThalamusIfUnknown(element);
91  }
92 
93  public WreckInfo(SubmarineInfo submarineInfo) : base(submarineInfo)
94  {
95  Name = $"{nameof(WreckInfo)} ({submarineInfo.Name})";
96  TryDetermineThalamusIfUnknown(submarineInfo.SubmarineElement);
97  }
98 
99  public WreckInfo(WreckInfo original) : base(original) { }
100 
101  // Attempts to determine if the wreck contains a thalamus item
102  private void TryDetermineThalamusIfUnknown(XElement element)
103  {
104  if (WreckContainsThalamus != HasThalamus.Unknown) { return; }
105 
106  if (element == null)
107  {
108  // nothing we can do, oh well
110  return;
111  }
112 
113  foreach (var subElement in element.Elements())
114  {
115  if (!string.Equals(subElement.Name.ToString(), nameof(Item), StringComparison.InvariantCultureIgnoreCase)) { continue; }
116 
117  var tags = subElement.GetAttributeIdentifierImmutableHashSet(nameof(ItemPrefab.Tags), ImmutableHashSet<Identifier>.Empty);
118 
119  if (tags.Contains(Tags.Thalamus))
120  {
122  return;
123  }
124  }
125 
127  }
128  }
129 
131  {
132  [Serialize(4000.0f, IsPropertySaveable.Yes), Editable]
133  public float Reward { get; set; }
134 
135  [Serialize(50.0f, IsPropertySaveable.Yes), Editable]
136  public float PreferredDifficulty { get; set; }
137 
138  private readonly HashSet<Identifier> missionTags = new HashSet<Identifier>();
139 
140  public HashSet<Identifier> MissionTags => missionTags;
141 
142  public EnemySubmarineInfo(SubmarineInfo submarineInfo, XElement element) : base(submarineInfo, element)
143  {
144  Name = $"{nameof(EnemySubmarineInfo)} ({submarineInfo.Name})";
146  foreach (var missionTag in element.GetAttributeIdentifierArray(nameof(MissionTags), Array.Empty<Identifier>()))
147  {
148  missionTags.Add(missionTag);
149  }
150  }
151 
152  public EnemySubmarineInfo(SubmarineInfo submarineInfo) : base(submarineInfo)
153  {
154  Name = $"{nameof(EnemySubmarineInfo)} ({submarineInfo.Name})";
155  }
156 
157  public EnemySubmarineInfo(EnemySubmarineInfo original) : base(original)
158  {
159  foreach (var missionTag in original.missionTags)
160  {
161  missionTags.Add(missionTag);
162  }
163  }
164 
165  public override void Save(XElement element)
166  {
167  base.Save(element);
168  element.Add(new XAttribute(nameof(MissionTags), string.Join(',', missionTags)));
169  }
170  }
171 }
BeaconStationInfo(BeaconStationInfo original)
BeaconStationInfo(SubmarineInfo submarineInfo, XElement element)
BeaconStationInfo(SubmarineInfo submarineInfo)
HashSet< Identifier > MissionTags
EnemySubmarineInfo(EnemySubmarineInfo original)
override void Save(XElement element)
EnemySubmarineInfo(SubmarineInfo submarineInfo)
EnemySubmarineInfo(SubmarineInfo submarineInfo, XElement element)
ExtraSubmarineInfo(SubmarineInfo submarineInfo, XElement element)
ExtraSubmarineInfo(ExtraSubmarineInfo original)
Dictionary< Identifier, SerializableProperty > SerializableProperties
ExtraSubmarineInfo(SubmarineInfo submarineInfo)
virtual void Save(XElement element)
static Dictionary< Identifier, SerializableProperty > DeserializeProperties(object obj, XElement element=null)
static string GetSupportedTypeName(Type type)
static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault=false, bool ignoreEditable=false)
WreckInfo(WreckInfo original)
HasThalamus WreckContainsThalamus
WreckInfo(SubmarineInfo submarineInfo)
WreckInfo(SubmarineInfo submarineInfo, XElement element)