1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::{AbilitySpec, Hands, ToolKind};
6use core::{f32::consts::PI, ops::Mul};
7
8pub struct SneakWieldAnimation;
9
10impl Animation for SneakWieldAnimation {
11 type Dependency<'a> = (
12 (Option<ToolKind>, Option<&'a AbilitySpec>),
13 Option<ToolKind>,
14 (Option<Hands>, Option<Hands>),
15 Vec3<f32>,
16 Vec3<f32>,
17 Vec3<f32>,
18 Vec3<f32>,
19 f32,
20 );
21 type Skeleton = CharacterSkeleton;
22
23 #[cfg(feature = "use-dyn-lib")]
24 const UPDATE_FN: &'static [u8] = b"character_sneakwield\0";
25
26 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_sneakwield"))]
27 fn update_skeleton_inner(
28 skeleton: &Self::Skeleton,
29 (
30 (active_tool_kind, active_tool_spec),
31 second_tool_kind,
32 hands,
33 velocity,
34 orientation,
35 last_ori,
36 look_dir,
37 global_time,
38 ): Self::Dependency<'_>,
39 anim_time: f32,
40 rate: &mut f32,
41 s_a: &SkeletonAttr,
42 ) -> Self::Skeleton {
43 let mut next = (*skeleton).clone();
44 let speed = Vec2::<f32>::from(velocity).magnitude();
45 *rate = 1.0;
46 let slow = (anim_time * 3.0).sin();
47 let breathe = ((anim_time * 0.5).sin()).abs();
48 let walkintensity = if speed > 5.0 { 1.0 } else { 0.45 };
49 let lower = if speed > 5.0 { 0.0 } else { 1.0 };
50 let _snapfoot = if speed > 5.0 { 1.1 } else { 2.0 };
51 let lab: f32 = 1.0;
52 let foothoril = (anim_time * 7.0 * lab + PI * 1.45).sin();
53 let foothorir = (anim_time * 7.0 * lab + PI * (0.45)).sin();
54 let speednorm = speed / 4.0;
55
56 let footvertl = (anim_time * 7.0 * lab).sin();
57 let footvertr = (anim_time * 7.0 * lab + PI).sin();
58
59 let footrotl = ((5.0 / (2.5 + (2.5) * ((anim_time * 7.0 * lab + PI * 1.4).sin()).powi(2)))
60 .sqrt())
61 * ((anim_time * 7.0 * lab + PI * 1.4).sin());
62
63 let footrotr = ((5.0 / (1.0 + (4.0) * ((anim_time * 7.0 * lab + PI * 0.4).sin()).powi(2)))
64 .sqrt())
65 * ((anim_time * 7.0 * lab + PI * 0.4).sin());
66
67 let short = (anim_time * lab * 7.0).sin();
68 let noisea = (anim_time * 11.0 + PI / 6.0).sin();
69 let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
70
71 let shortalt = (anim_time * lab * 7.0 + PI / 2.0).sin();
72
73 let head_look = Vec2::new(
74 (global_time + anim_time / 18.0).floor().mul(7331.0).sin() * 0.2,
75 (global_time + anim_time / 18.0).floor().mul(1337.0).sin() * 0.1,
76 );
77
78 let orientation: Vec2<f32> = Vec2::from(orientation);
79 let tilt = if vek::Vec2::new(orientation, last_ori.xy())
80 .map(|o| o.magnitude_squared())
81 .map(|m| m > 0.001 && m.is_finite())
82 .reduce_and()
83 && orientation.angle_between(last_ori.xy()).is_finite()
84 {
85 orientation.angle_between(last_ori.xy()).min(0.2)
86 * last_ori
87 .xy()
88 .determine_side(Vec2::zero(), orientation)
89 .signum()
90 } else {
91 0.0
92 } * 1.3;
93 next.main.position = Vec3::new(0.0, 0.0, 0.0);
94 next.main.orientation = Quaternion::rotation_x(0.0);
95 next.second.position = Vec3::new(0.0, 0.0, 0.0);
96 next.second.orientation = Quaternion::rotation_x(0.0);
97 next.hold.scale = Vec3::one() * 0.0;
98
99 if speed > 0.5 {
100 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 4.0 + s_a.hand.1, 1.0 + s_a.hand.2);
101 next.hand_l.orientation = Quaternion::rotation_x(1.0);
102
103 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, -1.0 + s_a.hand.1, s_a.hand.2);
104 next.hand_r.orientation = Quaternion::rotation_x(0.4);
105 next.head.position = Vec3::new(0.0, 1.0 + s_a.head.0, -1.0 + s_a.head.1 + short * 0.06);
106 next.head.orientation =
107 Quaternion::rotation_z(tilt * -2.5 + head_look.x * 0.2 - short * 0.06)
108 * Quaternion::rotation_x(head_look.y + 0.45);
109
110 next.chest.position = Vec3::new(0.0, s_a.chest.0, -1.0 + s_a.chest.1 + shortalt * -0.5);
111 next.chest.orientation = Quaternion::rotation_z(0.3 + short * 0.08 + tilt * -0.2)
112 * Quaternion::rotation_y(tilt * 0.8)
113 * Quaternion::rotation_x(-0.5);
114
115 next.belt.position = Vec3::new(0.0, 0.5 + s_a.belt.0, 0.7 + s_a.belt.1);
116 next.belt.orientation = Quaternion::rotation_z(short * 0.1 + tilt * -1.1)
117 * Quaternion::rotation_y(tilt * 0.5)
118 * Quaternion::rotation_x(0.2);
119
120 next.back.orientation =
121 Quaternion::rotation_x(-0.25 + short * 0.1 + noisea * 0.1 + noiseb * 0.1);
122
123 next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, 1.0 + s_a.shorts.1);
124 next.shorts.orientation = Quaternion::rotation_z(short * 0.16 + tilt * -1.5)
125 * Quaternion::rotation_y(tilt * 0.7)
126 * Quaternion::rotation_x(0.3);
127
128 next.foot_l.position = Vec3::new(
129 -s_a.foot.0,
130 s_a.foot.1 + foothoril * -10.5 * walkintensity - lower * 1.0,
131 1.0 + s_a.foot.2 + ((footvertl * -1.7).max(-1.0)) * walkintensity,
132 );
133 next.foot_l.orientation =
134 Quaternion::rotation_x(-0.2 + footrotl * -0.8 * walkintensity)
135 * Quaternion::rotation_y(tilt * 1.8);
136
137 next.foot_r.position = Vec3::new(
138 s_a.foot.0,
139 s_a.foot.1 + foothorir * -10.5 * walkintensity - lower * 1.0,
140 1.0 + s_a.foot.2 + ((footvertr * -1.7).max(-1.0)) * walkintensity,
141 );
142 next.foot_r.orientation =
143 Quaternion::rotation_x(-0.2 + footrotr * -0.8 * walkintensity)
144 * Quaternion::rotation_y(tilt * 1.8);
145
146 next.shoulder_l.orientation = Quaternion::rotation_x(short * 0.15 * walkintensity);
147
148 next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 * walkintensity);
149 } else {
150 next.head.position = Vec3::new(
151 0.0,
152 1.0 + s_a.head.0,
153 -2.0 + s_a.head.1 + slow * 0.1 + breathe * -0.05,
154 );
155 next.head.orientation = Quaternion::rotation_z(head_look.x)
156 * Quaternion::rotation_x(0.6 + head_look.y.abs());
157
158 next.chest.position = Vec3::new(0.0, s_a.chest.0, -3.0 + s_a.chest.1 + slow * 0.1);
159 next.chest.orientation = Quaternion::rotation_x(-0.7);
160
161 next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
162 next.belt.orientation = Quaternion::rotation_z(0.3 + head_look.x * -0.1);
163
164 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 5.0 + s_a.hand.1, 0.0 + s_a.hand.2);
165 next.hand_l.orientation = Quaternion::rotation_x(1.35);
166
167 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, s_a.hand.1, s_a.hand.2);
168 next.hand_r.orientation = Quaternion::rotation_x(0.4);
169
170 next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
171 next.shorts.orientation = Quaternion::rotation_z(0.6 + head_look.x * -0.2);
172
173 next.foot_l.position = Vec3::new(-s_a.foot.0, -6.0 + s_a.foot.1, 1.0 + s_a.foot.2);
174 next.foot_l.orientation = Quaternion::rotation_x(-0.5);
175
176 next.foot_r.position = Vec3::new(s_a.foot.0, 4.0 + s_a.foot.1, s_a.foot.2);
177 }
178
179 match (hands, active_tool_kind, second_tool_kind) {
180 ((Some(Hands::Two), _), tool, _) | ((None, Some(Hands::Two)), _, tool) => match tool {
181 Some(ToolKind::Sword) => {
182 next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
183 next.hand_l.orientation =
184 Quaternion::rotation_x(s_a.shl.3) * Quaternion::rotation_y(s_a.shl.4);
185 next.hand_r.position = Vec3::new(s_a.shr.0, s_a.shr.1, s_a.shr.2);
186 next.hand_r.orientation =
187 Quaternion::rotation_x(s_a.shr.3) * Quaternion::rotation_y(s_a.shr.4);
188
189 next.control.position = Vec3::new(s_a.sc.0, s_a.sc.1 - 3.0, s_a.sc.2);
190 next.control.orientation =
191 Quaternion::rotation_x(s_a.sc.3) * Quaternion::rotation_z(0.0);
192 },
193 Some(ToolKind::Axe) => {
194 next.main.position = Vec3::new(0.0, 0.0, 0.0);
195 next.main.orientation = Quaternion::rotation_x(0.0);
196
197 if speed < 0.5 {
198 next.head.position = Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1);
199 next.head.orientation = Quaternion::rotation_z(head_look.x)
200 * Quaternion::rotation_x(0.35 + head_look.y.abs());
201 next.chest.orientation = Quaternion::rotation_x(-0.35)
202 * Quaternion::rotation_y(0.0)
203 * Quaternion::rotation_z(0.15);
204 next.belt.position = Vec3::new(0.0, 1.0 + s_a.belt.0, s_a.belt.1);
205 next.belt.orientation = Quaternion::rotation_x(0.15)
206 * Quaternion::rotation_y(0.0)
207 * Quaternion::rotation_z(0.15);
208 next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, s_a.shorts.1);
209 next.shorts.orientation =
210 Quaternion::rotation_x(0.15) * Quaternion::rotation_z(0.25);
211 }
212 next.hand_l.position = Vec3::new(s_a.ahl.0, s_a.ahl.1, s_a.ahl.2);
213 next.hand_l.orientation =
214 Quaternion::rotation_x(s_a.ahl.3) * Quaternion::rotation_y(s_a.ahl.4);
215 next.hand_r.position = Vec3::new(s_a.ahr.0, s_a.ahr.1, s_a.ahr.2);
216 next.hand_r.orientation =
217 Quaternion::rotation_x(s_a.ahr.3) * Quaternion::rotation_z(s_a.ahr.5);
218
219 next.control.position = Vec3::new(s_a.ac.0, s_a.ac.1, s_a.ac.2);
220 next.control.orientation = Quaternion::rotation_x(s_a.ac.3)
221 * Quaternion::rotation_y(s_a.ac.4)
222 * Quaternion::rotation_z(s_a.ac.5);
223 },
224 Some(ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
225 next.hand_l.position = Vec3::new(s_a.hhl.0, s_a.hhl.1, s_a.hhl.2);
226 next.hand_l.orientation = Quaternion::rotation_x(s_a.hhl.3)
227 * Quaternion::rotation_y(s_a.hhl.4)
228 * Quaternion::rotation_z(s_a.hhl.5);
229 next.hand_r.position = Vec3::new(s_a.hhr.0, s_a.hhr.1, s_a.hhr.2);
230 next.hand_r.orientation = Quaternion::rotation_x(s_a.hhr.3)
231 * Quaternion::rotation_y(s_a.hhr.4)
232 * Quaternion::rotation_z(s_a.hhr.5);
233
234 next.control.position =
235 Vec3::new(s_a.hc.0, s_a.hc.1 + speed * 0.2, s_a.hc.2 + 6.0);
236 next.control.orientation = Quaternion::rotation_x(s_a.hc.3)
237 * Quaternion::rotation_y(s_a.hc.4 + speed * -0.04)
238 * Quaternion::rotation_z(s_a.hc.5);
239 },
240 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
241 if speed > 0.5 && velocity.z == 0.0 {
242 next.hand_r.position = Vec3::new(
243 7.0 + s_a.hand.0 + foothoril * 1.3,
244 -4.0 + s_a.hand.1 + foothoril * -7.0,
245 1.0 + s_a.hand.2 - foothoril * 5.5,
246 );
247 next.hand_r.orientation = Quaternion::rotation_x(0.6 + footrotl * -1.2)
248 * Quaternion::rotation_y(footrotl * -0.4);
249 } else {
250 next.hand_r.position = Vec3::new(s_a.sthr.0, s_a.sthr.1, s_a.sthr.2);
251 next.hand_r.orientation =
252 Quaternion::rotation_x(s_a.sthr.3) * Quaternion::rotation_y(s_a.sthr.4);
253 };
254
255 next.control.position = Vec3::new(s_a.stc.0, s_a.stc.1 - 2.0, s_a.stc.2 + 4.0);
256
257 next.hand_l.position = Vec3::new(s_a.sthl.0, s_a.sthl.1, s_a.sthl.2);
258 next.hand_l.orientation = Quaternion::rotation_x(s_a.sthl.3);
259
260 next.control.orientation = Quaternion::rotation_x(s_a.stc.3)
261 * Quaternion::rotation_y(s_a.stc.4)
262 * Quaternion::rotation_z(s_a.stc.5);
263 },
264 Some(ToolKind::Bow) => {
265 next.main.position = Vec3::new(0.0, 0.0, 0.0);
266 next.main.orientation = Quaternion::rotation_x(0.0);
267 next.hand_l.position = Vec3::new(s_a.bhl.0, s_a.bhl.1, s_a.bhl.2);
268 next.hand_l.orientation = Quaternion::rotation_x(s_a.bhl.3);
269 next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2);
270 next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3);
271
272 next.hold.position = Vec3::new(0.0, -1.0, -5.2);
273 next.hold.orientation = Quaternion::rotation_x(-PI / 2.0);
274 next.hold.scale = Vec3::one() * 1.0;
275
276 next.control.position = Vec3::new(s_a.bc.0 + 2.0, s_a.bc.1, s_a.bc.2 + 5.0);
277 next.control.orientation = Quaternion::rotation_x(speednorm * -0.5 + 0.8)
278 * Quaternion::rotation_y(s_a.bc.4)
279 * Quaternion::rotation_z(s_a.bc.5);
280 },
281 Some(ToolKind::Instrument) => {
282 if let Some(AbilitySpec::Custom(spec)) = active_tool_spec {
283 match spec.as_str() {
284 "Washboard" => {
285 next.hand_l.position = Vec3::new(-7.0, 0.0, 3.0);
286 next.hand_l.orientation = Quaternion::rotation_x(1.27);
287 next.main.position = Vec3::new(-5.0, -4.5, -5.0);
288 next.main.orientation = Quaternion::rotation_x(5.5);
289 },
290 _ => {
291 next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
292 next.hand_l.orientation = Quaternion::rotation_x(1.27);
293 next.main.position = Vec3::new(-5.0, 5.0, 23.0);
294 next.main.orientation = Quaternion::rotation_x(PI);
295 },
296 }
297 }
298 },
299 Some(ToolKind::Debug) => {
300 next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
301 next.hand_l.orientation = Quaternion::rotation_x(1.27);
302 next.main.position = Vec3::new(-5.0, 5.0, 23.0);
303 next.main.orientation = Quaternion::rotation_x(PI);
304 },
305 Some(ToolKind::Farming) => {
306 if speed < 0.5 {
307 next.head.orientation = Quaternion::rotation_z(head_look.x)
308 * Quaternion::rotation_x(-0.2 + head_look.y.abs());
309 }
310 next.hand_l.position = Vec3::new(9.0, 1.0, 1.0);
311 next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0);
312 next.hand_r.position = Vec3::new(9.0, 1.0, 11.0);
313 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
314 next.main.position = Vec3::new(7.5, 7.5, 13.2);
315 next.main.orientation = Quaternion::rotation_y(PI);
316
317 next.control.position = Vec3::new(-11.0 + slow * 2.0, 1.8, 4.0);
318 next.control.orientation = Quaternion::rotation_x(0.0)
319 * Quaternion::rotation_y(0.6)
320 * Quaternion::rotation_z(0.0);
321 },
322 _ => {},
323 },
324 ((_, _), _, _) => {},
325 };
326 match hands {
327 (Some(Hands::One), _) => {
328 next.control_l.position = Vec3::new(-7.0, 6.0, 5.0);
329 next.control_l.orientation =
330 Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(0.2);
331 next.hand_l.position = Vec3::new(-1.0, -0.5, 0.0);
332 next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
333 },
334 (_, _) => {},
335 };
336 match hands {
337 (None | Some(Hands::One), Some(Hands::One)) => {
338 next.control_r.position = Vec3::new(7.0, 6.0, 5.0);
339 next.control_r.orientation =
340 Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(-0.2);
341 next.hand_r.position = Vec3::new(1.0, -0.5, 0.0);
342 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
343 },
344 (_, _) => {},
345 };
346 match hands {
347 (None, None) | (None, Some(Hands::One)) => {
348 next.hand_l.position = Vec3::new(-8.0, 2.0, 1.0);
349 next.hand_l.orientation =
350 Quaternion::rotation_x(0.5) * Quaternion::rotation_y(0.25);
351 },
352 (_, _) => {},
353 };
354 match hands {
355 (None, None) | (Some(Hands::One), None) => {
356 next.hand_r.position = Vec3::new(8.0, 2.0, 1.0);
357 next.hand_r.orientation =
358 Quaternion::rotation_x(0.5) * Quaternion::rotation_y(-0.25);
359 },
360 (_, _) => {},
361 };
362
363 if let (None, Some(Hands::Two)) = hands {
364 next.second = next.main;
365 }
366
367 next.do_hold_lantern(
368 s_a,
369 anim_time,
370 anim_time,
371 speednorm,
372 0.0,
373 tilt,
374 Some(last_ori),
375 Some(look_dir),
376 );
377
378 next
379 }
380}