Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFishModel.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
17
18 public bool m_hasVerticalTail;
19
20 public float m_bitingPhase;
21
22 public float m_tailWagPhase;
23
25
26 public float m_digInDepth;
27
28 public float m_digInTailPhase;
29
30 public float? BendOrder { get; set; }
31
32 public float DigInOrder { get; set; }
33
34 public override float AttackPhase {
35 get => m_bitingPhase;
36 set => m_bitingPhase = value;
37 }
38
39 public override void Update(float dt) {
40 if (m_componentCreature.ComponentLocomotion.LastSwimOrder.HasValue
41 && m_componentCreature.ComponentLocomotion.LastSwimOrder.Value != Vector3.Zero) {
42 float num = m_componentCreature.ComponentLocomotion.LastSwimOrder.Value.LengthSquared() > 0.99f ? 1.75f : 1f;
44 }
45 else {
47 }
48 if (BendOrder.HasValue) {
50 m_tailTurn.X = 0f;
51 m_tailTurn.Y = BendOrder.Value;
52 }
53 else {
54 m_tailTurn.X = BendOrder.Value;
55 m_tailTurn.Y = 0f;
56 }
57 }
58 else {
59 m_tailTurn.X += MathUtils.Saturate(2f * m_componentCreature.ComponentLocomotion.TurnSpeed * dt)
60 * (0f - m_componentCreature.ComponentLocomotion.LastTurnOrder.X - m_tailTurn.X);
61 }
63 float num2 = (DigInOrder - m_digInDepth) * MathUtils.Min(1.5f * dt, 1f);
64 m_digInDepth += num2;
65 m_digInTailPhase += 20f * num2;
66 }
67 else if (DigInOrder < m_digInDepth) {
68 m_digInDepth += (DigInOrder - m_digInDepth) * MathUtils.Min(5f * dt, 1f);
69 }
70 float num3 = 0.33f * m_componentCreature.ComponentLocomotion.TurnSpeed;
71 float num4 = 1f * m_componentCreature.ComponentLocomotion.TurnSpeed;
72 IsAttackHitMoment = false;
73 if (AttackOrder || FeedOrder) {
74 if (AttackOrder) {
76 }
77 float bitingPhase = m_bitingPhase;
79 if (AttackOrder
80 && bitingPhase < 0.5f
81 && m_bitingPhase >= 0.5f) {
82 IsAttackHitMoment = true;
83 }
84 }
85 else {
86 if (m_tailWagPhase != 0f) {
88 }
89 if (m_bitingPhase != 0f) {
91 }
92 }
93 AttackOrder = false;
94 FeedOrder = false;
95 BendOrder = null;
96 DigInOrder = 0f;
97 base.Update(dt);
98 }
99
100 public override void AnimateCreature() {
101 Vector3 vector = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();
102 if (m_componentCreature.ComponentHealth.Health == 0f) {
103 float num = m_componentCreature.ComponentBody.BoundingBox.Max.Y - m_componentCreature.ComponentBody.BoundingBox.Min.Y;
104 Vector3 position = m_componentCreature.ComponentBody.Position + 1f * num * DeathPhase * Vector3.UnitY;
106 m_bodyBone.Index,
107 Matrix.CreateFromYawPitchRoll(vector.X, 0f, MathF.PI * DeathPhase) * Matrix.CreateTranslation(position)
108 );
111 if (m_jawBone != null) {
113 }
114 return;
115 }
116 if (m_componentCreature.ComponentBody.IsEmbeddedInIce) {
117 Matrix value = Matrix.CreateFromYawPitchRoll(vector.X, 0f, 0f)
118 * Matrix.CreateTranslation(m_componentCreature.ComponentBody.Position + new Vector3(0f, 0f - m_digInDepth, 0f));
119 SetBoneTransform(m_bodyBone.Index, value);
120 return;
121 }
122 float num2 = m_digInTailPhase + m_tailWagPhase;
123 float num3;
124 float num4;
125 float num5;
126 float num6;
127 if (m_hasVerticalTail) {
128 num3 = MathUtils.DegToRad(25f) * Math.Clamp(0.5f * MathF.Sin(MathF.PI * 2f * num2) - m_tailTurn.X, -1f, 1f);
129 num4 = MathUtils.DegToRad(30f)
130 * Math.Clamp(0.5f * MathF.Sin(2f * (MathF.PI * MathUtils.Max(num2 - 0.25f, 0f))) - m_tailTurn.X, -1f, 1f);
131 num5 = MathUtils.DegToRad(25f) * Math.Clamp(0.5f * MathF.Sin(MathF.PI * 2f * MovementAnimationPhase) - m_tailTurn.Y, -1f, 1f);
132 num6 = MathUtils.DegToRad(30f)
133 * Math.Clamp(0.5f * MathF.Sin(MathF.PI * 2f * MathUtils.Max(MovementAnimationPhase - 0.25f, 0f)) - m_tailTurn.Y, -1f, 1f);
134 }
135 else {
136 num3 = MathUtils.DegToRad(25f)
137 * Math.Clamp(0.5f * MathF.Sin(MathF.PI * 2f * (MovementAnimationPhase + num2)) - m_tailTurn.X, -1f, 1f);
138 num4 = MathUtils.DegToRad(30f)
139 * Math.Clamp(
140 0.5f * MathF.Sin(2f * (MathF.PI * MathUtils.Max(MovementAnimationPhase + num2 - 0.25f, 0f))) - m_tailTurn.X,
141 -1f,
142 1f
143 );
144 num5 = MathUtils.DegToRad(25f) * Math.Clamp(0f - m_tailTurn.Y, -1f, 1f);
145 num6 = MathUtils.DegToRad(30f) * Math.Clamp(0f - m_tailTurn.Y, -1f, 1f);
146 }
147 float radians = 0f;
148 if (m_bitingPhase > 0f) {
149 radians = (0f - MathUtils.DegToRad(30f)) * MathF.Sin(MathF.PI * m_bitingPhase);
150 }
151 Matrix value2 = Matrix.CreateFromYawPitchRoll(vector.X, 0f, 0f)
152 * Matrix.CreateTranslation(m_componentCreature.ComponentBody.Position + new Vector3(0f, 0f - m_digInDepth, 0f));
153 SetBoneTransform(m_bodyBone.Index, value2);
154 Matrix identity = Matrix.Identity;
155 if (num3 != 0f) {
156 identity *= Matrix.CreateRotationZ(num3);
157 }
158 if (num5 != 0f) {
159 identity *= Matrix.CreateRotationX(num5);
160 }
161 Matrix identity2 = Matrix.Identity;
162 if (num4 != 0f) {
163 identity2 *= Matrix.CreateRotationZ(num4);
164 }
165 if (num6 != 0f) {
166 identity2 *= Matrix.CreateRotationX(num6);
167 }
168 SetBoneTransform(m_tail1Bone.Index, identity);
169 SetBoneTransform(m_tail2Bone.Index, identity2);
170 if (m_jawBone != null) {
172 }
173 }
174
175 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
176 base.Load(valuesDictionary, idToEntityMap);
177 m_hasVerticalTail = valuesDictionary.GetValue<bool>("HasVerticalTail");
178 m_swimAnimationSpeed = valuesDictionary.GetValue<float>("SwimAnimationSpeed");
179 }
180
181 public override void SetModel(Model model) {
182 base.SetModel(model);
183 if (IsSet) {
184 return;
185 }
186 if (Model != null) {
187 m_bodyBone = Model.FindBone("Body");
188 m_tail1Bone = Model.FindBone("Tail1");
189 m_tail2Bone = Model.FindBone("Tail2");
190 m_jawBone = Model.FindBone("Jaw", false);
191 }
192 else {
193 m_bodyBone = null;
194 m_tail1Bone = null;
195 m_tail2Bone = null;
196 m_jawBone = null;
197 }
198 }
199
200 public override Vector3 CalculateEyePosition() {
201 Matrix matrix = m_componentCreature.ComponentBody.Matrix;
202 Vector3 result = m_componentCreature.ComponentBody.Position
203 + matrix.Up * 1f * m_componentCreature.ComponentBody.BoxSize.Y
204 + matrix.Forward * 0.45f * m_componentCreature.ComponentBody.BoxSize.Z;
206 "RecalculateModelEyePosition",
207 loader => {
208 loader.RecalculateModelEyePosition(this, ref result);
209 return false;
210 }
211 );
212 return result;
213 }
214 }
215}
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static float Saturate(float x)
static int Max(int x1, int x2)
static float DegToRad(float degrees)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
override void Update(float dt)
override Vector3 CalculateEyePosition()
override void SetModel(Model model)
virtual void SetBoneTransform(int boneIndex, Matrix? transformation)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Matrix CreateRotationX(float radians)
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreateRotationZ(float radians)
static readonly Matrix Identity
static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static readonly Vector3 Zero
static readonly Vector3 UnitY