veloren_voxygen_anim/golem/
combomelee.rs

1use super::{
2    super::{Animation, vek::*},
3    GolemSkeleton, SkeletonAttr,
4};
5use common::states::utils::{AbilityInfo, StageSection};
6
7pub struct ComboAnimation;
8impl Animation for ComboAnimation {
9    type Dependency<'a> = (
10        Option<&'a str>,
11        Option<StageSection>,
12        Option<AbilityInfo>,
13        usize,
14        Vec2<f32>,
15    );
16    type Skeleton = GolemSkeleton;
17
18    #[cfg(feature = "use-dyn-lib")]
19    const UPDATE_FN: &'static [u8] = b"golem_combo\0";
20
21    #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_combo")]
22    fn update_skeleton_inner(
23        skeleton: &Self::Skeleton,
24        (ability_id, stage_section, _ability_info, current_strike, _move_dir): Self::Dependency<'_>,
25        anim_time: f32,
26        rate: &mut f32,
27        _s_a: &SkeletonAttr,
28    ) -> Self::Skeleton {
29        *rate = 1.0;
30        let mut next = (*skeleton).clone();
31
32        let multi_strike_pullback = 1.0
33            - if matches!(stage_section, Some(StageSection::Recover)) {
34                anim_time.powi(4)
35            } else {
36                0.0
37            };
38
39        for strike in 0..=current_strike {
40            let (move1, move2) = if strike == current_strike {
41                match stage_section {
42                    Some(StageSection::Buildup) => {
43                        (((anim_time.max(0.4) - 0.4) * 1.5).powf(0.5), 0.0)
44                    },
45                    Some(StageSection::Action) => (1.0, (anim_time.min(0.4) * 2.5).powi(2)),
46                    Some(StageSection::Recover) => (1.0, 1.0),
47                    _ => (0.0, 0.0),
48                }
49            } else {
50                (1.0, 1.0)
51            };
52            let move1 = move1 * multi_strike_pullback;
53            let move2 = move2 * multi_strike_pullback;
54
55            match ability_id {
56                Some("common.abilities.custom.claygolem.dashstrike") => match strike {
57                    0..=2 => {
58                        next.head.orientation = Quaternion::rotation_x(-0.2)
59                            * Quaternion::rotation_z(move1 * -1.2 + move2 * 2.0);
60
61                        next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.6)
62                            * Quaternion::rotation_z(move1 * 1.2 + move2 * -3.2);
63
64                        next.lower_torso.orientation =
65                            Quaternion::rotation_z(move1 * -1.2 + move2 * 3.2)
66                                * Quaternion::rotation_x(move1 * 0.6);
67
68                        next.shoulder_l.orientation = Quaternion::rotation_y(move1 * 0.8)
69                            * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.6);
70
71                        next.shoulder_r.orientation = Quaternion::rotation_x(move1 * 0.4);
72
73                        next.hand_l.orientation = Quaternion::rotation_z(0.0)
74                            * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.8);
75
76                        next.hand_r.orientation = Quaternion::rotation_y(move1 * 0.5)
77                            * Quaternion::rotation_x(move1 * 0.4);
78                        next.torso.position = Vec3::new(0.0, move1 * 3.7, -8.0 + move2 * 8.0);
79                    },
80                    _ => {},
81                },
82                _ => match strike {
83                    0..=2 => {
84                        next.head.orientation = Quaternion::rotation_x(-0.2)
85                            * Quaternion::rotation_z(move1 * -1.2 + move2 * 2.0);
86
87                        next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.6)
88                            * Quaternion::rotation_z(move1 * 1.2 + move2 * -3.2);
89
90                        next.lower_torso.orientation =
91                            Quaternion::rotation_z(move1 * -1.2 + move2 * 3.2)
92                                * Quaternion::rotation_x(move1 * 0.6);
93
94                        next.shoulder_l.orientation = Quaternion::rotation_y(move1 * 0.8)
95                            * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.6);
96
97                        next.shoulder_r.orientation = Quaternion::rotation_x(move1 * 0.4);
98
99                        next.hand_l.orientation = Quaternion::rotation_z(0.0)
100                            * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.8);
101
102                        next.hand_r.orientation = Quaternion::rotation_y(move1 * 0.5)
103                            * Quaternion::rotation_x(move1 * 0.4);
104                        next.torso.position = Vec3::new(0.0, move1 * 3.7, move1 * -1.6);
105                    },
106                    _ => {},
107                },
108            }
109        }
110        next
111    }
112}