Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFlightlessBirdModel.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
17
19
20 public float m_walkLegsAngle;
21
22 public float m_walkBobHeight;
23
24 public float m_feedFactor;
25
26 public float m_footstepsPhase;
27
28 public float m_kickFactor;
29
30 public float m_kickPhase;
31
32 public float m_legAngle1;
33
34 public float m_legAngle2;
35
36 public float m_headAngleY;
37
38 public override float AttackPhase {
39 get => m_kickPhase;
40 set => m_kickPhase = value;
41 }
42
43 public override float AttackFactor {
44 get => m_kickFactor;
45 set => m_kickFactor = value;
46 }
47
48 public override void Update(float dt) {
49 float footstepsPhase = m_footstepsPhase;
50 float num = m_componentCreature.ComponentLocomotion.SlipSpeed
51 ?? Vector3.Dot(m_componentCreature.ComponentBody.Velocity, m_componentCreature.ComponentBody.Matrix.Forward);
52 if (MathF.Abs(num) > 0.2f) {
54 m_footstepsPhase += 1.25f * m_walkAnimationSpeed * num * dt;
55 }
56 else {
59 }
60 float num2 = (0f - m_walkBobHeight) * MathUtils.Sqr(MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase));
61 float num3 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
62 Bob += num3 * (num2 - Bob);
63 float num4 = MathF.Floor(m_footstepsPhase);
64 if (m_footstepsPhase > num4
65 && footstepsPhase <= num4) {
66 m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(1f);
67 }
68 m_feedFactor = FeedOrder ? MathUtils.Min(m_feedFactor + 2f * dt, 1f) : MathUtils.Max(m_feedFactor - 2f * dt, 0f);
69 IsAttackHitMoment = false;
70 if (AttackOrder) {
71 m_kickFactor = MathUtils.Min(m_kickFactor + 6f * dt, 1f);
72 float kickPhase = m_kickPhase;
74 if (kickPhase < 0.5f
75 && m_kickPhase >= 0.5f) {
76 IsAttackHitMoment = true;
77 }
78 }
79 else {
80 m_kickFactor = MathUtils.Max(m_kickFactor - 6f * dt, 0f);
81 if (m_kickPhase != 0f) {
82 if (m_kickPhase > 0.5f) {
84 }
85 else if (m_kickPhase > 0f) {
86 m_kickPhase = MathUtils.Max(m_kickPhase - dt * 2f, 0f);
87 }
88 }
89 }
90 FeedOrder = false;
91 AttackOrder = false;
92 base.Update(dt);
93 }
94
95 public override void AnimateCreature() {
96 Vector3 position = m_componentCreature.ComponentBody.Position;
97 Vector3 vector = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();
98 if (m_componentCreature.ComponentHealth.Health > 0f) {
99 float num = 0f;
100 float num2 = 0f;
101 float num3 = 0f;
102 if (MovementAnimationPhase != 0f
103 && (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.ImmersionFactor > 0f)) {
104 float num4 = Vector3.Dot(m_componentCreature.ComponentBody.Velocity, m_componentCreature.ComponentBody.Matrix.Forward)
105 > 0.75f * m_componentCreature.ComponentLocomotion.WalkSpeed
106 ? 1.5f * m_walkLegsAngle
108 float num5 = MathF.Sin((float)Math.PI * 2f * (MovementAnimationPhase + 0f));
109 float num6 = MathF.Sin((float)Math.PI * 2f * (MovementAnimationPhase + 0.5f));
110 num = num4 * num5 + m_kickPhase;
111 num2 = num4 * num6;
112 num3 = MathUtils.DegToRad(5f) * MathF.Sin((float)Math.PI * 4f * MovementAnimationPhase);
113 }
114 if (m_kickFactor != 0f) {
115 float x = MathUtils.DegToRad(60f) * MathF.Sin((float)Math.PI * MathUtils.Sigmoid(m_kickPhase, 5f));
116 num = MathUtils.Lerp(num, x, m_kickFactor);
117 }
118 float num7 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
119 m_legAngle1 += num7 * (num - m_legAngle1);
120 m_legAngle2 += num7 * (num2 - m_legAngle2);
121 m_headAngleY += num7 * (num3 - m_headAngleY);
122 Vector2 vector2 = m_componentCreature.ComponentLocomotion.LookAngles;
123 vector2.Y += m_headAngleY;
124 if (m_feedFactor > 0f) {
125 float y = 0f - MathUtils.DegToRad(35f + 55f * SimplexNoise.OctavedNoise((float)m_subsystemTime.GameTime, 3f, 2, 2f, 0.75f));
126 vector2 = Vector2.Lerp(v2: new Vector2(0f, y), v1: vector2, f: m_feedFactor);
127 }
128 vector2.X = Math.Clamp(vector2.X, 0f - MathUtils.DegToRad(90f), MathUtils.DegToRad(90f));
129 vector2.Y = Math.Clamp(vector2.Y, 0f - MathUtils.DegToRad(90f), MathUtils.DegToRad(50f));
130 Vector2 vector3 = Vector2.Zero;
131 if (m_neckBone != null) {
132 vector3 = 0.4f * vector2;
133 vector2 = 0.6f * vector2;
134 }
136 m_bodyBone.Index,
137 Matrix.CreateRotationY(vector.X) * Matrix.CreateTranslation(position.X, position.Y + Bob, position.Z)
138 );
139 SetBoneTransform(m_headBone.Index, Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationZ(0f - vector2.X));
140 if (m_neckBone != null) {
142 }
145 }
146 else {
147 float num8 = 1f - DeathPhase;
148 float num9 = Vector3.Dot(m_componentFrame.Matrix.Right, DeathCauseOffset) > 0f ? 1 : -1;
149 float num10 = m_componentCreature.ComponentBody.BoundingBox.Max.Y - m_componentCreature.ComponentBody.BoundingBox.Min.Y;
151 m_bodyBone.Index,
153 * Matrix.CreateFromYawPitchRoll(vector.X, 0f, (float)Math.PI / 2f * DeathPhase * num9)
155 * Matrix.CreateTranslation(position)
156 );
158 if (m_neckBone != null) {
160 }
163 }
164 }
165
166 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
167 base.Load(valuesDictionary, idToEntityMap);
168 m_walkAnimationSpeed = valuesDictionary.GetValue<float>("WalkAnimationSpeed");
169 m_walkLegsAngle = valuesDictionary.GetValue<float>("WalkLegsAngle");
170 m_walkBobHeight = valuesDictionary.GetValue<float>("WalkBobHeight");
171 }
172
173 public override void SetModel(Model model) {
174 base.SetModel(model);
175 if (IsSet) {
176 return;
177 }
178 if (Model != null) {
179 m_bodyBone = Model.FindBone("Body");
180 m_neckBone = Model.FindBone("Neck", false);
181 m_headBone = Model.FindBone("Head");
182 m_leg1Bone = Model.FindBone("Leg1");
183 m_leg2Bone = Model.FindBone("Leg2");
184 }
185 else {
186 m_bodyBone = null;
187 m_neckBone = null;
188 m_headBone = null;
189 m_leg1Bone = null;
190 m_leg2Bone = null;
191 }
192 }
193 }
194}
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static float Sigmoid(float x, float steepness)
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)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual void SetBoneTransform(int boneIndex, Matrix? transformation)
ComponentFrame m_componentFrame
static float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
ValuesDictionary ValuesDictionary
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)
static readonly Vector2 Zero
static Vector2 Lerp(Vector2 v1, Vector2 v2, float f)
static readonly Vector3 UnitY
static float Dot(Vector3 v1, Vector3 v2)