2020-01-21 22:54:32 +00:00
|
|
|
use super::utils::*;
|
2020-03-14 21:17:27 +00:00
|
|
|
use crate::{
|
2022-05-27 17:19:52 +00:00
|
|
|
comp::{
|
2023-01-16 05:34:19 +00:00
|
|
|
character_state::OutputEvents, controller::InputKind, inventory::item::armor::Friction,
|
|
|
|
CharacterState, InventoryAction, StateUpdate,
|
2022-05-27 17:19:52 +00:00
|
|
|
},
|
2023-01-28 17:14:36 +00:00
|
|
|
resources::Time,
|
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
|
|
|
|
2023-01-28 17:14:36 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
2021-10-05 00:15:58 +00:00
|
|
|
pub struct Data {
|
|
|
|
pub is_sneaking: bool,
|
2023-01-28 17:14:36 +00:00
|
|
|
pub(crate) time_entered: Time,
|
2022-05-27 17:19:52 +00:00
|
|
|
// None means unknown
|
|
|
|
pub(crate) footwear: Option<Friction>,
|
2021-10-05 00:15:58 +00:00
|
|
|
}
|
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
|
|
|
|
2023-03-26 23:50:42 +00:00
|
|
|
const LEAVE_STANCE_DELAY: f64 = 30.0;
|
2023-01-28 17:14:36 +00:00
|
|
|
if (self.time_entered.0 + LEAVE_STANCE_DELAY) < data.time.0 {
|
|
|
|
leave_stance(data, output_events);
|
|
|
|
}
|
|
|
|
|
2022-05-27 17:19:52 +00:00
|
|
|
handle_skating(data, &mut update);
|
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);
|
2023-01-16 05:34:19 +00:00
|
|
|
if input_is_pressed(data, InputKind::Roll) {
|
|
|
|
handle_input(data, output_events, &mut update, InputKind::Roll);
|
|
|
|
}
|
2020-03-14 21:17:27 +00:00
|
|
|
|
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())
|
|
|
|
{
|
2022-05-27 17:19:52 +00:00
|
|
|
update.character = CharacterState::Idle(Data {
|
|
|
|
is_sneaking: false,
|
2023-01-28 17:14:36 +00:00
|
|
|
time_entered: self.time_entered,
|
2022-05-27 17:19:52 +00:00
|
|
|
footwear: self.footwear,
|
|
|
|
});
|
2021-10-05 00:15:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-14 21:17:27 +00:00
|
|
|
update
|
|
|
|
}
|
2020-03-24 07:38:16 +00:00
|
|
|
|
2023-05-14 22:07:45 +00:00
|
|
|
fn swap_equipped_weapons(
|
|
|
|
&self,
|
|
|
|
data: &JoinData,
|
|
|
|
output_events: &mut OutputEvents,
|
|
|
|
) -> StateUpdate {
|
2020-03-24 07:38:16 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2023-05-14 22:07:45 +00:00
|
|
|
attempt_swap_equipped_weapons(data, &mut update, output_events);
|
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);
|
2022-05-27 17:19:52 +00:00
|
|
|
update.character = CharacterState::Idle(Data {
|
|
|
|
is_sneaking: true,
|
2023-01-28 17:14:36 +00:00
|
|
|
time_entered: self.time_entered,
|
2022-05-27 17:19:52 +00:00
|
|
|
footwear: self.footwear,
|
|
|
|
});
|
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);
|
2022-05-27 17:19:52 +00:00
|
|
|
update.character = CharacterState::Idle(Data::default());
|
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
|
|
|
}
|