Client LuaCsForBarotrauma
BackgroundCreaturePrefab.cs
1 using System.Collections.Generic;
2 using System.Xml.Linq;
3 
4 namespace Barotrauma
5 {
7  {
8  public readonly Sprite Sprite, LightSprite;
9  public readonly DeformableSprite DeformableSprite, DeformableLightSprite;
10 
11  public readonly string Name;
12 
13  public readonly XElement Config;
14 
15  [Serialize(1.0f, IsPropertySaveable.Yes)]
16  public float Speed { get; private set; }
17 
18  [Serialize(0.0f, IsPropertySaveable.Yes)]
19  public float WanderAmount { get; private set; }
20 
21  [Serialize(0.0f, IsPropertySaveable.Yes)]
22  public float WanderZAmount { get; private set; }
23 
25  public int SwarmMin { get; private set; }
26 
28  public int SwarmMax { get; private set; }
29 
30  [Serialize(200.0f, IsPropertySaveable.Yes)]
31  public float SwarmRadius { get; private set; }
32 
33  [Serialize(0.2f, IsPropertySaveable.Yes)]
34  public float SwarmCohesion { get; private set; }
35 
36  [Serialize(10.0f, IsPropertySaveable.Yes)]
37  public float MinDepth { get; private set; }
38 
39  [Serialize(1000.0f, IsPropertySaveable.Yes)]
40  public float MaxDepth { get; private set; }
41 
42  [Serialize(false, IsPropertySaveable.Yes)]
43  public bool DisableRotation { get; private set; }
44 
45  [Serialize(false, IsPropertySaveable.Yes)]
46  public bool DisableFlipping { get; private set; }
47 
48  [Serialize(1.0f, IsPropertySaveable.Yes)]
49  public float Scale { get; private set; }
50 
51  [Serialize(1.0f, IsPropertySaveable.Yes)]
52  public float Commonness { get; private set; }
53 
54  [Serialize(1000, IsPropertySaveable.Yes)]
55  public int MaxCount { get; private set; }
56 
57  [Serialize(0.0f, IsPropertySaveable.Yes)]
58  public float FlashInterval { get; private set; }
59 
60  [Serialize(0.0f, IsPropertySaveable.Yes)]
61  public float FlashDuration { get; private set; }
62 
63 
68  public Dictionary<Identifier, float> OverrideCommonness = new Dictionary<Identifier, float>();
69 
71  {
72  Name = element.Name.ToString();
73 
74  Config = element;
75 
77 
78  foreach (var subElement in element.Elements())
79  {
80  switch (subElement.Name.ToString().ToLowerInvariant())
81  {
82  case "sprite":
83  Sprite = new Sprite(subElement, lazyLoad: true);
84  break;
85  case "deformablesprite":
86  DeformableSprite = new DeformableSprite(subElement, lazyLoad: true);
87  break;
88  case "lightsprite":
89  LightSprite = new Sprite(subElement, lazyLoad: true);
90  break;
91  case "deformablelightsprite":
92  DeformableLightSprite = new DeformableSprite(subElement, lazyLoad: true);
93  break;
94  case "overridecommonness":
95  Identifier levelType = subElement.GetAttributeIdentifier("leveltype", Identifier.Empty);
96  if (!OverrideCommonness.ContainsKey(levelType))
97  {
98  OverrideCommonness.Add(levelType, subElement.GetAttributeFloat("commonness", 1.0f));
99  }
100  break;
101  }
102  }
103  }
104 
105  public float GetCommonness(LevelGenerationParams generationParams)
106  {
107  if (generationParams != null &&
108  !generationParams.Identifier.IsEmpty &&
109  (OverrideCommonness.TryGetValue(generationParams.Identifier, out float commonness) ||
110  (!generationParams.OldIdentifier.IsEmpty && OverrideCommonness.TryGetValue(generationParams.OldIdentifier, out commonness))))
111  {
112  return commonness;
113  }
114  return Commonness;
115  }
116  }
117 
118 }
BackgroundCreaturePrefab(ContentXElement element)
Dictionary< Identifier, float > OverrideCommonness
Overrides the commonness of the object in a specific level type. Key = name of the level type,...
readonly DeformableSprite DeformableSprite
float GetCommonness(LevelGenerationParams generationParams)
readonly Identifier Identifier
Definition: Prefab.cs:34
static Dictionary< Identifier, SerializableProperty > DeserializeProperties(object obj, XElement element=null)