diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 0a2d340a44..a12e737ead 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -38,20 +38,20 @@ pub struct StateUpdate { #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub enum MoveState { - Stand(Option<StandState>), - Run(Option<RunState>), - Sit(Option<SitState>), - Jump(Option<JumpState>), - Fall(Option<FallState>), - Glide(Option<GlideState>), - Swim(Option<SwimState>), - Climb(Option<ClimbState>), + Stand(Option<stand::State>), + Run(Option<run::State>), + Sit(Option<sit::State>), + Jump(Option<jump::State>), + Fall(Option<fall::State>), + Glide(Option<glide::State>), + Swim(Option<swim::State>), + Climb(Option<climb::State>), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub enum ActionState { - Idle(Option<IdleState>), - Wield(Option<WieldState>), + Idle(Option<idle::State>), + Wield(Option<wield::State>), Attack(AttackKind), Block(BlockKind), Dodge(DodgeKind), @@ -60,24 +60,24 @@ pub enum ActionState { #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub enum AttackKind { - BasicAttack(Option<BasicAttackState>), - Charge(Option<ChargeAttackState>), + BasicAttack(Option<basic_attack::State>), + Charge(Option<charge_attack::State>), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub enum BlockKind { - BasicBlock(Option<BasicBlockState>), + BasicBlock(Option<basic_block::State>), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub enum DodgeKind { - Roll(Option<RollState>), + Roll(Option<roll::State>), } impl ActionState { pub fn is_equip_finished(&self) -> bool { match self { - Wield(Some(WieldState { equip_delay })) => *equip_delay == Duration::default(), + Wield(Some(wield::State { equip_delay })) => *equip_delay == Duration::default(), _ => true, } } @@ -85,7 +85,7 @@ impl ActionState { /// Returns the current `equip_delay` if in `WieldState`, otherwise `Duration::default()` pub fn get_delay(&self) -> Duration { match self { - Wield(Some(WieldState { equip_delay })) => *equip_delay, + Wield(Some(wield::State { equip_delay })) => *equip_delay, _ => Duration::default(), } } @@ -164,8 +164,8 @@ impl CharacterState { impl Default for CharacterState { fn default() -> Self { Self { - move_state: MoveState::Fall(Some(FallState)), - action_state: ActionState::Idle(Some(IdleState)), + move_state: MoveState::Fall(None), + action_state: ActionState::Idle(None), } } } diff --git a/common/src/comp/states/basic_attack.rs b/common/src/comp/states/basic_attack.rs index 725e8acc93..95b45ae968 100644 --- a/common/src/comp/states/basic_attack.rs +++ b/common/src/comp/states/basic_attack.rs @@ -6,12 +6,12 @@ use crate::util::state_utils::*; use std::time::Duration; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct BasicAttackState { +pub struct State { /// How long the state has until exitting pub remaining_duration: Duration, } -impl StateHandler for BasicAttackState { +impl StateHandler for State { fn new(ecs_data: &EcsStateData) -> Self { let tool_data = if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) { @@ -40,7 +40,7 @@ impl StateHandler for BasicAttackState { } // Otherwise, tick down remaining_duration, and keep rolling - update.character.action_state = Attack(BasicAttack(Some(BasicAttackState { + update.character.action_state = Attack(BasicAttack(Some(State { remaining_duration: self .remaining_duration .checked_sub(Duration::from_secs_f32(ecs_data.dt.0)) diff --git a/common/src/comp/states/basic_block.rs b/common/src/comp/states/basic_block.rs index 053c837015..cc59682bd9 100644 --- a/common/src/comp/states/basic_block.rs +++ b/common/src/comp/states/basic_block.rs @@ -7,12 +7,12 @@ const BLOCK_ACCEL: f32 = 30.0; const BLOCK_SPEED: f32 = 75.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct BasicBlockState { +pub struct State { /// How long the blocking state has been active pub active_duration: Duration, } -impl StateHandler for BasicBlockState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self { active_duration: Duration::default(), diff --git a/common/src/comp/states/charge_attack.rs b/common/src/comp/states/charge_attack.rs index ea4420f3f9..040ae971d7 100644 --- a/common/src/comp/states/charge_attack.rs +++ b/common/src/comp/states/charge_attack.rs @@ -10,12 +10,12 @@ use vek::Vec3; const CHARGE_SPEED: f32 = 20.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct ChargeAttackState { +pub struct State { /// How long the state has until exitting pub remaining_duration: Duration, } -impl StateHandler for ChargeAttackState { +impl StateHandler for State { fn new(ecs_data: &EcsStateData) -> Self { let tool_data = if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) { @@ -76,7 +76,7 @@ impl StateHandler for ChargeAttackState { } // Tick remaining-duration and keep charging - update.character.action_state = Attack(Charge(Some(ChargeAttackState { + update.character.action_state = Attack(Charge(Some(State { remaining_duration: self .remaining_duration .checked_sub(Duration::from_secs_f32(ecs_data.dt.0)) diff --git a/common/src/comp/states/climb.rs b/common/src/comp/states/climb.rs index 9b1df0a52a..d5f6801433 100644 --- a/common/src/comp/states/climb.rs +++ b/common/src/comp/states/climb.rs @@ -7,9 +7,9 @@ const HUMANOID_CLIMB_ACCEL: f32 = 5.0; const CLIMB_SPEED: f32 = 5.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct ClimbState; +pub struct State; -impl StateHandler for ClimbState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/fall.rs b/common/src/comp/states/fall.rs index 55c72c3e97..8882b948c0 100644 --- a/common/src/comp/states/fall.rs +++ b/common/src/comp/states/fall.rs @@ -7,9 +7,9 @@ const HUMANOID_AIR_ACCEL: f32 = 10.0; const HUMANOID_AIR_SPEED: f32 = 100.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct FallState; +pub struct State; -impl StateHandler for FallState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/glide.rs b/common/src/comp/states/glide.rs index 4060b6c4f4..47c2ecb7b5 100644 --- a/common/src/comp/states/glide.rs +++ b/common/src/comp/states/glide.rs @@ -7,9 +7,9 @@ const GLIDE_ACCEL: f32 = 15.0; const GLIDE_SPEED: f32 = 45.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct GlideState; +pub struct State; -impl StateHandler for GlideState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/idle.rs b/common/src/comp/states/idle.rs index 2cfa12ad91..3498d912bf 100644 --- a/common/src/comp/states/idle.rs +++ b/common/src/comp/states/idle.rs @@ -1,9 +1,9 @@ use crate::comp::{ActionState::Wield, EcsStateData, ItemKind::Tool, StateHandler, StateUpdate}; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct IdleState; +pub struct State; -impl StateHandler for IdleState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/jump.rs b/common/src/comp/states/jump.rs index 16bf65b534..3cb2a5aacd 100644 --- a/common/src/comp/states/jump.rs +++ b/common/src/comp/states/jump.rs @@ -2,9 +2,9 @@ use super::{EcsStateData, MoveState::*, StateHandler, StateUpdate}; use crate::event::LocalEvent; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct JumpState; +pub struct State; -impl StateHandler for JumpState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/mod.rs b/common/src/comp/states/mod.rs index 2d29505272..b064026210 100644 --- a/common/src/comp/states/mod.rs +++ b/common/src/comp/states/mod.rs @@ -1,34 +1,18 @@ // Module declarations -mod basic_attack; -mod basic_block; -mod charge_attack; -mod climb; -mod fall; -mod glide; -mod idle; -mod jump; -mod roll; -mod run; -mod sit; -mod stand; -mod swim; -mod wield; - -// Reexports -pub use basic_attack::*; -pub use basic_block::*; -pub use charge_attack::*; -pub use climb::*; -pub use fall::*; -pub use glide::*; -pub use idle::*; -pub use jump::*; -pub use roll::*; -pub use run::*; -pub use sit::*; -pub use stand::*; -pub use swim::*; -pub use wield::*; +pub mod basic_attack; +pub mod basic_block; +pub mod charge_attack; +pub mod climb; +pub mod fall; +pub mod glide; +pub mod idle; +pub mod jump; +pub mod roll; +pub mod run; +pub mod sit; +pub mod stand; +pub mod swim; +pub mod wield; use super::{ ActionState, ActionState::*, AttackKind::*, BlockKind::*, DodgeKind::*, EcsStateData, @@ -112,28 +96,28 @@ impl ActionState { Attack(kind) => match kind { BasicAttack(opt_state) => opt_state // If data hasn't been initialized, initialize a new one - .unwrap_or_else(|| BasicAttackState::new(ecs_data)) + .unwrap_or_else(|| basic_attack::State::new(ecs_data)) // Call handler .handle(ecs_data), Charge(opt_state) => opt_state - .unwrap_or_else(|| ChargeAttackState::new(ecs_data)) + .unwrap_or_else(|| charge_attack::State::new(ecs_data)) .handle(ecs_data), }, Block(kind) => match kind { BasicBlock(opt_state) => opt_state - .unwrap_or_else(|| BasicBlockState::new(ecs_data)) + .unwrap_or_else(|| basic_block::State::new(ecs_data)) .handle(ecs_data), }, Dodge(kind) => match kind { Roll(opt_state) => opt_state - .unwrap_or_else(|| RollState::new(ecs_data)) + .unwrap_or_else(|| roll::State::new(ecs_data)) .handle(ecs_data), }, Wield(opt_state) => opt_state - .unwrap_or_else(|| WieldState::new(ecs_data)) + .unwrap_or_else(|| wield::State::new(ecs_data)) .handle(ecs_data), Idle(opt_state) => opt_state - .unwrap_or_else(|| IdleState::new(ecs_data)) + .unwrap_or_else(|| idle::State::new(ecs_data)) .handle(ecs_data), // All states should be explicitly handled // Do not use default match: _ => {}, @@ -188,29 +172,29 @@ impl MoveState { match self { Stand(opt_state) => opt_state // If data hasn't been initialized, initialize a new one - .unwrap_or_else(|| StandState::new(ecs_data)) + .unwrap_or_else(|| stand::State::new(ecs_data)) // Call handler .handle(ecs_data), Run(opt_state) => opt_state - .unwrap_or_else(|| RunState::new(ecs_data)) + .unwrap_or_else(|| run::State::new(ecs_data)) .handle(ecs_data), Jump(opt_state) => opt_state - .unwrap_or_else(|| JumpState::new(ecs_data)) + .unwrap_or_else(|| jump::State::new(ecs_data)) .handle(ecs_data), Climb(opt_state) => opt_state - .unwrap_or_else(|| ClimbState::new(ecs_data)) + .unwrap_or_else(|| climb::State::new(ecs_data)) .handle(ecs_data), Glide(opt_state) => opt_state - .unwrap_or_else(|| GlideState::new(ecs_data)) + .unwrap_or_else(|| glide::State::new(ecs_data)) .handle(ecs_data), Swim(opt_state) => opt_state - .unwrap_or_else(|| SwimState::new(ecs_data)) + .unwrap_or_else(|| swim::State::new(ecs_data)) .handle(ecs_data), Fall(opt_state) => opt_state - .unwrap_or_else(|| FallState::new(ecs_data)) + .unwrap_or_else(|| fall::State::new(ecs_data)) .handle(ecs_data), Sit(opt_state) => opt_state - .unwrap_or_else(|| SitState::new(ecs_data)) + .unwrap_or_else(|| sit::State::new(ecs_data)) .handle(ecs_data), // All states should be explicitly handled // Do not use default match: _ => {}, diff --git a/common/src/comp/states/roll.rs b/common/src/comp/states/roll.rs index 63e1e29c78..3947a0e565 100644 --- a/common/src/comp/states/roll.rs +++ b/common/src/comp/states/roll.rs @@ -8,12 +8,12 @@ use vek::Vec3; const ROLL_SPEED: f32 = 17.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct RollState { +pub struct State { /// How long the state has until exitting remaining_duration: Duration, } -impl StateHandler for RollState { +impl StateHandler for State { fn new(ecs_data: &EcsStateData) -> Self { let tool_data = if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) { @@ -55,7 +55,7 @@ impl StateHandler for RollState { } // Otherwise, tick down remaining_duration - update.character.action_state = Dodge(Roll(Some(RollState { + update.character.action_state = Dodge(Roll(Some(State { remaining_duration: self .remaining_duration .checked_sub(Duration::from_secs_f32(ecs_data.dt.0)) diff --git a/common/src/comp/states/run.rs b/common/src/comp/states/run.rs index 598eb5dbb7..a2ca009956 100644 --- a/common/src/comp/states/run.rs +++ b/common/src/comp/states/run.rs @@ -6,9 +6,9 @@ const HUMANOID_ACCEL: f32 = 50.0; const HUMANOID_SPEED: f32 = 120.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct RunState; +pub struct State; -impl StateHandler for RunState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/sit.rs b/common/src/comp/states/sit.rs index 2e47c8d4f5..032cc4a27d 100644 --- a/common/src/comp/states/sit.rs +++ b/common/src/comp/states/sit.rs @@ -2,9 +2,9 @@ use crate::comp::{ActionState::*, EcsStateData, MoveState::*, StateHandler, Stat use crate::util::state_utils::*; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct SitState; +pub struct State; -impl StateHandler for SitState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/stand.rs b/common/src/comp/states/stand.rs index b3372c8721..9536cc7a61 100644 --- a/common/src/comp/states/stand.rs +++ b/common/src/comp/states/stand.rs @@ -2,9 +2,9 @@ use crate::comp::{EcsStateData, MoveState::*, StateHandler, StateUpdate}; use crate::util::state_utils::*; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct StandState; +pub struct State; -impl StateHandler for StandState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/swim.rs b/common/src/comp/states/swim.rs index 1d739a7aec..8ccecc2b70 100644 --- a/common/src/comp/states/swim.rs +++ b/common/src/comp/states/swim.rs @@ -4,12 +4,12 @@ use std::time::Duration; use vek::{Vec2, Vec3}; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct SwimState; +pub struct State; const HUMANOID_WATER_ACCEL: f32 = 70.0; const HUMANOID_WATER_SPEED: f32 = 120.0; -impl StateHandler for SwimState { +impl StateHandler for State { fn new(_ecs_data: &EcsStateData) -> Self { Self {} } diff --git a/common/src/comp/states/wield.rs b/common/src/comp/states/wield.rs index 06f55afb1c..bcf9e0d582 100644 --- a/common/src/comp/states/wield.rs +++ b/common/src/comp/states/wield.rs @@ -1,16 +1,16 @@ use crate::comp::{ - ActionState::*, EcsStateData, IdleState, ItemKind::Tool, StateHandler, StateUpdate, ToolData, + ActionState::*, EcsStateData, ItemKind::Tool, StateHandler, StateUpdate, ToolData, }; use std::time::Duration; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct WieldState { +pub struct State { /// How long before a new action can be performed /// after equipping pub equip_delay: Duration, } -impl StateHandler for WieldState { +impl StateHandler for State { fn new(ecs_data: &EcsStateData) -> Self { let tool_data = if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) { @@ -37,7 +37,7 @@ impl StateHandler for WieldState { if ecs_data.inputs.toggle_wield.is_just_pressed() && ecs_data.character.action_state.is_equip_finished() { - update.character.action_state = Idle(Some(IdleState)); + update.character.action_state = Idle(None); return update; } @@ -54,7 +54,7 @@ impl StateHandler for WieldState { } else { // Equip delay hasn't expired yet // Update wield delay - update.character.action_state = Wield(Some(WieldState { + update.character.action_state = Wield(Some(State { equip_delay: self .equip_delay .checked_sub(Duration::from_secs_f32(ecs_data.dt.0)) diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 23c850b490..c1118c0ce4 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -1,6 +1,5 @@ use crate::comp::{ - Agent, CharacterState, Controller, ControllerInputs, GlideState, MountState, MoveState::Glide, - Pos, Stats, + Agent, CharacterState, Controller, ControllerInputs, MountState, MoveState::Glide, Pos, Stats, }; use crate::pathfinding::WorldPath; use crate::terrain::TerrainGrid; @@ -163,7 +162,7 @@ impl<'a> System<'a> for Sys { inputs.roll.set_state(true); } - if target_character.move_state == Glide(Some(GlideState)) + if target_character.move_state == Glide(None) && target_pos.0.z > pos.0.z + 5.0 { inputs.glide.set_state(true);