1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use super::utils::*;
use crate::{
    comp::{character_state::OutputEvents, CharacterState, StateUpdate},
    states::{
        behavior::{CharacterBehavior, JoinData},
        idle, wielding,
    },
};
use serde::{Deserialize, Serialize};
use vek::Vec2;

const WALLRUN_ANTIGRAV: f32 = crate::consts::GRAVITY * 0.5;

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct Data {
    /// Had weapon
    pub was_wielded: bool,
}

impl CharacterBehavior for Data {
    fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
        let mut update = StateUpdate::from(data);

        handle_wield(data, &mut update);
        handle_jump(data, output_events, &mut update, 1.0);
        handle_climb(data, &mut update);

        {
            let lift = WALLRUN_ANTIGRAV;
            update.vel.0.z += data.dt.0
                * lift
                * (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075).clamp(0.2, 1.0);
        }

        // fall off wall, hit ground, or enter water
        // TODO: Rugged way to determine when state change occurs and we need to leave
        // this state
        if data.physics.on_wall.is_none()
            || data.physics.on_ground.is_some()
            || data.physics.in_liquid().is_some()
        {
            update.character = if self.was_wielded {
                CharacterState::Wielding(wielding::Data { is_sneaking: false })
            } else {
                CharacterState::Idle(idle::Data::default())
            };
        }

        update
    }
}