Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentHumanModel.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
38 public float m_sneakFactor;
39 public float m_lieDownFactorEye;
40
42
44
45 public float m_walkLegsAngle;
46
47 public float m_walkBobHeight;
48
49 public float m_headingOffset;
50
51 public float m_punchFactor;
52
53 public float m_punchPhase;
54
55 public int m_punchCounter;
56
57 public float m_footstepsPhase;
58
59 public bool m_rowLeft;
60
61 public bool m_rowRight;
62
63 public float m_aimHandAngle;
64
66
68
70
72
74
76
78
79 public override float AttackPhase {
80 get => m_punchPhase;
81 set => m_punchPhase = value;
82 }
83
84 public override float AttackFactor {
85 get => m_punchFactor;
86 set => m_punchFactor = value;
87 }
88
89 public override void Update(float dt) {
90 m_sneakFactor = m_componentCreature.ComponentBody.IsCrouching
91 ? MathUtils.Min(m_sneakFactor + 2f * dt, 1f)
92 : MathUtils.Max(m_sneakFactor - 2f * dt, 0f);
93 if ((m_componentSleep != null && m_componentSleep.IsSleeping)
94 || m_componentCreature.ComponentHealth.Health <= 0f) {
97 }
98 else {
101 }
102 bool flag = true;
103 bool flag2 = true;
104 float footstepsPhase = m_footstepsPhase;
105 if (m_componentCreature.ComponentLocomotion.LadderValue.HasValue) {
106 m_footstepsPhase += 1.5f * m_walkAnimationSpeed * m_componentCreature.ComponentBody.Velocity.Length() * dt;
107 flag2 = false;
108 }
109 else if (!m_componentCreature.ComponentLocomotion.IsCreativeFlyEnabled) {
110 float num = m_componentCreature.ComponentLocomotion.SlipSpeed
111 ?? (m_componentCreature.ComponentBody.Velocity.XZ - m_componentCreature.ComponentBody.StandingOnVelocity.XZ).Length();
112 if (num > 0.5f) {
114 m_footstepsPhase += 1f * m_walkAnimationSpeed * num * dt;
115 flag = false;
116 flag2 = false;
117 }
118 }
119 if (flag) {
120 float num2 = 0.5f * MathF.Floor(2f * MovementAnimationPhase);
121 if (MovementAnimationPhase != num2) {
123 ? MathUtils.Min(MovementAnimationPhase + 2f * dt, num2 + 0.5f)
124 : MathUtils.Max(MovementAnimationPhase - 2f * dt, num2);
125 }
126 }
127 if (flag2) {
128 m_footstepsPhase = 0f;
129 }
130 float num3 = 0f;
131 ComponentMount componentMount = m_componentRider?.Mount;
132 if (componentMount != null) {
133 ComponentCreatureModel componentCreatureModel = componentMount.Entity.FindComponent<ComponentCreatureModel>();
134 if (componentCreatureModel != null) {
135 Bob = componentCreatureModel.Bob;
136 num3 = Bob;
137 }
138 m_headingOffset = 0f;
139 }
140 else {
141 float x = MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase);
142 num3 = m_walkBobHeight * MathUtils.Sqr(x);
143 float num4 = 0f;
144 if (m_componentCreature.ComponentLocomotion.LastWalkOrder.HasValue
145 && m_componentCreature.ComponentLocomotion.LastWalkOrder != Vector2.Zero) {
146 num4 = Vector2.Angle(Vector2.UnitY, m_componentCreature.ComponentLocomotion.LastWalkOrder.Value);
147 }
150 }
151 float num5 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
152 Bob += num5 * (num3 - Bob);
153 IsAttackHitMoment = false;
154 if (AttackOrder) {
155 m_punchFactor = MathUtils.Min(m_punchFactor + 4f * dt, 1f);
156 float punchPhase = m_punchPhase;
158 if (punchPhase < 0.5f
159 && m_punchPhase >= 0.5f) {
160 IsAttackHitMoment = true;
162 }
163 }
164 else {
165 m_punchFactor = MathUtils.Max(m_punchFactor - 4f * dt, 0f);
166 if (m_punchPhase != 0f) {
167 if (m_punchPhase > 0.5f) {
169 }
170 else if (m_punchPhase > 0f) {
172 }
173 }
174 }
177 if ((m_rowLeft || m_rowRight)
178 && componentMount != null
179 && componentMount.ComponentBody.ImmersionFactor > 0f
180 && Math.Floor(1.1000000238418579 * m_subsystemTime.GameTime)
181 != Math.Floor(1.1000000238418579 * (m_subsystemTime.GameTime - m_subsystemTime.GameTimeDelta))) {
182 m_subsystemAudio.PlayRandomSound(
183 "Audio/Rowing",
184 m_random.Float(0.4f, 0.6f),
185 m_random.Float(-0.3f, 0.2f),
186 m_componentCreature.ComponentBody.Position,
187 3f,
188 true
189 );
190 }
191 float num6 = MathF.Floor(m_footstepsPhase);
192 if (m_footstepsPhase > num6
193 && footstepsPhase <= num6) {
194 if (m_componentCreature.ComponentBody.CrouchFactor < 1f) {
195 m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 8f);
196 }
197 if (!m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(1f)) {
198 m_footstepsPhase = 0f;
199 }
200 }
204 AttackOrder = false;
205 RowLeftOrder = false;
206 RowRightOrder = false;
210 base.Update(dt);
211 }
212
213 public override void AnimateCreature() {
214 Vector3 position = m_componentCreature.ComponentBody.Position;
215 Vector3 vector = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();
216 if (OnAnimate != null
217 && OnAnimate()) {
218 return;
219 }
220 if (m_lieDownFactorModel == 0f) {
221 ComponentMount componentMount = m_componentRider?.Mount;
222 float num = MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase);
223 position.Y += Bob;
224 vector.X += m_headingOffset;
225 float num2 = (float)MathUtils.Remainder(0.75 * m_subsystemGameInfo.TotalElapsedGameTime + (GetHashCode() & 0xFFFF), 10000.0);
226 float x = Math.Clamp(
227 MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.Noise(1.02f * num2 - 100f))
228 + m_componentCreature.ComponentLocomotion.LookAngles.X
229 + 1f * m_componentCreature.ComponentLocomotion.LastTurnOrder.X
231 0f - MathUtils.DegToRad(80f),
233 );
234 float y = Math.Clamp(
235 MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.Noise(0.96f * num2 - 200f)) + m_componentCreature.ComponentLocomotion.LookAngles.Y,
236 0f - MathUtils.DegToRad(45f),
238 );
239 float num3 = 0f;
240 float y2 = 0f;
241 float x2 = 0f;
242 float y3 = 0f;
243 float num4 = 0f;
244 float num5 = 0f;
245 float num6 = 0f;
246 float num7 = 0f;
247 if (componentMount != null) {
248 if (componentMount.Entity.ValuesDictionary.DatabaseObject.Name == "Boat") {
249 position.Y -= 0.2f;
250 vector.X += (float)Math.PI;
251 num4 = 0.4f;
252 num6 = 0.4f;
253 num5 = 0.2f;
254 num7 = -0.2f;
255 num3 = 1.1f;
256 x2 = 1.1f;
257 y2 = 0.2f;
258 y3 = -0.2f;
259 }
260 else {
261 num4 = 0.5f;
262 num6 = 0.5f;
263 num5 = 0.15f;
264 num7 = -0.15f;
265 y2 = 0.55f;
266 y3 = -0.55f;
267 }
268 }
269 else if (m_componentCreature.ComponentLocomotion.IsCreativeFlyEnabled) {
270 float num8 = m_componentCreature.ComponentLocomotion.LastWalkOrder.HasValue
271 ? MathUtils.Min(0.03f * m_componentCreature.ComponentBody.Velocity.XZ.LengthSquared(), 0.5f)
272 : 0f;
273 num3 = -0.1f - num8;
274 x2 = num3;
275 y2 = MathUtils.Lerp(0f, 0.25f, SimplexNoise.Noise(1.07f * num2 + 400f));
276 y3 = 0f - MathUtils.Lerp(0f, 0.25f, SimplexNoise.Noise(0.93f * num2 + 500f));
277 }
278 else if (MovementAnimationPhase != 0f) {
279 num4 = -0.5f * num;
280 num6 = 0.5f * num;
281 num3 = m_walkLegsAngle * num;
282 x2 = 0f - num3;
283 }
284 float num9 = 0f;
285 if (m_componentMiner != null) {
286 float num10 = MathF.Sin(MathF.Sqrt(m_componentMiner.PokingPhase) * (float)Math.PI);
287 num9 = m_componentMiner.ActiveBlockValue == 0 ? 1f * num10 : 0.3f + 1f * num10;
288 }
289 float num11 = m_punchPhase != 0f
290 ? (0f - MathUtils.DegToRad(90f)) * MathF.Sin((float)Math.PI * 2f * MathUtils.Sigmoid(m_punchPhase, 4f))
291 : 0f;
292 float num12 = (m_punchCounter & 1) == 0 ? num11 : 0f;
293 float num13 = (m_punchCounter & 1) != 0 ? num11 : 0f;
294 float num14 = 0f;
295 float num15 = 0f;
296 float num16 = 0f;
297 float num17 = 0f;
298 if (m_rowLeft || m_rowRight) {
299 float num18 = 0.6f * (float)Math.Sin(6.91150426864624 * m_subsystemTime.GameTime);
300 float num19 = 0.2f + 0.2f * (float)Math.Cos(6.91150426864624 * (m_subsystemTime.GameTime + 0.5));
301 if (m_rowLeft) {
302 num14 = num18;
303 num15 = num19;
304 }
305 if (m_rowRight) {
306 num16 = num18;
307 num17 = 0f - num19;
308 }
309 }
310 float num20 = 0f;
311 float num21 = 0f;
312 float num22 = 0f;
313 float num23 = 0f;
314 if (m_aimHandAngle != 0f) {
315 num20 = 1.5f;
316 num21 = -0.7f;
317 num22 = m_aimHandAngle * 1f;
318 num23 = 0f;
319 }
320 float num24 = !m_componentCreature.ComponentLocomotion.IsCreativeFlyEnabled ? 1 : 4;
321 num4 += MathUtils.Lerp(-0.1f, 0.1f, SimplexNoise.Noise(num2)) + num12 + num14 + num20;
322 num5 += MathUtils.Lerp(0f, num24 * 0.15f, SimplexNoise.Noise(1.1f * num2 + 100f)) + num15 + num21;
323 num6 += num9 + MathUtils.Lerp(-0.1f, 0.1f, SimplexNoise.Noise(0.9f * num2 + 200f)) + num13 + num16 + num22;
324 num7 += 0f - MathUtils.Lerp(0f, num24 * 0.15f, SimplexNoise.Noise(1.05f * num2 + 300f)) + num17 + num23;
325 float s = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
326 m_headAngles += s * (new Vector2(x, y) - m_headAngles);
327 m_handAngles1 += s * (new Vector2(num4, num5) - m_handAngles1);
328 m_handAngles2 += s * (new Vector2(num6, num7) - m_handAngles2);
329 m_legAngles1 += s * (new Vector2(num3, y2) - m_legAngles1);
330 m_legAngles2 += s * (new Vector2(x2, y3) - m_legAngles2);
331 if (m_componentCreature.ComponentBody.CrouchFactor == 1) {
332 m_legAngles1 *= 0.5f;
333 m_legAngles2 *= 0.5f;
334 }
335 float f = MathUtils.Sigmoid(m_componentCreature.ComponentBody.CrouchFactor, 4f);
336 //Vector3 position2 = new(0f, MathUtils.Lerp(0f, 4f, f), MathUtils.Lerp(0f, -3.3f, f));
337 Vector3 position3 = new(position.X, position.Y - MathUtils.Lerp(0f, 0.7f, f), position.Z);
338 Vector3 position4 = new(0f, MathUtils.Lerp(0f, 7f, f), MathUtils.Lerp(0f, 28f, f));
339 Vector3 scale = new(1f, 1f, MathUtils.Lerp(1f, 0.5f, f));
345 m_leg1Bone.Index,
348 * Matrix.CreateTranslation(position4)
349 * Matrix.CreateScale(scale)
350 );
352 m_leg2Bone.Index,
355 * Matrix.CreateTranslation(position4)
356 * Matrix.CreateScale(scale)
357 );
358 }
359 else {
361 float num26 = 1f - num25;
362 Vector3 position2 = position
363 + num25
364 * 0.5f
365 * m_componentCreature.ComponentBody.BoxSize.Y
366 * Vector3.Normalize(m_componentCreature.ComponentBody.Matrix.Forward * new Vector3(1f, 0f, 1f))
367 + num25 * Vector3.UnitY * m_componentCreature.ComponentBody.BoxSize.Z * 0.1f;
369 m_bodyBone.Index,
370 Matrix.CreateFromYawPitchRoll(vector.X, (float)Math.PI / 2f * num25, 0f) * Matrix.CreateTranslation(position2)
371 );
374 m_hand1Bone.Index,
376 );
378 m_hand2Bone.Index,
380 );
383 }
384 }
385
386 public override void DrawExtras(Camera camera) {
387 base.DrawExtras(camera);
388 if (IsExtrasDrawn) {
389 return;
390 }
391 if (m_componentCreature.ComponentHealth.Health > 0f
392 && m_componentMiner != null
393 && m_componentMiner.ActiveBlockValue != 0) {
394 int num = Terrain.ExtractContents(m_componentMiner.ActiveBlockValue);
395 Block block = BlocksManager.Blocks[num];
397 m *= camera.InvertedViewMatrix;
398 m.Right = Vector3.Normalize(m.Right);
399 m.Up = Vector3.Normalize(m.Up);
400 m.Forward = Vector3.Normalize(m.Forward);
401 Vector3 InhandRotation = block.GetInHandRotation(m_componentMiner.ActiveBlockValue);
406 * Matrix.CreateTranslation(new Vector3(0.05f, 0.05f, -0.56f) * (m_componentCreature.ComponentBody.BoxSize.Y / 1.77f))
407 * m;
408 int x = Terrain.ToCell(matrix.Translation.X);
409 int y = Terrain.ToCell(matrix.Translation.Y);
410 int z = Terrain.ToCell(matrix.Translation.Z);
411 m_drawBlockEnvironmentData.DrawBlockMode = DrawBlockMode.ThirdPerson;
412 m_drawBlockEnvironmentData.InWorldMatrix = matrix;
413 m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
414 m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z)
416 m_drawBlockEnvironmentData.Light = m_subsystemTerrain.Terrain.GetCellLight(x, y, z);
417 m_drawBlockEnvironmentData.BillboardDirection = -Vector3.UnitZ;
418 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
419 m_drawBlockEnvironmentData.Owner = m_entity;
420 Matrix matrix2 = matrix * camera.ViewMatrix;
421 block.DrawBlock(
422 m_subsystemModelsRenderer.PrimitivesRenderer,
423 m_componentMiner.ActiveBlockValue,
424 Color.White,
425 block.GetInHandScale(m_componentMiner.ActiveBlockValue),
426 ref matrix2,
428 );
429 }
430 }
431
432 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
433 base.Load(valuesDictionary, idToEntityMap);
434 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
436 m_subsystemNoise = Project.FindSubsystem<SubsystemNoise>(true);
437 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
438 m_componentMiner = Entity.FindComponent<ComponentMiner>();
439 m_componentRider = Entity.FindComponent<ComponentRider>();
440 m_componentSleep = Entity.FindComponent<ComponentSleep>();
441 m_componentPlayer = Entity.FindComponent<ComponentPlayer>();
442 m_walkAnimationSpeed = valuesDictionary.GetValue<float>("WalkAnimationSpeed");
443 m_walkBobHeight = valuesDictionary.GetValue<float>("WalkBobHeight");
444 m_walkLegsAngle = valuesDictionary.GetValue<float>("WalkLegsAngle");
445 }
446
447 public override void SetModel(Model model) {
448 base.SetModel(model);
449 if (IsSet) {
450 return;
451 }
452 if (Model != null) {
453 m_bodyBone = Model.FindBone("Body");
454 m_headBone = Model.FindBone("Head");
455 m_leg1Bone = Model.FindBone("Leg1");
456 m_leg2Bone = Model.FindBone("Leg2");
457 m_hand1Bone = Model.FindBone("Hand1");
458 m_hand2Bone = Model.FindBone("Hand2");
459 }
460 else {
461 m_bodyBone = null;
462 m_headBone = null;
463 m_leg1Bone = null;
464 m_leg2Bone = null;
465 m_hand1Bone = null;
466 m_hand2Bone = null;
467 }
468 }
469
470 public override Vector3 CalculateEyePosition() {
471 float f = MathUtils.Sigmoid(m_lieDownFactorEye, 1f);
472 float num = MathUtils.Sigmoid(m_componentCreature.ComponentBody.CrouchFactor, 4f);
473 float num2 = 0.875f * m_componentCreature.ComponentBody.BoxSize.Y;
474 float num3 = MathUtils.Lerp(MathUtils.Lerp(num2, 0.45f * num2, num), 0.2f * num2, f);
475 Matrix matrix = m_componentCreature.ComponentBody.Matrix;
476 Vector3 result = m_componentCreature.ComponentBody.Position + matrix.Up * (num3 + 2f * Bob) + matrix.Forward * -0.2f * num;
478 "RecalculateModelEyePosition",
479 loader => {
480 loader.RecalculateModelEyePosition(this, ref result);
481 return false;
482 }
483 );
484 return result;
485 }
486
488 float num = 0f;
489 if (m_lieDownFactorEye != 0f) {
490 num += MathUtils.DegToRad(80f) * MathUtils.Sigmoid(MathUtils.Max(m_lieDownFactorEye - 0.2f, 0f) / 0.8f, 4f);
491 }
492 Quaternion result = m_componentCreature.ComponentBody.Rotation
494 0f - m_componentCreature.ComponentLocomotion.LookAngles.X,
495 m_componentCreature.ComponentLocomotion.LookAngles.Y,
496 num
497 );
499 "RecalculateModelEyeRotation",
500 loader => {
501 loader.RecalculateModelEyeRotation(this, ref result);
502 return false;
503 }
504 );
505 return result;
506 }
507 }
508}
Engine.Vector3 Vector3
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static float Sigmoid(float x, float steepness)
static float NormalizeAngle(float angle)
static float Saturate(float x)
static int Max(int x1, int x2)
static int Sqr(int x)
static float DegToRad(float degrees)
static float Lerp(float x1, float x2, float f)
virtual Vector3 GetInHandOffset(int value)
void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
绘制方块_用于绘制方块物品形态
virtual Vector3 GetInHandRotation(int value)
virtual float GetInHandScale(int value)
Matrix ViewMatrix
Matrix InvertedViewMatrix
virtual float ImmersionFactor
DrawBlockEnvironmentData m_drawBlockEnvironmentData
override Quaternion CalculateEyeRotation()
override void SetModel(Model model)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
SubsystemModelsRenderer m_subsystemModelsRenderer
override void DrawExtras(Camera camera)
virtual void SetBoneTransform(int boneIndex, Matrix? transformation)
virtual Func< bool > OnAnimate
static float Noise(float x)
static Func< int, int > GetTemperatureAdjustmentAtHeight
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Color White
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 Matrix CreateRotationY(float radians)
Vector3 Translation
Vector3 Forward
static Matrix CreateScale(float scale)
static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static readonly Vector2 Zero
static readonly Vector2 UnitY
static float Angle(Vector2 v1, Vector2 v2)
static Vector3 Lerp(Vector3 v1, Vector3 v2, float f)
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero
static readonly Vector3 UnitZ