veloren_voxygen_anim/arthropod/
multi.rs

1use std::f32::consts::PI;
2
3use super::{
4    super::{Animation, vek::*},
5    ArthropodSkeleton, SkeletonAttr,
6};
7use common::states::utils::StageSection;
8
9pub struct MultiAction;
10
11pub struct MultiActionDependency<'a> {
12    pub ability_id: Option<&'a str>,
13    pub stage_section: Option<StageSection>,
14    pub current_action: u32,
15    pub max_actions: Option<u32>,
16    pub global_time: f32,
17    pub timer: f32,
18}
19
20impl Animation for MultiAction {
21    type Dependency<'a> = MultiActionDependency<'a>;
22    type Skeleton = ArthropodSkeleton;
23
24    #[cfg(feature = "use-dyn-lib")]
25    const UPDATE_FN: &'static [u8] = b"arthropod_multi\0";
26
27    #[cfg_attr(feature = "be-dyn-lib", export_name = "arthropod_multi")]
28    fn update_skeleton_inner(
29        skeleton: &Self::Skeleton,
30        d: Self::Dependency<'_>,
31        anim_time: f32,
32        _rate: &mut f32,
33        s_a: &SkeletonAttr,
34    ) -> Self::Skeleton {
35        let mut next = (*skeleton).clone();
36
37        let multi_action_pullback = 1.0
38            - if matches!(d.stage_section, Some(StageSection::Recover)) {
39                anim_time
40            } else {
41                0.0
42            };
43
44        for action in 0..=d.current_action {
45            let (move1base, move2base, move3base) = if action == d.current_action {
46                match d.stage_section {
47                    Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
48                    Some(StageSection::Action) => (1.0, anim_time, 0.0),
49                    Some(StageSection::Recover) => (1.0, 1.0, anim_time),
50                    _ => (0.0, 0.0, 0.0),
51                }
52            } else {
53                (1.0, 1.0, 1.0)
54            };
55            let _move1 = move1base * multi_action_pullback;
56            let _move2 = move2base * multi_action_pullback;
57
58            match d.ability_id {
59                Some(
60                    "common.abilities.custom.arthropods.tarantula.singlestrike"
61                    | "common.abilities.custom.arthropods.blackwidow.singlestrike"
62                    | "common.abilities.custom.arthropods.antlion.singlestrike"
63                    | "common.abilities.custom.arthropods.hornbeetle.singlestrike"
64                    | "common.abilities.custom.arthropods.weevil.singlestrike"
65                    | "common.abilities.custom.arthropods.crawler.singlestrike",
66                ) => {
67                    let pullback = 1.0 - move3base;
68                    let subtract = d.global_time - d.timer;
69                    let check = subtract - subtract.trunc();
70                    let mirror = (check - 0.5).signum();
71                    let movement1abs = move1base.powi(2) * pullback;
72                    let movement2abs = move2base.powi(4) * pullback;
73                    let movement3abs = move3base * pullback;
74
75                    if s_a.snapper {
76                        next.chest.scale = Vec3::one() * s_a.scaler;
77
78                        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
79                        next.head.orientation = Quaternion::rotation_x(
80                            movement1abs * -0.2 + movement2abs * 0.4 + movement3abs * 0.8,
81                        ) * Quaternion::rotation_y(
82                            movement1abs * -0.1 + movement2abs * 0.2 + movement3abs * 0.2,
83                        );
84
85                        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
86
87                        next.mandible_l.position =
88                            Vec3::new(-s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
89                        next.mandible_r.position =
90                            Vec3::new(s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
91                        next.mandible_l.orientation = Quaternion::rotation_z(
92                            movement1abs * 0.7 + movement2abs * -1.0 + movement3abs * 0.8,
93                        );
94                        next.mandible_r.orientation = Quaternion::rotation_z(
95                            movement1abs * -0.7 + movement2abs * 1.0 + movement3abs * -0.8,
96                        );
97
98                        next.wing_fl.position =
99                            Vec3::new(-s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
100                        next.wing_fr.position = Vec3::new(s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
101                        next.wing_fl.orientation =
102                            Quaternion::rotation_x(movement1abs * -0.5 + movement2abs * 0.5)
103                                * Quaternion::rotation_y(movement1abs * 0.2 + movement2abs * -0.2)
104                                * Quaternion::rotation_z(movement1abs * -0.2 + movement2abs * 0.2);
105                        next.wing_fr.orientation =
106                            Quaternion::rotation_x(movement1abs * -0.5 + movement2abs * 0.5)
107                                * Quaternion::rotation_y(movement1abs * -0.2 + movement2abs * 0.2)
108                                * Quaternion::rotation_z(movement1abs * 0.2 + movement2abs * -0.2);
109
110                        next.wing_bl.position =
111                            Vec3::new(-s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
112                        next.wing_br.position = Vec3::new(s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
113                        next.wing_bl.orientation =
114                            Quaternion::rotation_x(movement1abs * -0.3 + movement2abs * 0.3)
115                                * Quaternion::rotation_y(movement1abs * 0.2 + movement2abs * -0.2);
116                        next.wing_br.orientation =
117                            Quaternion::rotation_x(movement1abs * -0.3 + movement2abs * 0.3)
118                                * Quaternion::rotation_y(movement1abs * -0.2 + movement2abs * 0.2);
119
120                        next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
121                        next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
122
123                        next.leg_fcl.position =
124                            Vec3::new(-s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
125                        next.leg_fcr.position = Vec3::new(s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
126
127                        next.leg_bcl.position =
128                            Vec3::new(-s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
129                        next.leg_bcr.position = Vec3::new(s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
130
131                        next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
132                        next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
133                    } else {
134                        next.chest.scale = Vec3::one() * s_a.scaler;
135                        next.chest.orientation = Quaternion::rotation_x(movement2abs * 0.3)
136                            * Quaternion::rotation_z((movement1abs * 4.0 * PI).sin() * 0.02);
137
138                        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
139                        next.head.orientation =
140                            Quaternion::rotation_x(
141                                movement1abs * 0.5 + movement2abs * -1.5 + movement3abs * 0.8,
142                            ) * Quaternion::rotation_y(
143                                mirror * movement1abs * -0.2 + mirror * movement2abs * 0.2,
144                            ) * Quaternion::rotation_z((movement1abs * 4.0 * PI).sin() * 0.02);
145
146                        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
147
148                        next.mandible_l.position =
149                            Vec3::new(-s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
150                        next.mandible_r.position =
151                            Vec3::new(s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
152                        next.mandible_l.orientation = Quaternion::rotation_x(
153                            movement1abs * 0.5 + movement2abs * -1.5 + movement3abs * 0.8,
154                        ) * Quaternion::rotation_z(
155                            movement1abs * 0.5 + movement2abs * -0.6 + movement3abs * 0.8,
156                        );
157                        next.mandible_r.orientation = Quaternion::rotation_x(
158                            movement1abs * 0.5 + movement2abs * -1.5 + movement3abs * 0.8,
159                        ) * Quaternion::rotation_z(
160                            movement1abs * -0.5 + movement2abs * 0.6 + movement3abs * -0.8,
161                        );
162
163                        next.wing_fl.position =
164                            Vec3::new(-s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
165                        next.wing_fr.position = Vec3::new(s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
166
167                        next.wing_bl.position =
168                            Vec3::new(-s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
169                        next.wing_br.position = Vec3::new(s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
170
171                        next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
172                        next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
173                        next.leg_fl.orientation = Quaternion::rotation_z(
174                            s_a.leg_ori.0
175                                + movement1abs * 0.4
176                                + movement2abs * -0.4
177                                + movement3abs * 0.8,
178                        ) * Quaternion::rotation_x(
179                            movement1abs * 1.0 + movement2abs * -1.8 + movement3abs * 0.8,
180                        );
181                        next.leg_fr.orientation = Quaternion::rotation_z(
182                            -s_a.leg_ori.0
183                                + movement1abs * -0.4
184                                + movement2abs * 0.4
185                                + movement3abs * -0.8,
186                        ) * Quaternion::rotation_x(
187                            movement1abs * 1.0 + movement2abs * -1.8 + movement3abs * 0.8,
188                        );
189
190                        next.leg_fcl.position =
191                            Vec3::new(-s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
192                        next.leg_fcr.position = Vec3::new(s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
193
194                        next.leg_bcl.position =
195                            Vec3::new(-s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
196                        next.leg_bcr.position = Vec3::new(s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
197
198                        next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
199                        next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
200                    }
201                },
202                _ => {},
203            }
204        }
205
206        next
207    }
208}