use super::utils::*;
use crate::{
comp::{character_state::OutputEvents, CharacterState, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
wielding,
},
};
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct StaticData {
pub buildup_duration: Duration,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Data {
pub static_data: StaticData,
pub timer: Duration,
pub is_sneaking: bool,
}
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0, None);
handle_move(data, &mut update, if self.is_sneaking { 0.4 } else { 1.0 });
handle_jump(data, output_events, &mut update, 1.0);
if self.timer < self.static_data.buildup_duration {
update.character = CharacterState::Equipping(Data {
timer: tick_attack_or_default(data, self.timer, None),
..*self
});
} else {
update.character = CharacterState::Wielding(wielding::Data {
is_sneaking: self.is_sneaking,
});
}
update
}
}