2020-01-21 22:54:32 +00:00
|
|
|
use super::utils::*;
|
2020-03-14 21:17:27 +00:00
|
|
|
use crate::{
|
2021-10-05 00:15:58 +00:00
|
|
|
comp::{character_state::OutputEvents, CharacterState, InventoryAction, StateUpdate},
|
2020-12-01 00:28:00 +00:00
|
|
|
states::behavior::{CharacterBehavior, JoinData},
|
2020-03-14 21:17:27 +00:00
|
|
|
};
|
2021-10-05 00:15:58 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2019-12-28 16:10:39 +00:00
|
|
|
|
2021-10-05 00:15:58 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Data {
|
|
|
|
pub is_sneaking: bool,
|
|
|
|
}
|
2019-12-28 16:10:39 +00:00
|
|
|
|
2020-03-14 21:17:27 +00:00
|
|
|
impl CharacterBehavior for Data {
|
2021-10-13 02:03:18 +00:00
|
|
|
fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
|
2020-03-21 21:16:26 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2020-03-15 13:34:17 +00:00
|
|
|
|
2021-08-29 23:23:34 +00:00
|
|
|
handle_orientation(data, &mut update, 1.0, None);
|
2021-10-05 00:15:58 +00:00
|
|
|
handle_move(data, &mut update, if self.is_sneaking { 0.4 } else { 1.0 });
|
2021-10-13 02:03:18 +00:00
|
|
|
handle_jump(data, output_events, &mut update, 1.0);
|
2020-06-12 16:07:38 +00:00
|
|
|
handle_wield(data, &mut update);
|
2020-03-14 21:17:27 +00:00
|
|
|
handle_climb(data, &mut update);
|
2022-02-03 09:01:23 +00:00
|
|
|
handle_wallrun(data, &mut update);
|
2020-03-14 21:17:27 +00:00
|
|
|
handle_dodge_input(data, &mut update);
|
|
|
|
|
2021-10-05 00:15:58 +00:00
|
|
|
// Try to Fall/Stand up/Move
|
|
|
|
if self.is_sneaking
|
|
|
|
&& (data.physics.on_ground.is_none() || data.physics.in_liquid().is_some())
|
|
|
|
{
|
|
|
|
update.character = CharacterState::Idle(Data { is_sneaking: false });
|
|
|
|
}
|
|
|
|
|
2020-03-14 21:17:27 +00:00
|
|
|
update
|
|
|
|
}
|
2020-03-24 07:38:16 +00:00
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn swap_equipped_weapons(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2020-03-24 07:38:16 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-07-20 07:43:52 +00:00
|
|
|
attempt_swap_equipped_weapons(data, &mut update);
|
2020-03-24 07:38:16 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn manipulate_loadout(
|
|
|
|
&self,
|
|
|
|
data: &JoinData,
|
|
|
|
output_events: &mut OutputEvents,
|
|
|
|
inv_action: InventoryAction,
|
|
|
|
) -> StateUpdate {
|
2020-03-24 07:38:16 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-10-13 02:03:18 +00:00
|
|
|
handle_manipulate_loadout(data, output_events, &mut update, inv_action);
|
2020-03-24 07:38:16 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn wield(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2021-01-31 20:29:50 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-07-20 07:43:52 +00:00
|
|
|
attempt_wield(data, &mut update);
|
2021-01-31 20:29:50 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2022-03-13 05:44:07 +00:00
|
|
|
fn glide_wield(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
|
2020-05-27 06:41:55 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2022-03-13 05:44:07 +00:00
|
|
|
attempt_glide_wield(data, &mut update, output_events);
|
2020-05-27 06:41:55 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn sit(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2020-08-02 05:09:11 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-07-20 07:43:52 +00:00
|
|
|
attempt_sit(data, &mut update);
|
2020-08-02 05:09:11 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn dance(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2020-06-16 21:32:39 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-07-20 07:43:52 +00:00
|
|
|
attempt_dance(data, &mut update);
|
2020-06-16 21:32:39 +00:00
|
|
|
update
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:03:18 +00:00
|
|
|
fn sneak(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2020-03-24 07:38:16 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-10-05 00:15:58 +00:00
|
|
|
update.character = CharacterState::Idle(Data { is_sneaking: true });
|
2020-03-24 07:38:16 +00:00
|
|
|
update
|
|
|
|
}
|
2021-02-07 02:15:29 +00:00
|
|
|
|
2021-12-07 20:40:27 +00:00
|
|
|
fn stand(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2021-02-07 02:15:29 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-12-07 20:40:27 +00:00
|
|
|
update.character = CharacterState::Idle(Data { is_sneaking: false });
|
2021-02-07 02:15:29 +00:00
|
|
|
update
|
|
|
|
}
|
2021-10-05 00:15:58 +00:00
|
|
|
|
2021-12-07 20:40:27 +00:00
|
|
|
fn talk(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
|
2021-10-05 00:15:58 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-12-07 20:40:27 +00:00
|
|
|
attempt_talk(data, &mut update);
|
2021-10-05 00:15:58 +00:00
|
|
|
update
|
|
|
|
}
|
2019-12-28 16:10:39 +00:00
|
|
|
}
|