Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentBirdModel.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
8 public bool m_hasWings;
9
11
13
15
17
19
21
23
24 public float m_flyAnimationSpeed;
25
27
29
30 public float m_walkBobHeight;
31
32 public float m_peckPhase;
33
34 public float m_kickPhase;
35 public float FlyPhase { get; set; }
36
37 public override float AttackPhase {
38 get => m_kickPhase;
39 set => m_kickPhase = value;
40 }
41
42 public override float AttackFactor {
44 set => m_peckAnimationSpeed = value;
45 }
46
47 public override void Update(float dt) {
48 float num = Vector3.Dot(m_componentCreature.ComponentBody.Velocity, m_componentCreature.ComponentBody.Matrix.Forward);
49 if (MathF.Abs(num) > 0.1f) {
51 }
52 else {
53 float num2 = MathF.Floor(MovementAnimationPhase);
54 if (MovementAnimationPhase != num2) {
56 ? MathUtils.Min(MovementAnimationPhase + 2f * dt, num2 + 1f)
57 : MathUtils.Max(MovementAnimationPhase - 2f * dt, num2);
58 }
59 }
60 float num3 = (0f - m_walkBobHeight) * MathUtils.Sqr(MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase));
61 float num4 = MathUtils.Min(12f * m_subsystemTime.GameTimeDelta, 1f);
62 Bob += num4 * (num3 - Bob);
63 if (m_hasWings) {
64 if (m_componentCreature.ComponentLocomotion.LastFlyOrder.HasValue) {
65 float num5 = m_componentCreature.ComponentLocomotion.LastFlyOrder.Value.LengthSquared() > 0.99f ? 1.5f : 1f;
67 if (m_componentCreature.ComponentLocomotion.LastFlyOrder.Value.Y < -0.1f
68 && m_componentCreature.ComponentBody.Velocity.Length() > 4f) {
69 FlyPhase = 0.72f;
70 }
71 }
72 else if (FlyPhase != 1f) {
74 }
75 }
76 if (FeedOrder) {
78 if (m_peckPhase > 0.75f) {
79 m_peckPhase -= 0.5f;
80 }
81 }
82 else if (m_peckPhase != 0f) {
84 }
85 FeedOrder = false;
86 IsAttackHitMoment = false;
87 if (AttackOrder) {
89 float kickPhase = m_kickPhase;
91 if (kickPhase < 0.5f
92 && m_kickPhase >= 0.5f) {
93 IsAttackHitMoment = true;
94 }
95 }
96 else {
98 if (m_kickPhase != 0f) {
99 if (m_kickPhase > 0.5f) {
101 }
102 else if (m_kickPhase > 0f) {
103 m_kickPhase = MathUtils.Max(m_kickPhase - dt * 2f, 0f);
104 }
105 }
106 }
107 AttackOrder = false;
108 base.Update(dt);
109 }
110
111 public override void AnimateCreature() {
112 float num = 0f;
113 if (m_hasWings) {
114 num += 1.2f * MathF.Sin((float)Math.PI * 2f * (FlyPhase + 0.75f));
115 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue) {
116 num += 0.3f * MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase);
117 }
118 }
119 float num2;
120 float num3;
121 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue
122 || m_componentCreature.ComponentBody.ImmersionFactor > 0f
123 || m_componentCreature.ComponentLocomotion.FlySpeed == 0f) {
124 num2 = 0.6f * MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase);
125 num3 = 0f - num2;
126 }
127 else {
128 num2 = num3 = 0f - MathUtils.DegToRad(60f);
129 }
130 Vector3 vector = m_componentCreature.ComponentBody.Rotation.ToYawPitchRoll();
131 if (m_componentCreature.ComponentHealth.Health > 0f) {
132 float yaw = m_componentCreature.ComponentLocomotion.LookAngles.X / 2f;
133 float yaw2 = m_componentCreature.ComponentLocomotion.LookAngles.X / 2f;
134 float num4 = 0f;
135 float num5 = 0f;
136 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue
137 || m_componentCreature.ComponentBody.ImmersionFactor > 0f) {
138 num4 = 0.5f * MathF.Sin((float)Math.PI * 2f * MovementAnimationPhase / 2f);
139 num5 = 0f - num4;
140 }
141 float num6 = MathF.Cos((float)Math.PI * 2f * m_kickPhase != 0 ? m_kickPhase : m_peckPhase);
142 num4 -= 1.25f * (1f - (num6 >= 0f ? num6 : -0.5f * num6));
143 num4 += m_componentCreature.ComponentLocomotion.LookAngles.Y;
145 m_bodyBone.Index,
146 Matrix.CreateFromYawPitchRoll(vector.X, 0f, 0f)
147 * Matrix.CreateTranslation(m_componentCreature.ComponentBody.Position + new Vector3(0f, Bob, 0f))
148 );
151 m_headBone.Index,
152 Matrix.CreateFromYawPitchRoll(yaw, num5 + Math.Clamp(vector.Y, -(float)Math.PI / 4f, (float)Math.PI / 4f), vector.Z)
153 );
154 if (m_hasWings) {
157 }
160 }
161 else {
162 float num7 = 1f - DeathPhase;
163 float num8 = m_componentCreature.ComponentBody.BoundingBox.Max.Y - m_componentCreature.ComponentBody.BoundingBox.Min.Y;
164 Vector3 position = m_componentCreature.ComponentBody.Position
165 + 0.5f * num8 * Vector3.Normalize(m_componentCreature.ComponentBody.Matrix.Forward * new Vector3(1f, 0f, 1f));
167 m_bodyBone.Index,
168 Matrix.CreateFromYawPitchRoll(vector.X, (float)Math.PI / 2f * DeathPhase, 0f) * Matrix.CreateTranslation(position)
169 );
172 if (m_hasWings) {
174 SetBoneTransform(m_wing2Bone.Index, Matrix.CreateRotationY((0f - num) * num7));
175 }
178 }
179 }
180
181 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
182 base.Load(valuesDictionary, idToEntityMap);
183 m_flyAnimationSpeed = valuesDictionary.GetValue<float>("FlyAnimationSpeed");
184 m_walkAnimationSpeed = valuesDictionary.GetValue<float>("WalkAnimationSpeed");
185 m_peckAnimationSpeed = valuesDictionary.GetValue<float>("PeckAnimationSpeed");
186 m_walkBobHeight = valuesDictionary.GetValue<float>("WalkBobHeight");
187 }
188
189 public override void SetModel(Model model) {
190 base.SetModel(model);
191 if (IsSet) {
192 return;
193 }
194 if (Model != null) {
195 m_bodyBone = Model.FindBone("Body");
196 m_neckBone = Model.FindBone("Neck");
197 m_headBone = Model.FindBone("Head");
198 m_leg1Bone = Model.FindBone("Leg1");
199 m_leg2Bone = Model.FindBone("Leg2");
200 m_wing1Bone = Model.FindBone("Wing1", false);
201 m_wing2Bone = Model.FindBone("Wing2", false);
202 }
203 else {
204 m_bodyBone = null;
205 m_neckBone = null;
206 m_headBone = null;
207 m_leg1Bone = null;
208 m_leg2Bone = null;
209 m_wing1Bone = null;
210 m_wing2Bone = null;
211 }
212 m_hasWings = m_wing1Bone != null && m_wing2Bone != null;
213 }
214 }
215}
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static int Max(int x1, int x2)
static int Sqr(int x)
static float DegToRad(float degrees)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
override void SetModel(Model model)
override void Update(float dt)
virtual void SetBoneTransform(int boneIndex, Matrix? transformation)
ValuesDictionary ValuesDictionary
static Matrix CreateRotationX(float radians)
static Matrix CreateTranslation(float x, float y, float z)
static readonly Matrix Identity
static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static Matrix CreateRotationY(float radians)
static Vector3 Normalize(Vector3 v)
static float Dot(Vector3 v1, Vector3 v2)