2020-03-16 11:32:57 +00:00
|
|
|
use crate::{
|
|
|
|
comp::{Attacking, CharacterState, EnergySource, StateUpdate},
|
2020-03-20 14:45:36 +00:00
|
|
|
states::utils::*,
|
2020-09-30 00:47:11 +00:00
|
|
|
sys::character_behavior::{CharacterBehavior, JoinData},
|
2020-03-16 11:32:57 +00:00
|
|
|
};
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-03-21 21:16:26 +00:00
|
|
|
use std::time::Duration;
|
2020-03-16 11:32:57 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Data {
|
|
|
|
/// How long the state has until exiting
|
|
|
|
pub duration: Duration,
|
|
|
|
pub only_up: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CharacterBehavior for Data {
|
|
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
2020-03-21 21:16:26 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2020-03-16 11:32:57 +00:00
|
|
|
|
2020-03-26 19:02:01 +00:00
|
|
|
handle_move(data, &mut update, 1.0);
|
2020-03-16 11:32:57 +00:00
|
|
|
|
|
|
|
// Still going
|
|
|
|
if self.duration != Duration::default() {
|
|
|
|
if self.only_up {
|
2020-03-19 16:01:58 +00:00
|
|
|
update.vel.0.z += 500.0 * data.dt.0;
|
2020-03-16 11:32:57 +00:00
|
|
|
} else {
|
2020-03-28 01:31:22 +00:00
|
|
|
update.vel.0 += *data.inputs.look_dir * 500.0 * data.dt.0;
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|
|
|
|
update.character = CharacterState::Boost(Data {
|
|
|
|
duration: self
|
|
|
|
.duration
|
|
|
|
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
only_up: self.only_up,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Done
|
|
|
|
else {
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grant energy on successful hit
|
|
|
|
if let Some(attack) = data.attacking {
|
|
|
|
if attack.applied && attack.hit_count > 0 {
|
|
|
|
data.updater.remove::<Attacking>(data.entity);
|
|
|
|
update.energy.change_by(100, EnergySource::HitEnemy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
|
|
|
}
|