Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemGrassTrapBlockBehavior.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
5 public class TrapValue {
6 public float Damage;
7 }
8
9 public Dictionary<Point3, TrapValue> m_trapValues = [];
10
11 public List<Point3> m_toRemove = [];
12
13 public override int[] HandledBlocks => [87];
14
16
17 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody) {
18 if (cellFace.Face == 4
19 && componentBody.Mass > 20f) {
20 Point3 key = new(cellFace.X, cellFace.Y, cellFace.Z);
21 if (!m_trapValues.TryGetValue(key, out TrapValue value)) {
22 value = new TrapValue();
23 m_trapValues.Add(key, value);
24 }
25 value.Damage += 0f - velocity;
26 }
27 }
28
29 public virtual void Update(float dt) {
30 foreach (KeyValuePair<Point3, TrapValue> trapValue in m_trapValues) {
31 if (trapValue.Value.Damage > 1f) {
32 for (int i = -1; i <= 1; i++) {
33 for (int j = -1; j <= 1; j++) {
34 if (MathF.Abs(i) + MathF.Abs(j) <= 1
35 && SubsystemTerrain.Terrain.GetCellContents(trapValue.Key.X + i, trapValue.Key.Y, trapValue.Key.Z + j) == 87) {
36 SubsystemTerrain.DestroyCell(
37 0,
38 trapValue.Key.X + i,
39 trapValue.Key.Y,
40 trapValue.Key.Z + j,
41 0,
42 false,
43 false
44 );
45 }
46 }
47 }
48 trapValue.Value.Damage = 0f;
49 }
50 else {
51 trapValue.Value.Damage -= 0.5f * dt;
52 }
53 if (trapValue.Value.Damage <= 0f) {
54 m_toRemove.Add(trapValue.Key);
55 }
56 }
57 foreach (Point3 item in m_toRemove) {
58 m_trapValues.Remove(item);
59 }
60 m_toRemove.Clear();
61 }
62 }
63}
override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)