From 2fa902270ea4ce97ff7db3117b65fcf5a5119e9b Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 24 Feb 2020 15:35:07 +0100 Subject: [PATCH] fix: block --- common/src/comp/ability.rs | 6 ++--- common/src/comp/character_state.rs | 12 +++++----- common/src/states/basic_block.rs | 36 ++++++++---------------------- common/src/states/mod.rs | 1 + common/src/states/utils.rs | 10 +++++++++ common/src/states/wielded.rs | 10 +++++---- voxygen/src/scene/figure/cache.rs | 6 ++--- voxygen/src/scene/figure/mod.rs | 7 +++--- voxygen/src/session.rs | 14 +----------- 9 files changed, 42 insertions(+), 60 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index f944b05b8d..39be87db17 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -10,9 +10,7 @@ pub enum AbilityActionKind { // UpdatePool? } impl Default for AbilityActionKind { - fn default() -> Self { - Self::Primary - } + fn default() -> Self { Self::Primary } } #[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct AbilityAction(pub AbilityActionKind); @@ -33,7 +31,7 @@ impl Default for AbilityPool { fn default() -> Self { Self { primary: Some(comp::CharacterState::BasicAttack(None)), - secondary: None, + secondary: Some(comp::CharacterState::BasicBlock(None)), block: None, dodge: Some(comp::CharacterState::Roll(None)), } diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 417e49b042..6cd5178a20 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -43,7 +43,7 @@ pub enum CharacterState { Wielded(Option), Glide(Option), BasicAttack(Option), - //BasicBlock(Option), + BasicBlock(Option), //Charge(Option), Roll(Option), } @@ -58,7 +58,7 @@ impl CharacterState { pub fn is_block(&self) -> bool { match self { - //CharacterState::BasicBlock(_) => true, + CharacterState::BasicBlock(_) => true, _ => false, } } @@ -102,12 +102,12 @@ impl CharacterState { CharacterState::BasicAttack(opt_state) => opt_state .unwrap_or_else(|| basic_attack::State::new(ecs_data)) .handle(ecs_data), - /*CharacterState::Charge(opt_state) => opt_state - .unwrap_or_else(|| charge_attack::State::new(ecs_data)) - .handle(ecs_data), CharacterState::BasicBlock(opt_state) => opt_state .unwrap_or_else(|| basic_block::State::new(ecs_data)) - .handle(ecs_data),*/ + .handle(ecs_data), + /*CharacterState::Charge(opt_state) => opt_state + .unwrap_or_else(|| charge_attack::State::new(ecs_data)) + .handle(ecs_data),*/ CharacterState::Roll(opt_state) => opt_state .unwrap_or_else(|| roll::State::new(ecs_data)) .handle(ecs_data), diff --git a/common/src/states/basic_block.rs b/common/src/states/basic_block.rs index 4952691d72..e3ee63f18f 100644 --- a/common/src/states/basic_block.rs +++ b/common/src/states/basic_block.rs @@ -1,24 +1,19 @@ use super::utils::*; -use crate::comp::{EcsStateData, StateUpdate}; -use crate::states::StateHandler; -use std::time::Duration; +use crate::{ + comp::{EcsStateData, StateUpdate}, + states::StateHandler, +}; +use std::{collections::VecDeque, time::Duration}; use vek::Vec2; const BLOCK_ACCEL: f32 = 30.0; const BLOCK_SPEED: f32 = 75.0; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct State { - /// How long the blocking state has been active - pub active_duration: Duration, -} +pub struct State {} impl StateHandler for State { - fn new(_ecs_data: &EcsStateData) -> Self { - Self { - active_duration: Duration::default(), - } - } + fn new(_ecs_data: &EcsStateData) -> Self { Self {} } fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate { let mut update = StateUpdate { @@ -26,23 +21,10 @@ impl StateHandler for State { vel: *ecs_data.vel, ori: *ecs_data.ori, character: *ecs_data.character, + local_events: VecDeque::new(), + server_events: VecDeque::new(), }; - // TODO: Apply simple move speed debuff instead - - // Update movement - update.vel.0 += Vec2::broadcast(ecs_data.dt.0) - * ecs_data.inputs.move_dir - * match ecs_data.physics.on_ground { - true if update.vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL, - _ => 0.0, - }; - - if !ecs_data.inputs.secondary.is_pressed() { - update.character.action_state = attempt_wield(ecs_data.stats); - return update; - } - update } } diff --git a/common/src/states/mod.rs b/common/src/states/mod.rs index e917b855b1..016362d5be 100644 --- a/common/src/states/mod.rs +++ b/common/src/states/mod.rs @@ -1,5 +1,6 @@ // Module declarations pub mod basic_attack; +pub mod basic_block; pub mod climb; pub mod glide; pub mod idle; diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index d430afdec8..5527365e20 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -105,6 +105,16 @@ pub fn handle_primary(ecs_data: &EcsStateData, update: &mut StateUpdate) { } } +pub fn handle_secondary(ecs_data: &EcsStateData, update: &mut StateUpdate) { + if let Some(state) = ecs_data.ability_pool.secondary { + if let CharacterState::Wielded(_) = update.character { + if ecs_data.inputs.secondary.is_pressed() { + update.character = state; + } + } + } +} + pub fn handle_dodge(ecs_data: &EcsStateData, update: &mut StateUpdate) { if let Some(state) = ecs_data.ability_pool.dodge { if let CharacterState::Idle(_) | CharacterState::Wielded(_) = update.character { diff --git a/common/src/states/wielded.rs b/common/src/states/wielded.rs index e70b0c0c34..73d09ca2ec 100644 --- a/common/src/states/wielded.rs +++ b/common/src/states/wielded.rs @@ -1,8 +1,9 @@ use super::utils::*; -use crate::comp::{EcsStateData, ItemKind::Tool, StateUpdate, ToolData}; -use crate::states::StateHandler; -use std::collections::VecDeque; -use std::time::Duration; +use crate::{ + comp::{EcsStateData, ItemKind::Tool, StateUpdate, ToolData}, + states::StateHandler, +}; +use std::{collections::VecDeque, time::Duration}; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct State { @@ -41,6 +42,7 @@ impl StateHandler for State { handle_glide(&ecs_data, &mut update); handle_unwield(&ecs_data, &mut update); handle_primary(&ecs_data, &mut update); + handle_secondary(&ecs_data, &mut update); handle_dodge(&ecs_data, &mut update); update diff --git a/voxygen/src/scene/figure/cache.rs b/voxygen/src/scene/figure/cache.rs index 9c06759809..3290c3fc23 100644 --- a/voxygen/src/scene/figure/cache.rs +++ b/voxygen/src/scene/figure/cache.rs @@ -170,9 +170,9 @@ impl FigureModelCache { if camera_mode != CameraMode::FirstPerson || character_state .map(|cs| match cs { - //CharacterState::BasicAttack(_) // TODO: enable - //| CharacterState::BasicBlock(_) - CharacterState::Wielding(_) + CharacterState::BasicAttack(_) + | CharacterState::BasicBlock(_) + | CharacterState::Wielding(_) | CharacterState::Wielded(_) => true, _ => false, }) diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 22cc8322af..4313677564 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -457,15 +457,16 @@ impl FigureMgr { skeleton_attr, ) }, - /*CharacterState::Block(_) => { + CharacterState::BasicBlock(_) => { anim::character::BlockIdleAnimation::update_skeleton( - &target_base, + &CharacterSkeleton::new(), (active_tool_kind, time), state.state_time, &mut state_animation_rate, skeleton_attr, ) - } + }, + /* CharacterState::Charge(_) => { anim::character::ChargeAnimation::update_skeleton( &target_base, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 353f64f873..508b8cbe6a 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -220,20 +220,8 @@ impl PlayState for SessionState { if let Some(select_pos) = select_pos { client.remove_block(select_pos); } - } else if client - .state() - .read_storage::() - .get(client.entity()) - .map(|cs| match cs { - /*ActionState::Attack(_) // TODO: uncomment - | ActionState::Block(_) - | ActionState::Wield(_) => true,*/ - _ => false, - }) - .unwrap_or(false) - { - self.inputs.secondary.set_state(state); } else { + self.inputs.secondary.set_state(state); if let Some(select_pos) = select_pos { client.collect_block(select_pos); }