use super::utils::*;
use crate::{
comp::{character_state::OutputEvents, CharacterState, PoiseState, StateUpdate},
states::behavior::{CharacterBehavior, JoinData},
};
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct StaticData {
pub buildup_duration: Duration,
pub recover_duration: Duration,
pub movement_speed: f32,
pub ori_rate: f32,
pub poise_state: PoiseState,
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
pub static_data: StaticData,
pub timer: Duration,
pub stage_section: StageSection,
pub was_wielded: bool,
}
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
if matches!(
self.static_data.poise_state,
PoiseState::Dazed | PoiseState::KnockedDown
) {
leave_stance(data, output_events);
}
handle_orientation(data, &mut update, self.static_data.ori_rate, None);
handle_move(data, &mut update, self.static_data.movement_speed);
match self.stage_section {
StageSection::Buildup => {
if self.timer < self.static_data.buildup_duration {
update.character = CharacterState::Stunned(Data {
timer: tick_attack_or_default(data, self.timer, None),
..*self
});
} else {
update.character = CharacterState::Stunned(Data {
timer: Duration::default(),
stage_section: StageSection::Recover,
..*self
});
}
},
StageSection::Recover => {
if self.timer < self.static_data.recover_duration {
update.character = CharacterState::Stunned(Data {
timer: tick_attack_or_default(
data,
self.timer,
Some(data.stats.recovery_speed_modifier),
),
..*self
});
} else {
end_ability(data, &mut update);
}
},
_ => {
end_ability(data, &mut update);
},
}
update
}
}