2020-03-16 11:32:57 +00:00
|
|
|
use crate::{
|
2021-03-12 04:53:25 +00:00
|
|
|
comp::{CharacterState, InputKind, 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-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,
|
2021-03-12 04:53:25 +00:00
|
|
|
/// Whether or not the state should end
|
|
|
|
pub end: bool,
|
2020-10-17 02:29:14 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
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 {
|
2020-10-17 02:29:14 +00:00
|
|
|
timer: self
|
|
|
|
.timer
|
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
2020-03-16 11:32:57 +00:00
|
|
|
.unwrap_or_default(),
|
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-12 04:53:25 +00:00
|
|
|
if self.end || self.static_data.ability_info.input.is_none() {
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
} else {
|
2021-03-12 21:01:30 +00:00
|
|
|
reset_state(self, data, &mut update);
|
2021-03-12 04:53:25 +00:00
|
|
|
}
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
2021-03-12 04:53:25 +00:00
|
|
|
|
|
|
|
fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
update.removed_inputs.push(input);
|
|
|
|
|
|
|
|
if Some(input) == self.static_data.ability_info.input {
|
2021-03-12 21:01:30 +00:00
|
|
|
if let CharacterState::Boost(c) = &mut update.character {
|
|
|
|
c.end = true;
|
|
|
|
}
|
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) {
|
|
|
|
handle_input(join, update, data.static_data.ability_info.input.unwrap());
|
2020-03-16 11:32:57 +00:00
|
|
|
}
|