1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use std::f32::consts::PI;
7
8pub struct ShootAnimation;
9
10type ShootAnimationDependency<'a> = (
11 Option<ToolKind>,
12 Vec3<f32>,
13 Vec3<f32>,
14 Vec3<f32>,
15 f32,
16 Vec3<f32>,
17 f32,
18 Option<StageSection>,
19 f32,
20 Option<&'a str>,
21);
22
23impl Animation for ShootAnimation {
24 type Dependency<'a> = ShootAnimationDependency<'a>;
25 type Skeleton = BipedSmallSkeleton;
26
27 #[cfg(feature = "use-dyn-lib")]
28 const UPDATE_FN: &'static [u8] = b"biped_small_shoot\0";
29
30 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_shoot"))]
31 fn update_skeleton_inner(
32 skeleton: &Self::Skeleton,
33 (
34 active_tool_kind,
35 velocity,
36 _orientation,
37 _last_ori,
38 _global_time,
39 _avg_vel,
40 _acc_vel,
41 stage_section,
42 _timer,
43 ability_id,
44 ): Self::Dependency<'_>,
45 anim_time: f32,
46 _rate: &mut f32,
47 s_a: &SkeletonAttr,
48 ) -> Self::Skeleton {
49 let mut next = (*skeleton).clone();
50 let speed = Vec2::<f32>::from(velocity).magnitude();
51
52 let fast = (anim_time * 10.0).sin();
53 let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
54
55 let speednorm = speed / 9.4;
56 let speednormcancel = 1.0 - speednorm;
57
58 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + fast * -0.1 * speednormcancel);
59 next.head.orientation = Quaternion::rotation_x(0.45 * speednorm)
60 * Quaternion::rotation_y(fast * 0.07 * speednormcancel);
61 next.chest.position = Vec3::new(
62 0.0,
63 s_a.chest.0,
64 s_a.chest.1 + fastalt * 0.4 * speednormcancel + speednormcancel * -0.5,
65 );
66
67 next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
68
69 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
70 next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
71 * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
72
73 match ability_id {
74 Some("common.abilities.adlet.hunter.throw") => {
75 next.main.position = Vec3::new(8.0, -7.0, 2.0);
76 next.main.orientation = Quaternion::rotation_x(PI / -2.0);
77
78 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
79 next.hand_r.position = Vec3::new(5.0, -2.0, s_a.grip.2);
80
81 next.hand_l.orientation = Quaternion::rotation_x(0.0);
82 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
83 },
84 Some("common.abilities.adlet.tracker.trap") => {
85 next.main.position = Vec3::new(10.0, 0.0, 9.0);
86
87 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
88 next.hand_r.position = Vec3::new(5.0, -2.0, s_a.grip.2);
89
90 next.hand_l.orientation = Quaternion::rotation_x(0.0);
91 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
92 },
93 _ => {
94 next.main.position = Vec3::new(0.0, 0.0, 0.0);
95 next.main.orientation = Quaternion::rotation_x(0.0);
96
97 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
98 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
99
100 next.hand_l.orientation = Quaternion::rotation_x(0.0);
101 next.hand_r.orientation = Quaternion::rotation_x(0.0);
102 },
103 };
104
105 match active_tool_kind {
106 Some(ToolKind::Bow) => match ability_id {
107 Some("common.abilities.adlet.tracker.trap") => {
108 let (move1base, move2base, move3) = match stage_section {
109 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
110 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
111 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
112 _ => (0.0, 0.0, 0.0),
113 };
114 let pullback = 1.0 - move3;
115 let move1abs = move1base * pullback;
116 let move2abs = move2base * pullback;
117 next.main.position = Vec3::new(2.0, -3.0, -3.0);
118
119 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 - 2.0);
120 next.hand_r.position = Vec3::new(
121 s_a.hand.0,
122 s_a.hand.1 + move2abs * 1.5,
123 s_a.hand.2 - 2.5 + move1abs * 2.5,
124 );
125
126 next.hand_r.orientation =
127 Quaternion::rotation_x(move1abs * 4.0 + move2abs * -0.7)
128 * Quaternion::rotation_y(0.0 + move1abs * -0.7);
129
130 next.hand_l.orientation = Quaternion::rotation_x(PI / 3.0 * move1abs)
131 * Quaternion::rotation_y(-0.7 * move1abs + move2abs * 0.1);
132 },
133 _ => {
134 let (move1base, move2base, move3) = match stage_section {
135 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
136 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
137 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
138 _ => (0.0, 0.0, 0.0),
139 };
140 let pullback = 1.0 - move3;
141 let move1abs = move1base * pullback;
142 let move2abs = move2base * pullback;
143 next.control_l.position = Vec3::new(
144 -1.0 - s_a.grip.0 * 2.0 + move2abs * -4.0,
145 move2abs * -8.0,
146 0.0,
147 );
148 next.control_r.position = Vec3::new(1.0 + s_a.grip.0 * 2.0, 3.0, -2.0);
149
150 next.control.position = Vec3::new(
151 -1.0,
152 2.0 + move1abs * 3.0 + s_a.grip.2,
153 3.0 + move1abs * 7.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
154 );
155
156 next.control_l.orientation =
157 Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
158 next.control_r.orientation =
159 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
160 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
161
162 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.4)
163 * Quaternion::rotation_y(0.5 * speednorm);
164 },
165 },
166 Some(ToolKind::Natural) => match ability_id {
167 Some("common.abilities.custom.irrwurz.magicball") => {
168 let (move1base, move2base, move3) = match stage_section {
169 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
170 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
171 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
172 _ => (0.0, 0.0, 0.0),
173 };
174 let pullback = 1.0 - move3;
175 let move1abs = move1base * pullback;
176 let move2abs = move2base * pullback;
177 next.main.position = Vec3::new(2.0, -3.0, -3.0);
178
179 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 - 2.0);
180 next.hand_r.position = Vec3::new(
181 s_a.hand.0,
182 s_a.hand.1 + move2abs * 1.5,
183 s_a.hand.2 - 2.5 + move1abs * 2.5,
184 );
185
186 next.hand_r.orientation =
187 Quaternion::rotation_x(move1abs * 4.0 + move2abs * -0.7);
188
189 next.hand_l.orientation = Quaternion::rotation_x(PI / 3.0 * move1abs)
190 * Quaternion::rotation_y(-0.7 * move1abs + move2abs * 0.1);
191 },
192 Some("common.abilities.custom.goblin_chucker.throw") => {
193 let (move1base, move2base, move3) = match stage_section {
194 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
195 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
196 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
197 _ => (0.0, 0.0, 0.0),
198 };
199 let pullback = 1.0 - move3;
200 let move1abs = move1base * pullback;
201 let move2abs = move2base * pullback;
202
203 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 - 2.0);
204 next.hand_r.position = Vec3::new(
205 s_a.hand.0,
206 s_a.hand.1 + move2abs * 1.5,
207 s_a.hand.2 - 2.5 + move1abs * 2.5,
208 );
209
210 next.hand_r.orientation =
211 Quaternion::rotation_x(move1abs * 4.0 + move2abs * -0.7)
212 * Quaternion::rotation_y(0.0 + move1abs * -0.7);
213
214 next.hand_l.orientation = Quaternion::rotation_x(PI / 3.0 * move1abs)
215 * Quaternion::rotation_y(-0.7 * move1abs + move2abs * 0.1);
216 },
217 _ => {
218 let (move1base, move2base, move3) = match stage_section {
219 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
220 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
221 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
222 _ => (0.0, 0.0, 0.0),
223 };
224 let pullback = 1.0 - move3;
225 let move1abs = move1base * pullback;
226 let move2abs = move2base * pullback;
227 next.control_l.position = Vec3::new(
228 1.0 - s_a.grip.0 * 2.0 + move2abs * -4.0,
229 move2abs * -8.0,
230 0.0,
231 );
232 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 6.0, -2.0);
233
234 next.control.position = Vec3::new(
235 -1.0,
236 2.0 + move1abs * 3.0 + s_a.grip.2,
237 3.0 + move1abs * 7.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
238 );
239
240 next.control_l.orientation =
241 Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
242 next.control_r.orientation =
243 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
244 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
245
246 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.4)
247 * Quaternion::rotation_y(0.5 * speednorm);
248 },
249 },
250 Some(ToolKind::Blowgun) => {
251 let (move1base, move2base, move3) = match stage_section {
252 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
253 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
254 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
255 _ => (0.0, 0.0, 0.0),
256 };
257 let pullback = 1.0 - move3;
258 let move1abs = move1base * pullback;
259 let move2abs = move2base * pullback;
260 next.head.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -0.7);
261 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 0.0, 3.0);
262 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 0.0, 4.0);
263
264 next.control.position = Vec3::new(
265 0.0,
266 move1abs * -2.0 + move2abs * 1.0 + s_a.grip.2,
267 move1abs * 3.5 + move2abs * -2.0 + 4.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
268 );
269
270 next.control_l.orientation =
271 Quaternion::rotation_x(3.8 + move1abs * 0.4 + move2abs * -0.5)
272 * Quaternion::rotation_y(-0.3);
273 next.control_r.orientation = Quaternion::rotation_x(
274 3.5 + move1abs * 0.4 + move2abs * -0.5 + s_a.grip.0 * 0.2,
275 ) * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
276
277 next.control.orientation = Quaternion::rotation_x(
278 -2.2 + move1abs * 0.7 + move2abs * -0.2 + 0.5 * speednorm,
279 );
280 },
281 Some(ToolKind::Staff) => match ability_id {
282 Some(
283 "common.abilities.custom.dwarves.flamekeeper.mines"
284 | "common.abilities.custom.dwarves.flamekeeper.lava_mortar",
285 ) => {
286 let (move1base, _move2base, move3) = match stage_section {
287 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
288 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
289 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
290 _ => (0.0, 0.0, 0.0),
291 };
292 let pullback = 1.0 - move3;
293 let move1abs = move1base * pullback;
294 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
295 next.control_r.position = Vec3::new(
296 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
297 -4.0 + move1abs * 4.0,
298 3.0,
299 );
300
301 next.control.position = Vec3::new(
302 -5.0,
303 -1.0 + s_a.grip.2,
304 -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
305 );
306
307 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
308 * Quaternion::rotation_y(-0.3)
309 * Quaternion::rotation_z(-0.3);
310 next.control_r.orientation =
311 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
312 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
313 * Quaternion::rotation_z(-0.0);
314
315 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.3)
316 * Quaternion::rotation_y(-0.2 * speednorm + move1abs * 0.3)
317 * Quaternion::rotation_z(0.5 + move1abs * 0.6);
318 },
319 _ => {
320 let (move1base, _move2base, move3) = match stage_section {
321 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
322 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
323 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
324 _ => (0.0, 0.0, 0.0),
325 };
326 let pullback = 1.0 - move3;
327 let move1abs = move1base * pullback;
328 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
329 next.control_r.position = Vec3::new(
330 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
331 -4.0 + move1abs * 4.0,
332 3.0,
333 );
334
335 next.control.position = Vec3::new(
336 -5.0,
337 -1.0 + s_a.grip.2,
338 -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
339 );
340
341 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
342 * Quaternion::rotation_y(-0.3)
343 * Quaternion::rotation_z(-0.3);
344 next.control_r.orientation =
345 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
346 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
347 * Quaternion::rotation_z(-0.0);
348
349 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.6)
350 * Quaternion::rotation_y(-0.2 * speednorm)
351 * Quaternion::rotation_z(0.5 + move1abs * 0.6);
352 },
353 },
354 Some(ToolKind::Spear) => {
355 let (move1base, move2base, move3) = match stage_section {
356 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
357 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
358 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
359 _ => (0.0, 0.0, 0.0),
360 };
361 let pullback = 1.0 - move3;
362 let move1abs = move1base * pullback;
363 let move2abs = move2base * pullback;
364 next.control_l.position = Vec3::new(
365 0.0,
366 0.0 + move1abs * 4.0 + move2abs * -4.0,
367 -2.0 + move1abs * -8.0,
368 );
369 next.control_r.position = Vec3::new(
370 -1.0 + s_a.grip.0 * 2.0,
371 2.0 + move3 * -4.0,
372 -2.0 + move3 * -4.0,
373 );
374
375 next.control.position = Vec3::new(
376 -1.0,
377 0.0 + move1abs * -8.0 + move2abs * 8.0 + s_a.grip.2,
378 3.0 + move1abs * 7.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
379 );
380
381 next.control_l.orientation =
382 Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
383 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
384 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2 + move3 * -1.5);
385
386 next.control.orientation =
387 Quaternion::rotation_x(-0.3 + move1abs * 0.5 + move2abs * -0.5 + move3 * 0.5)
388 * Quaternion::rotation_y(0.5 * speednorm);
389
390 if matches!(stage_section, Some(StageSection::Recover)) {
391 if move3 < 0.05 {
392 next.main.position += Vec3::new(0.0, 100000.0, -10000000.0);
393 }
394 if move3 < 0.3 {
395 next.main.scale = Vec3::zero();
396 }
397 }
398 },
399 Some(ToolKind::Dagger) => {
400 let (move1base, move2base, move3) = match stage_section {
401 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
402 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
403 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
404 _ => (0.0, 0.0, 0.0),
405 };
406 let pullback = 1.0 - move3;
407 let move1abs = move1base * pullback;
408 let move2abs = move2base * pullback;
409 next.main.position = Vec3::new(0.0, 2.0, -5.0);
410 next.control_l.position = Vec3::new(
411 0.0,
412 0.0 + move1abs * 1.0 + move2abs * -1.0,
413 -2.0 + move1abs * -2.0,
414 );
415 next.control_r.position = Vec3::new(
416 -1.0 + s_a.grip.0 * 2.0,
417 2.0 + move3 * -4.0,
418 -2.0 + move3 * -4.0,
419 );
420
421 next.control.position = Vec3::new(
422 -1.0,
423 0.0 + move1abs * -3.0 + move2abs * 3.0 + s_a.grip.2,
424 3.0 + move1abs * 3.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
425 );
426
427 next.control_l.orientation =
428 Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
429 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
430 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2 + move3 * -1.5);
431
432 next.control.orientation =
433 Quaternion::rotation_x(-0.3 + move1abs * 0.5 + move2abs * -0.5 + move3 * 0.5)
434 * Quaternion::rotation_y(0.5 * speednorm);
435
436 if matches!(stage_section, Some(StageSection::Recover)) {
437 next.main.scale = Vec3::zero();
438 }
439 },
440 Some(ToolKind::Axe) => {
441 let (move1base, move2base, move3) = match stage_section {
442 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
443 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
444 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
445 _ => (0.0, 0.0, 0.0),
446 };
447 let pullback = 1.0 - move3;
448 let move1abs = move1base * pullback;
449 let move2abs = move2base * pullback;
450 next.main.position = Vec3::new(-2.0, 6.0, 0.0);
451 next.control_l.position = Vec3::new(-2.0 - s_a.grip.0 * 2.0, 7.0, 3.0);
452 next.control_r.position = Vec3::new(
453 2.0 + s_a.grip.0 * 2.0,
454 9.0 + move3 * -4.0,
455 2.0 + move3 * -4.0,
456 );
457
458 next.control.position = Vec3::new(
459 -1.0,
460 0.0 + move1abs * -3.0 + move2abs * 3.0 + s_a.grip.2,
461 3.0 + move1abs * 3.0 - s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0,
462 );
463 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
464 * Quaternion::rotation_y(-0.0)
465 * Quaternion::rotation_z(-0.0);
466
467 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
468 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
469
470 next.control.orientation =
471 Quaternion::rotation_x(-0.3 + move1abs * 0.5 + move2abs * -0.5 + move3 * 0.5)
472 * Quaternion::rotation_y(0.5 * speednorm);
473
474 if matches!(stage_section, Some(StageSection::Recover)) {
475 next.main.scale = Vec3::zero();
476 }
477 },
478 _ => {},
479 }
480
481 next
482 }
483}