Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Items/Components/Holdable/Sprayer.cs
1 using Microsoft.Xna.Framework;
2 using System.Collections.Generic;
3 using System.Xml.Linq;
4 
6 {
7  partial class Sprayer : RangedWeapon
8  {
9  [Serialize(0.0f, IsPropertySaveable.No, description: "The distance at which the item can spray walls.")]
10  public float Range { get; set; }
11 
12  [Serialize(1.0f, IsPropertySaveable.No, description: "How fast the item changes the color of the walls.")]
13  public float SprayStrength { get; set; }
14 
15  private readonly Dictionary<Identifier, Color> liquidColors;
16  private ItemContainer liquidContainer;
17 
18  public Sprayer(Item item, ContentXElement element) : base(item, element)
19  {
20  item.IsShootable = true;
21  item.RequireAimToUse = true;
22 
23  foreach (var subElement in element.Elements())
24  {
25  switch (subElement.Name.ToString().ToLowerInvariant())
26  {
27  case "paintcolors":
28  {
29  liquidColors = new Dictionary<Identifier, Color>();
30  foreach (XElement paintElement in subElement.Elements())
31  {
32  Identifier paintName = paintElement.GetAttributeIdentifier("paintitem", Identifier.Empty);
33  Color paintColor = paintElement.GetAttributeColor("color", Color.Transparent);
34 
35  if (paintName != string.Empty)
36  {
37  liquidColors.Add(paintName, paintColor);
38  }
39  }
40  }
41  break;
42  }
43  }
44  InitProjSpecific(element);
45  }
46 
47  public override void OnItemLoaded()
48  {
49  liquidContainer = item.GetComponent<ItemContainer>();
50  }
51 
52  partial void InitProjSpecific(ContentXElement element);
53 
54 #if SERVER
55  public override bool Use(float deltaTime, Character character = null)
56  {
57  return character != null || character.Removed;
58  }
59 #endif
60 
61  }
62 }
bool IsShootable
Should the item's Use method be called with the "Use" or with the "Shoot" key?
bool RequireAimToUse
If true, the user has to hold the "aim" key before use is registered. False by default.
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...