veloren/common/src/states/idle.rs

108 lines
3.5 KiB
Rust
Raw Normal View History

use super::utils::*;
2020-03-14 21:17:27 +00:00
use crate::{
2022-05-27 17:19:52 +00:00
comp::{
character_state::OutputEvents, controller::InputKind, inventory::item::armor::Friction,
CharacterState, InventoryAction, StateUpdate,
2022-05-27 17:19:52 +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
2022-09-08 19:51:02 +00:00
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
2021-10-05 00:15:58 +00:00
pub struct Data {
pub is_sneaking: bool,
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 {
fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
2022-05-27 17:19:52 +00:00
handle_skating(data, &mut update);
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 });
handle_jump(data, output_events, &mut update, 1.0);
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);
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,
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
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
}
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);
handle_manipulate_loadout(data, output_events, &mut update, inv_action);
2020-03-24 07:38:16 +00:00
update
}
fn wield(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
2021-07-20 07:43:52 +00:00
attempt_wield(data, &mut update);
update
}
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);
attempt_glide_wield(data, &mut update, output_events);
2020-05-27 06:41:55 +00:00
update
}
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
}
fn dance(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
2021-07-20 07:43:52 +00:00
attempt_dance(data, &mut update);
update
}
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,
footwear: self.footwear,
});
2020-03-24 07:38:16 +00:00
update
}
2021-12-07 20:40:27 +00:00
fn stand(&self, data: &JoinData, _: &mut OutputEvents) -> StateUpdate {
let mut update = StateUpdate::from(data);
2022-05-27 17:19:52 +00:00
update.character = CharacterState::Idle(Data::default());
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
}