diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 096092a8fb..35842f23d9 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -341,7 +341,7 @@ impl From<&CharacterAbility> for CharacterState { energy_increase: *energy_increase, combo_duration: *combo_duration, timer: Duration::default(), - stage_section: combo_melee::StageSection::Buildup, + stage_section: wielding::StageSection::Buildup, }), CharacterAbility::LeapMelee { energy_cost: _, diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 084f8bd33c..183d8f6b39 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -128,8 +128,8 @@ impl Tool { range: 3.5, angle: 45.0, base_buildup_duration: Duration::from_millis(10), + base_swing_duration: Duration::from_millis(10), base_recover_duration: Duration::from_millis(10), - swing_frac: 0.5, }, combo_melee::Stage { stage: 2, @@ -139,9 +139,9 @@ impl Tool { knockback: 5.0, range: 3.5, angle: 45.0, - base_buildup_duration: Duration::from_millis(1000), + base_buildup_duration: Duration::from_millis(400), + base_swing_duration: Duration::from_millis(600), base_recover_duration: Duration::from_millis(400), - swing_frac: 0.6, }, combo_melee::Stage { stage: 3, @@ -152,8 +152,8 @@ impl Tool { range: 3.5, angle: 45.0, base_buildup_duration: Duration::from_millis(10), + base_swing_duration: Duration::from_millis(10), base_recover_duration: Duration::from_millis(10), - swing_frac: 0.5, }, ], initial_energy_gain: 0, @@ -180,8 +180,8 @@ impl Tool { range: 3.5, angle: 45.0, base_buildup_duration: Duration::from_millis(150), + base_swing_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100), - swing_frac: 0.5, }, combo_melee::Stage { stage: 2, @@ -192,8 +192,8 @@ impl Tool { range: 3.5, angle: 45.0, base_buildup_duration: Duration::from_millis(150), + base_swing_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100), - swing_frac: 0.6, }, combo_melee::Stage { stage: 3, @@ -204,8 +204,8 @@ impl Tool { range: 3.5, angle: 45.0, base_buildup_duration: Duration::from_millis(150), + base_swing_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100), - swing_frac: 0.5, }, ], initial_energy_gain: 0, diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index 65294dc975..3694a20555 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -1,6 +1,6 @@ use crate::{ comp::{Attacking, CharacterState, EnergySource, StateUpdate}, - states::utils::*, + states::{utils::*, wielding::StageSection}, sys::character_behavior::{CharacterBehavior, JoinData}, }; use serde::{Deserialize, Serialize}; @@ -24,19 +24,10 @@ pub struct Stage { pub angle: f32, /// Initial buildup duration of stage (how long until state can deal damage) pub base_buildup_duration: Duration, + /// Duration of stage spent in swing (controls animation stuff, and can also be used to handle movement separately to buildup) + pub base_swing_duration: Duration, /// Initial recover duration of stage (how long until character exits state) pub base_recover_duration: Duration, - /// Determines what portion of the buildup duration is a swing. Used for animation purposes. - pub swing_frac: f64, -} - -/// Determines whether state is in buildup, swing, recover, or combo -#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub enum StageSection { - Buildup, - Swing, - Recover, - Combo, } /// A sequence of attacks that can incrementally become faster and more @@ -94,6 +85,37 @@ impl CharacterBehavior for Data { stage_section: self.stage_section, }); } else if self.stage_section == StageSection::Buildup { + update.character = CharacterState::ComboMelee(Data { + stage: self.stage, + num_stages: self.num_stages, + combo: self.combo, + stage_data: self.stage_data.clone(), + initial_energy_gain: self.initial_energy_gain, + max_energy_gain: self.max_energy_gain, + energy_increase: self.energy_increase, + combo_duration: self.combo_duration, + timer: Duration::default(), + stage_section: StageSection::Swing, + }); + } else if self.stage_section == StageSection::Swing + && self.timer < self.stage_data[stage_index].base_swing_duration + { + update.character = CharacterState::ComboMelee(Data { + stage: self.stage, + num_stages: self.num_stages, + combo: self.combo, + stage_data: self.stage_data.clone(), + initial_energy_gain: self.initial_energy_gain, + max_energy_gain: self.max_energy_gain, + energy_increase: self.energy_increase, + combo_duration: self.combo_duration, + timer: self + .timer + .checked_add(Duration::from_secs_f32(data.dt.0)) + .unwrap_or_default(), + stage_section: self.stage_section, + }); + } else if self.stage_section == StageSection::Swing { // Hit attempt data.updater.insert(data.entity, Attacking { base_healthchange: -((self.stage_data[stage_index].max_damage.min( diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index f64ae9c77f..9f340f8d09 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -3,6 +3,7 @@ use crate::{ comp::{CharacterState, StateUpdate}, sys::character_behavior::{CharacterBehavior, JoinData}, }; +use serde::{Deserialize, Serialize}; pub struct Data; @@ -57,3 +58,14 @@ impl CharacterBehavior for Data { update } } + + + +/// Determines what portion a state is in. Used in all attacks (eventually). Is used to control aspects of animation code, as well as logic within the character states. +#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum StageSection { + Buildup, + Swing, + Recover, + Combo, +} \ No newline at end of file diff --git a/voxygen/src/anim/src/character/alpha.rs b/voxygen/src/anim/src/character/alpha.rs index 27b8b49801..618f052c75 100644 --- a/voxygen/src/anim/src/character/alpha.rs +++ b/voxygen/src/anim/src/character/alpha.rs @@ -4,7 +4,7 @@ use super::{ }; use common::{ comp::item::{Hands, ToolKind}, - states::combo_melee::StageSection, + states::wielding::StageSection, }; use std::f32::consts::PI; diff --git a/voxygen/src/anim/src/character/beta.rs b/voxygen/src/anim/src/character/beta.rs index 3172abb3cb..ed24a9e663 100644 --- a/voxygen/src/anim/src/character/beta.rs +++ b/voxygen/src/anim/src/character/beta.rs @@ -4,7 +4,7 @@ use super::{ }; use common::{ comp::item::{Hands, ToolKind}, - states::combo_melee::StageSection, + states::wielding::StageSection, }; pub struct BetaAnimation; diff --git a/voxygen/src/anim/src/character/spin.rs b/voxygen/src/anim/src/character/spin.rs index c0206607d6..e31da53f28 100644 --- a/voxygen/src/anim/src/character/spin.rs +++ b/voxygen/src/anim/src/character/spin.rs @@ -4,7 +4,7 @@ use super::{ }; use common::{ comp::item::{Hands, ToolKind}, - states::combo_melee::StageSection, + states::wielding::StageSection, }; use std::f32::consts::PI; diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 8152c4db22..64d74196f2 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -30,7 +30,7 @@ use common::{ }, span, state::{DeltaTime, State}, - states::combo_melee::StageSection, + states::wielding::StageSection, terrain::TerrainChunk, vol::RectRasterableVol, }; @@ -915,19 +915,18 @@ impl FigureMgr { CharacterState::ComboMelee(s) => { let stage_index = (s.stage - 1) as usize; let stage_time = s.timer.as_secs_f64(); - let mut stage_section = Some(s.stage_section); let stage_progress = match s.stage_section { StageSection::Buildup => { - let buildup_progress = stage_time + stage_time / s.stage_data[stage_index] .base_buildup_duration - .as_secs_f64(); - if buildup_progress < s.stage_data[stage_index].swing_frac { - buildup_progress / (1.0 - s.stage_data[stage_index].swing_frac) - } else { - stage_section = Some(StageSection::Swing); - (buildup_progress - (1.0 - s.stage_data[stage_index].swing_frac)) / s.stage_data[stage_index].swing_frac - } + .as_secs_f64() + }, + StageSection::Swing => { + stage_time + / s.stage_data[stage_index] + .base_swing_duration + .as_secs_f64() }, StageSection::Recover => { stage_time @@ -936,26 +935,25 @@ impl FigureMgr { .as_secs_f64() }, StageSection::Combo => stage_time / s.combo_duration.as_secs_f64(), - _ => 0.0, }; match s.stage { 1 => anim::character::AlphaAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, vel.0.magnitude(), time, stage_section), + (active_tool_kind, second_tool_kind, vel.0.magnitude(), time, Some(s.stage_section)), stage_progress, &mut state_animation_rate, skeleton_attr, ), 2 => anim::character::SpinAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, time, stage_section), + (active_tool_kind, second_tool_kind, time, Some(s.stage_section)), stage_progress, &mut state_animation_rate, skeleton_attr, ), _ => anim::character::BetaAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, vel.0.magnitude(), time, stage_section), + (active_tool_kind, second_tool_kind, vel.0.magnitude(), time, Some(s.stage_section)), stage_progress, &mut state_animation_rate, skeleton_attr,