2020-03-16 11:32:57 +00:00
|
|
|
use crate::{
|
2021-03-14 15:19:22 +00:00
|
|
|
comp::{CharacterState, StateUpdate},
|
2020-12-01 00:28:00 +00:00
|
|
|
states::{
|
|
|
|
behavior::{CharacterBehavior, JoinData},
|
|
|
|
utils::*,
|
|
|
|
},
|
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
|
|
|
|
2020-10-17 02:29:14 +00:00
|
|
|
/// Separated out to condense update portions of character state
|
2020-03-16 11:32:57 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2020-10-17 02:29:14 +00:00
|
|
|
pub struct StaticData {
|
|
|
|
pub movement_duration: Duration,
|
2020-03-16 11:32:57 +00:00
|
|
|
pub only_up: bool,
|
2021-03-26 20:11:25 +00:00
|
|
|
pub speed: f32,
|
|
|
|
pub max_exit_velocity: f32,
|
2021-03-12 04:53:25 +00:00
|
|
|
pub ability_info: AbilityInfo,
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 02:29:14 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Data {
|
|
|
|
/// Struct containing data that does not change over the course of the
|
|
|
|
/// character state
|
|
|
|
pub static_data: StaticData,
|
|
|
|
/// Timer for each stage
|
|
|
|
pub timer: Duration,
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:32:57 +00:00
|
|
|
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
|
|
|
|
2020-10-17 02:29:14 +00:00
|
|
|
if self.timer < self.static_data.movement_duration {
|
|
|
|
// Movement
|
|
|
|
if self.static_data.only_up {
|
2021-03-26 20:11:25 +00:00
|
|
|
update.vel.0.z += self.static_data.speed * data.dt.0;
|
2020-03-16 11:32:57 +00:00
|
|
|
} else {
|
2021-03-26 20:11:25 +00:00
|
|
|
update.vel.0 += *data.inputs.look_dir * self.static_data.speed * data.dt.0;
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|
|
|
|
update.character = CharacterState::Boost(Data {
|
2021-05-30 19:39:30 +00:00
|
|
|
timer: tick_attack_or_default(data, self.timer, None),
|
2020-10-27 22:16:17 +00:00
|
|
|
..*self
|
2020-03-16 11:32:57 +00:00
|
|
|
});
|
2020-10-17 02:29:14 +00:00
|
|
|
} else {
|
|
|
|
// Done
|
2021-03-14 18:42:39 +00:00
|
|
|
if input_is_pressed(data, self.static_data.ability_info.input) {
|
2021-03-12 21:01:30 +00:00
|
|
|
reset_state(self, data, &mut update);
|
2021-03-14 15:19:22 +00:00
|
|
|
} else {
|
2021-03-27 23:05:48 +00:00
|
|
|
update.vel.0 = update.vel.0.try_normalized().unwrap_or_default()
|
2021-03-26 20:11:25 +00:00
|
|
|
* update
|
|
|
|
.vel
|
|
|
|
.0
|
|
|
|
.magnitude()
|
|
|
|
.min(self.static_data.max_exit_velocity);
|
2021-03-14 15:19:22 +00:00
|
|
|
update.character = CharacterState::Wielding;
|
2021-03-12 21:01:30 +00:00
|
|
|
}
|
2021-03-12 04:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 21:01:30 +00:00
|
|
|
fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) {
|
2021-03-14 18:42:39 +00:00
|
|
|
handle_input(join, update, data.static_data.ability_info.input);
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|