veloren/common/src/comp/states/basic_block.rs

42 lines
1.3 KiB
Rust
Raw Normal View History

2019-12-28 16:10:39 +00:00
use super::{BLOCK_ACCEL, BLOCK_SPEED};
use crate::comp::{EcsStateData, StateHandle, StateUpdate};
use crate::util::movement_utils::*;
2019-12-26 14:43:59 +00:00
use std::time::Duration;
2019-12-26 18:01:19 +00:00
use vek::Vec2;
2019-12-26 14:43:59 +00:00
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
2019-12-28 16:10:39 +00:00
pub struct BasicBlockState {
2019-12-26 14:43:59 +00:00
/// How long the blocking state has been active
active_duration: Duration,
}
2019-12-28 16:10:39 +00:00
impl StateHandle for BasicBlockState {
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {
let mut update = StateUpdate {
2019-12-26 14:43:59 +00:00
pos: *ecs_data.pos,
vel: *ecs_data.vel,
ori: *ecs_data.ori,
character: *ecs_data.character,
};
2019-12-26 18:01:19 +00:00
// TODO: Apply simple move speed debuff instead
2019-12-28 16:10:39 +00:00
update.character.move_disabled = true;
2019-12-26 18:01:19 +00:00
// Update movement
update.vel.0 += Vec2::broadcast(ecs_data.dt.0)
* ecs_data.inputs.move_dir
* match ecs_data.physics.on_ground {
true if update.vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL,
_ => 0.0,
};
if !ecs_data.inputs.secondary.is_pressed() {
2019-12-28 16:10:39 +00:00
update.character.action_state = attempt_wield(ecs_data.stats);
2019-12-26 18:01:19 +00:00
update.character.move_disabled = false;
return update;
}
return update;
2019-12-26 14:43:59 +00:00
}
}