From c99e4c3c18579653d528c887e3e54e87d160e72e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 11 Sep 2020 14:56:04 -0500 Subject: [PATCH] Added swing duration to dash melee. Added framework for animation to be added. --- common/src/comp/ability.rs | 7 ++++-- common/src/comp/inventory/item/tool.rs | 1 + common/src/states/dash_melee.rs | 23 +++++++++++++++++ voxygen/src/anim/src/character/dash.rs | 26 +++++++++++++++++--- voxygen/src/scene/figure/mod.rs | 34 +++++++++++++++++++++++--- 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 468330df13..f56c8671a0 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -82,8 +82,9 @@ pub enum CharacterAbility { forward_speed: f32, buildup_duration: Duration, charge_duration: Duration, - infinite_charge: bool, + swing_duration: Duration, recover_duration: Duration, + infinite_charge: bool, }, BasicBlock, Roll, @@ -330,8 +331,9 @@ impl From<&CharacterAbility> for CharacterState { forward_speed, buildup_duration, charge_duration, - infinite_charge, + swing_duration, recover_duration, + infinite_charge, } => CharacterState::DashMelee(dash_melee::Data { static_data: dash_melee::StaticData { base_damage: *base_damage, @@ -345,6 +347,7 @@ impl From<&CharacterAbility> for CharacterState { infinite_charge: *infinite_charge, buildup_duration: *buildup_duration, charge_duration: *charge_duration, + swing_duration: *swing_duration, recover_duration: *recover_duration, }, end_charge: false, diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index ab3eec1333..84054fe2d2 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -177,6 +177,7 @@ impl Tool { forward_speed: 4.0, buildup_duration: Duration::from_millis(200), charge_duration: Duration::from_millis(400), + swing_duration: Duration::from_millis(100), recover_duration: Duration::from_millis(750), infinite_charge: true, }, diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 5f26f25f5c..2eb462652c 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -31,6 +31,8 @@ pub struct StaticData { pub buildup_duration: Duration, /// How long the state charges for until it reaches max damage pub charge_duration: Duration, + /// Suration of state spent in swing + pub swing_duration: Duration, /// How long the state has until exiting pub recover_duration: Duration, } @@ -174,6 +176,27 @@ impl CharacterBehavior for Data { ); } else if self.stage_section == StageSection::Charge { // Transitions to swing section of stage + update.character = CharacterState::DashMelee(Data { + static_data: self.static_data, + end_charge: self.end_charge, + timer: Duration::default(), + stage_section: StageSection::Swing, + exhausted: self.exhausted, + }) + } else if self.stage_section == StageSection::Swing && self.timer < self.static_data.swing_duration { + // Swings + update.character = CharacterState::DashMelee(Data { + static_data: self.static_data, + end_charge: self.end_charge, + timer: self + .timer + .checked_add(Duration::from_secs_f32(data.dt.0)) + .unwrap_or_default(), + stage_section: self.stage_section, + exhausted: self.exhausted, + }) + } else if self.stage_section == StageSection::Swing { + // Transitions to recover section of stage update.character = CharacterState::DashMelee(Data { static_data: self.static_data, end_charge: self.end_charge, diff --git a/voxygen/src/anim/src/character/dash.rs b/voxygen/src/anim/src/character/dash.rs index 8e1cf865c3..1af9ec84c7 100644 --- a/voxygen/src/anim/src/character/dash.rs +++ b/voxygen/src/anim/src/character/dash.rs @@ -2,7 +2,10 @@ use super::{ super::{vek::*, Animation}, CharacterSkeleton, SkeletonAttr, }; -use common::comp::item::{Hands, ToolKind}; +use common::{ + comp::item::{Hands, ToolKind}, + states::utils::StageSection, +}; pub struct Input { pub attack: bool, @@ -10,7 +13,7 @@ pub struct Input { pub struct DashAnimation; impl Animation for DashAnimation { - type Dependency = (Option, Option, f64); + type Dependency = (Option, Option, f64, Option); type Skeleton = CharacterSkeleton; #[cfg(feature = "use-dyn-lib")] @@ -20,7 +23,7 @@ impl Animation for DashAnimation { #[allow(clippy::single_match)] // TODO: Pending review in #587 fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, _global_time): Self::Dependency, + (active_tool_kind, second_tool_kind, _global_time, stage_section): Self::Dependency, anim_time: f64, rate: &mut f32, skeleton_attr: &SkeletonAttr, @@ -42,6 +45,23 @@ impl Animation for DashAnimation { match active_tool_kind { //TODO: Inventory Some(ToolKind::Sword(_)) => { + if let Some(stage_section) = stage_section { + match stage_section { + StageSection::Buildup => { + + }, + StageSection::Charge => { + + }, + StageSection::Swing => { + + }, + StageSection::Recover => { + + } + } + } + next.head.position = Vec3::new( 0.0, -2.0 + skeleton_attr.head.0, diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 1264b7b390..fa34a685ed 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -897,11 +897,39 @@ impl FigureMgr { skeleton_attr, ) }, - CharacterState::DashMelee(_) => { + CharacterState::DashMelee(s) => { + let stage_time = s.timer.as_secs_f64(); + let stage_progress = match s.stage_section { + StageSection::Buildup => { + stage_time + / s.static_data + .buildup_duration + .as_secs_f64() + }, + StageSection::Charge => { + stage_time + / s.static_data + .charge_duration + .as_secs_f64() + }, + StageSection::Swing => { + stage_time + / s.static_data + .swing_duration + .as_secs_f64() + }, + StageSection::Recover => { + stage_time + / s.static_data + .recover_duration + .as_secs_f64() + }, + _ => 0.0, + }; anim::character::DashAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, time), - state.state_time, + (active_tool_kind, second_tool_kind, time, Some(s.stage_section)), + stage_progress, &mut state_animation_rate, skeleton_attr, )