Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/Components/ElectricalDischarger.cs
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
4 using System;
5 
7 {
8  partial class ElectricalDischarger : Powered
9  {
10  private static SpriteSheet electricitySprite;
11 
12  private int frameOffset;
13 
14  partial void InitProjSpecific()
15  {
16  if (electricitySprite == null)
17  {
18  electricitySprite = new SpriteSheet("Content/Lights/Electricity.png", 4, 4, new Vector2(0.5f, 0.0f));
19  }
20  }
21 
22  partial void DischargeProjSpecific()
23  {
24  PlaySound(ActionType.OnUse);
25  foreach (Node node in nodes)
26  {
27  GameMain.ParticleManager.CreateParticle("swirlysmoke", node.WorldPosition, Vector2.Zero);
28 
29  if (node.ParentIndex > -1)
30  {
31  CreateParticlesBetween(nodes[node.ParentIndex].WorldPosition, node.WorldPosition);
32  }
33  }
34  foreach (var character in charactersInRange)
35  {
36  CreateParticlesBetween(character.character.WorldPosition, character.node.WorldPosition);
37  }
38 
39  static void CreateParticlesBetween(Vector2 start, Vector2 end)
40  {
41  const float ParticleInterval = 50.0f;
42  Vector2 diff = end - start;
43  float dist = diff.Length();
44  Vector2 normalizedDiff = MathUtils.NearlyEqual(dist, 0.0f) ? Vector2.Zero : diff / dist;
45  for (float x = 0.0f; x < dist; x += ParticleInterval)
46  {
47  var spark = GameMain.ParticleManager.CreateParticle("ElectricShock", start + normalizedDiff * x, Vector2.Zero);
48  if (spark != null)
49  {
50  spark.Size *= 0.3f;
51  }
52  }
53  }
54  }
55 
56  public void DrawElectricity(SpriteBatch spriteBatch)
57  {
58  if (timer <= 0.0f && Screen.Selected is { IsEditor: false }) { return; }
59  for (int i = 0; i < nodes.Count; i++)
60  {
61  if (nodes[i].Length <= 1.0f) { continue; }
62  var node = nodes[i];
63  electricitySprite.Draw(spriteBatch,
64  (i + frameOffset) % electricitySprite.FrameCount,
65  new Vector2(node.WorldPosition.X, -node.WorldPosition.Y),
66  Color.Lerp(Color.LightBlue, Color.White, Rand.Range(0.0f, 1.0f)),
67  electricitySprite.Origin, -node.Angle - MathHelper.PiOver2,
68  new Vector2(
69  Math.Min(node.Length / electricitySprite.FrameSize.X, 1.0f) * Rand.Range(0.5f, 2.0f),
70  node.Length / electricitySprite.FrameSize.Y) * Rand.Range(1.0f, 1.2f));
71  }
72 
73  if (GameMain.DebugDraw)
74  {
75  for (int i = 1; i < nodes.Count; i++)
76  {
77  GUI.DrawLine(spriteBatch,
78  new Vector2(nodes[i].WorldPosition.X, -nodes[i].WorldPosition.Y),
79  new Vector2(nodes[nodes[i].ParentIndex].WorldPosition.X, -nodes[nodes[i].ParentIndex].WorldPosition.Y),
80  Color.LightCyan,
81  width: 3);
82 
83  if (nodes[i].Length <= 1.0f) { continue; }
84  GUI.DrawRectangle(spriteBatch, new Vector2(nodes[i].WorldPosition.X, -nodes[i].WorldPosition.Y), Vector2.One * 10, Color.LightCyan, isFilled: true);
85  }
86  }
87  }
88 
89  public void ClientEventRead(IReadMessage msg, float sendingTime)
90  {
91  UInt16 userID = msg.ReadUInt16();
92  if (userID != Entity.NullEntityID)
93  {
94  user = Entity.FindEntityByID(userID) as Character;
95  }
97  charging = true;
98  timer = Duration;
99  IsActive = true;
100  }
101  }
102 }
const ushort NullEntityID
Definition: Entity.cs:14
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
Definition: Entity.cs:204
static bool DebugDraw
Definition: GameMain.cs:29
float powerConsumption
The maximum amount of power the item can draw from connected items
ActionType
ActionTypes define when a StatusEffect is executed.
Definition: Enums.cs:19