mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
c212de00c2
- replace serde_derive by feature of serde incl. source code modifications to compile - reduce futures-timer to "2.0" to be same as async_std - update notify - removed mio, bincode and lz4 compress in common as networking is now in own crate btw there is a better lz4 compress crate, which is newer than 2017 - update prometheus to 0.9 - can't update uvth yet due to usues - hashbrown to 7.2 to only need a single version - libsqlite3 update - image didn't change as there is a problem with `image 0.23` - switch old directories with newer directories-next - no num upgrade as we still depend on num 0.2 anyways - rodio and cpal upgrade - const-tewaker update - dispatch (untested) update - git2 update - iterations update
56 lines
1.8 KiB
Rust
56 lines
1.8 KiB
Rust
use crate::{
|
|
comp::{CharacterState, StateUpdate},
|
|
sys::character_behavior::{CharacterBehavior, JoinData},
|
|
util::Dir,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::time::Duration;
|
|
use vek::Vec3;
|
|
|
|
const ROLL_SPEED: f32 = 25.0;
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
|
pub struct Data {
|
|
/// How long the state has until exiting
|
|
pub remaining_duration: Duration,
|
|
/// Had weapon
|
|
pub was_wielded: bool,
|
|
}
|
|
|
|
impl CharacterBehavior for Data {
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
// Update velocity
|
|
update.vel.0 = Vec3::new(0.0, 0.0, update.vel.0.z)
|
|
+ (update.vel.0 * Vec3::new(1.0, 1.0, 0.0)
|
|
+ 0.25 * data.inputs.move_dir.try_normalized().unwrap_or_default())
|
|
.try_normalized()
|
|
.unwrap_or_default()
|
|
* ROLL_SPEED;
|
|
|
|
// Smooth orientation
|
|
update.ori.0 = Dir::slerp_to_vec3(update.ori.0, update.vel.0.xy().into(), 9.0 * data.dt.0);
|
|
|
|
if self.remaining_duration == Duration::default() {
|
|
// Roll duration has expired
|
|
update.vel.0 *= 0.3;
|
|
if self.was_wielded {
|
|
update.character = CharacterState::Wielding;
|
|
} else {
|
|
update.character = CharacterState::Idle;
|
|
}
|
|
} else {
|
|
// Otherwise, tick down remaining_duration
|
|
update.character = CharacterState::Roll(Data {
|
|
remaining_duration: self
|
|
.remaining_duration
|
|
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
|
.unwrap_or_default(),
|
|
was_wielded: self.was_wielded,
|
|
});
|
|
}
|
|
|
|
update
|
|
}
|
|
}
|