Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentAutoJump.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
13 public double m_lastAutoJumpTime;
14
15 public bool m_alwaysEnabled;
16
17 public float m_jumpStrength;
18
19 public bool m_collidedWithBody;
20
22
23 public virtual void Update(float dt) {
25 && m_subsystemTime.GameTime - m_lastAutoJumpTime > 0.3
26 && m_componentCreature.ComponentBody.CrouchFactor == 0f) {
27 Vector2? lastWalkOrder = m_componentCreature.ComponentLocomotion.LastWalkOrder;
28 if (lastWalkOrder.HasValue) {
29 Vector2 vector = new(
30 m_componentCreature.ComponentBody.CollisionVelocityChange.X,
31 m_componentCreature.ComponentBody.CollisionVelocityChange.Z
32 );
33 if (vector != Vector2.Zero
35 Vector2 v = Vector2.Normalize(vector);
36 Vector3 vector2 = m_componentCreature.ComponentBody.Matrix.Right * lastWalkOrder.Value.X
37 + m_componentCreature.ComponentBody.Matrix.Forward * lastWalkOrder.Value.Y;
38 Vector2 v2 = Vector2.Normalize(new Vector2(vector2.X, vector2.Z));
39 bool flag = false;
40 Vector3 v3 = Vector3.Zero;
41 Vector3 vector3 = Vector3.Zero;
42 Vector3 vector4 = Vector3.Zero;
43 if (Vector2.Dot(v2, -v) > 0.6f) {
44 if (Vector2.Dot(v2, Vector2.UnitX) > 0.6f) {
45 v3 = m_componentCreature.ComponentBody.Position + Vector3.UnitX;
46 vector3 = v3 - Vector3.UnitZ;
47 vector4 = v3 + Vector3.UnitZ;
48 flag = true;
49 }
50 else if (Vector2.Dot(v2, -Vector2.UnitX) > 0.6f) {
51 v3 = m_componentCreature.ComponentBody.Position - Vector3.UnitX;
52 vector3 = v3 - Vector3.UnitZ;
53 vector4 = v3 + Vector3.UnitZ;
54 flag = true;
55 }
56 else if (Vector2.Dot(v2, Vector2.UnitY) > 0.6f) {
57 v3 = m_componentCreature.ComponentBody.Position + Vector3.UnitZ;
58 vector3 = v3 - Vector3.UnitX;
59 vector4 = v3 + Vector3.UnitX;
60 flag = true;
61 }
62 else if (Vector2.Dot(v2, -Vector2.UnitY) > 0.6f) {
63 v3 = m_componentCreature.ComponentBody.Position - Vector3.UnitZ;
64 vector3 = v3 - Vector3.UnitX;
65 vector4 = v3 + Vector3.UnitX;
66 flag = true;
67 }
68 }
69 if (flag) {
70 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(Terrain.ToCell(v3.X), Terrain.ToCell(v3.Y), Terrain.ToCell(v3.Z));
71 int cellValue2 = m_subsystemTerrain.Terrain.GetCellValue(
72 Terrain.ToCell(vector3.X),
73 Terrain.ToCell(vector3.Y),
74 Terrain.ToCell(vector3.Z)
75 );
76 int cellValue3 = m_subsystemTerrain.Terrain.GetCellValue(
77 Terrain.ToCell(vector4.X),
78 Terrain.ToCell(vector4.Y),
79 Terrain.ToCell(vector4.Z)
80 );
81 int cellValue4 = m_subsystemTerrain.Terrain.GetCellValue(
82 Terrain.ToCell(v3.X),
83 Terrain.ToCell(v3.Y) + 1,
84 Terrain.ToCell(v3.Z)
85 );
86 int cellValue5 = m_subsystemTerrain.Terrain.GetCellValue(
87 Terrain.ToCell(vector3.X),
88 Terrain.ToCell(vector3.Y) + 1,
89 Terrain.ToCell(vector3.Z)
90 );
91 int cellValue6 = m_subsystemTerrain.Terrain.GetCellValue(
92 Terrain.ToCell(vector4.X),
93 Terrain.ToCell(vector4.Y) + 1,
94 Terrain.ToCell(vector4.Z)
95 );
96 int cellContents = Terrain.ExtractContents(cellValue);
97 int cellContents2 = Terrain.ExtractContents(cellValue2);
98 int cellContents3 = Terrain.ExtractContents(cellValue3);
99 int cellContents4 = Terrain.ExtractContents(cellValue4);
100 int cellContents5 = Terrain.ExtractContents(cellValue5);
101 int cellContents6 = Terrain.ExtractContents(cellValue6);
102 Block block = BlocksManager.Blocks[cellContents];
103 Block block2 = BlocksManager.Blocks[cellContents2];
104 Block block3 = BlocksManager.Blocks[cellContents3];
105 Block block4 = BlocksManager.Blocks[cellContents4];
106 Block block5 = BlocksManager.Blocks[cellContents5];
107 Block block6 = BlocksManager.Blocks[cellContents6];
108 if (!block.NoAutoJump
109 && ((block.IsCollidable_(cellValue) && !block4.IsCollidable_(cellValue4))
110 || (block2.IsCollidable_(cellValue2) && !block5.IsCollidable_(cellValue5))
111 || (block3.IsCollidable_(cellValue3) && !block6.IsCollidable_(cellValue6)))) {
112 m_componentCreature.ComponentLocomotion.JumpOrder = MathUtils.Max(
114 m_componentCreature.ComponentLocomotion.JumpOrder
115 );
117 }
118 }
119 }
120 }
121 }
122 m_collidedWithBody = false;
123 }
124
125 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
126 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
127 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
128 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
129 m_alwaysEnabled = valuesDictionary.GetValue<bool>("AlwaysEnabled");
130 m_jumpStrength = valuesDictionary.GetValue<float>("JumpStrength");
131 m_componentCreature.ComponentBody.CollidedWithBody += delegate { m_collidedWithBody = true; };
132 }
133 }
134}
static int Max(int x1, int x2)
virtual bool IsCollidable_(int value)
bool NoAutoJump
SubsystemTerrain m_subsystemTerrain
virtual void Update(float dt)
ComponentCreature m_componentCreature
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
static float Dot(Vector2 v1, Vector2 v2)
static readonly Vector2 Zero
static readonly Vector2 UnitY
static readonly Vector2 UnitX
static Vector2 Normalize(Vector2 v)
static readonly Vector3 Zero
static readonly Vector3 UnitX
static readonly Vector3 UnitZ