2020-08-08 20:53:55 +00:00
|
|
|
use crate::{
|
2020-08-08 22:22:21 +00:00
|
|
|
comp::{shockwave, Attacking, CharacterState, StateUpdate},
|
2020-08-08 20:53:55 +00:00
|
|
|
event::ServerEvent,
|
|
|
|
states::utils::*,
|
2020-09-30 00:47:11 +00:00
|
|
|
sys::character_behavior::{CharacterBehavior, JoinData},
|
2020-08-08 20:53:55 +00:00
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Data {
|
|
|
|
/// Whether the attack can deal more damage
|
|
|
|
pub exhausted: bool,
|
|
|
|
/// How long until state should deal damage
|
|
|
|
pub buildup_duration: Duration,
|
|
|
|
/// How long the state has until exiting
|
|
|
|
pub recover_duration: Duration,
|
|
|
|
/// Base damage
|
|
|
|
pub damage: u32,
|
|
|
|
/// Knockback
|
|
|
|
pub knockback: f32,
|
|
|
|
/// Angle of the shockwave
|
|
|
|
pub shockwave_angle: f32,
|
|
|
|
/// Speed of the shockwave
|
|
|
|
pub shockwave_speed: f32,
|
|
|
|
/// How long the shockwave travels for
|
|
|
|
pub shockwave_duration: Duration,
|
2020-09-19 16:55:31 +00:00
|
|
|
/// Whether the shockwave requires the target to be on the ground
|
|
|
|
pub requires_ground: bool,
|
2020-08-08 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CharacterBehavior for Data {
|
|
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
|
2020-08-09 23:11:58 +00:00
|
|
|
handle_move(data, &mut update, 0.05);
|
2020-08-08 20:53:55 +00:00
|
|
|
|
|
|
|
if self.buildup_duration != Duration::default() {
|
|
|
|
// Build up
|
|
|
|
update.character = CharacterState::GroundShockwave(Data {
|
2020-08-09 23:11:58 +00:00
|
|
|
exhausted: self.exhausted,
|
2020-08-08 20:53:55 +00:00
|
|
|
buildup_duration: self
|
|
|
|
.buildup_duration
|
|
|
|
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
recover_duration: self.recover_duration,
|
|
|
|
damage: self.damage,
|
|
|
|
knockback: self.knockback,
|
|
|
|
shockwave_angle: self.shockwave_angle,
|
|
|
|
shockwave_speed: self.shockwave_speed,
|
|
|
|
shockwave_duration: self.shockwave_duration,
|
2020-09-19 16:55:31 +00:00
|
|
|
requires_ground: self.requires_ground,
|
2020-08-08 20:53:55 +00:00
|
|
|
});
|
|
|
|
} else if !self.exhausted {
|
|
|
|
// Attack
|
2020-08-08 22:22:21 +00:00
|
|
|
let properties = shockwave::Properties {
|
|
|
|
angle: self.shockwave_angle,
|
|
|
|
speed: self.shockwave_speed,
|
|
|
|
duration: self.shockwave_duration,
|
2020-08-08 20:53:55 +00:00
|
|
|
damage: self.damage,
|
|
|
|
knockback: self.knockback,
|
2020-09-19 16:55:31 +00:00
|
|
|
requires_ground: self.requires_ground,
|
2020-08-08 20:53:55 +00:00
|
|
|
owner: Some(*data.uid),
|
|
|
|
};
|
|
|
|
update.server_events.push_front(ServerEvent::Shockwave {
|
2020-08-08 22:22:21 +00:00
|
|
|
properties,
|
|
|
|
pos: *data.pos,
|
|
|
|
ori: *data.ori,
|
2020-08-08 20:53:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
update.character = CharacterState::GroundShockwave(Data {
|
|
|
|
exhausted: true,
|
|
|
|
buildup_duration: self.buildup_duration,
|
|
|
|
recover_duration: self.recover_duration,
|
|
|
|
damage: self.damage,
|
|
|
|
knockback: self.knockback,
|
|
|
|
shockwave_angle: self.shockwave_angle,
|
|
|
|
shockwave_speed: self.shockwave_speed,
|
|
|
|
shockwave_duration: self.shockwave_duration,
|
2020-09-19 16:55:31 +00:00
|
|
|
requires_ground: self.requires_ground,
|
2020-08-08 20:53:55 +00:00
|
|
|
});
|
|
|
|
} else if self.recover_duration != Duration::default() {
|
|
|
|
// Recovery
|
|
|
|
update.character = CharacterState::GroundShockwave(Data {
|
2020-08-09 23:11:58 +00:00
|
|
|
exhausted: self.exhausted,
|
2020-08-08 20:53:55 +00:00
|
|
|
buildup_duration: self.buildup_duration,
|
|
|
|
recover_duration: self
|
|
|
|
.recover_duration
|
|
|
|
.checked_sub(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
damage: self.damage,
|
|
|
|
knockback: self.knockback,
|
|
|
|
shockwave_angle: self.shockwave_angle,
|
|
|
|
shockwave_speed: self.shockwave_speed,
|
|
|
|
shockwave_duration: self.shockwave_duration,
|
2020-09-19 16:55:31 +00:00
|
|
|
requires_ground: self.requires_ground,
|
2020-08-08 20:53:55 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Done
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
// Make sure attack component is removed
|
|
|
|
data.updater.remove::<Attacking>(data.entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
|
|
|
}
|