Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Map/Levels/DestructibleLevelWall.cs
1 using Microsoft.Xna.Framework;
2 using System;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  partial class DestructibleLevelWall : LevelWall, IDamageable
8  {
9 
10  public override float Alpha
11  {
12  get
13  {
14  if (FadeOutDuration <= 0.0f || FadeOutTimer < FadeOutDuration - 1.0f) { return 1.0f; }
15  return MathHelper.Clamp(FadeOutDuration - FadeOutTimer, 0.0f, 1.0f);
16  }
17  }
18 
19  partial void AddDamageProjSpecific(float damage, Vector2 worldPosition)
20  {
21  if (damage <= 0.0f) { return; }
22  Vector2 particlePos = worldPosition;
23  Vector2 particleDir = particlePos - WorldPosition;
24  if (particleDir.LengthSquared() > 0.0001f) { particleDir = Vector2.Normalize(particleDir); }
25  if (!Cells.Any(c => c.IsPointInside(particlePos)))
26  {
27  bool intersectionFound = false;
28  foreach (var cell in Cells)
29  {
30  foreach (var edge in cell.Edges)
31  {
32  if (MathUtils.GetLineSegmentIntersection(worldPosition, cell.Center, edge.Point1 + cell.Translation, edge.Point2 + cell.Translation, out Vector2 intersection))
33  {
34  intersectionFound = true;
35  particlePos = intersection;
36  particleDir = edge.GetNormal(cell);
37  break;
38  }
39  }
40  if (intersectionFound) { break; }
41  }
42  }
43 
44  int particleAmount = MathHelper.Clamp((int)damage, 1, 10);
45  for (int i = 0; i < particleAmount; i++)
46  {
47  var particle = GameMain.ParticleManager.CreateParticle("iceexplosionsmall",
48  particlePos + Rand.Vector(5.0f),
49  particleDir * Rand.Range(30.0f, 500.0f) + Rand.Vector(20.0f));
50  GameMain.ParticleManager.CreateParticle("iceshards",
51  particlePos + Rand.Vector(5.0f),
52  particleDir * Rand.Range(100.0f, 500.0f) + Rand.Vector(100.0f));
53  }
54  }
55 
56  public void SetDamage(float damage)
57  {
58  Damage = damage;
59  if (Damage >= MaxHealth && !Destroyed)
60  {
61  CreateFragments();
62  Destroy();
63  }
64  }
65  }
66 }