Removed swing_frac, added a swing duration instead to allow for more utility in character state. Moved location of stage_section enum to wielding so it could more easily be used by other character states.

This commit is contained in:
Sam 2020-09-07 12:30:52 -05:00
parent 2ba9d1e54f
commit 847bddbd89
8 changed files with 69 additions and 37 deletions

View File

@ -341,7 +341,7 @@ impl From<&CharacterAbility> for CharacterState {
energy_increase: *energy_increase, energy_increase: *energy_increase,
combo_duration: *combo_duration, combo_duration: *combo_duration,
timer: Duration::default(), timer: Duration::default(),
stage_section: combo_melee::StageSection::Buildup, stage_section: wielding::StageSection::Buildup,
}), }),
CharacterAbility::LeapMelee { CharacterAbility::LeapMelee {
energy_cost: _, energy_cost: _,

View File

@ -128,8 +128,8 @@ impl Tool {
range: 3.5, range: 3.5,
angle: 45.0, angle: 45.0,
base_buildup_duration: Duration::from_millis(10), base_buildup_duration: Duration::from_millis(10),
base_swing_duration: Duration::from_millis(10),
base_recover_duration: Duration::from_millis(10), base_recover_duration: Duration::from_millis(10),
swing_frac: 0.5,
}, },
combo_melee::Stage { combo_melee::Stage {
stage: 2, stage: 2,
@ -139,9 +139,9 @@ impl Tool {
knockback: 5.0, knockback: 5.0,
range: 3.5, range: 3.5,
angle: 45.0, 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), base_recover_duration: Duration::from_millis(400),
swing_frac: 0.6,
}, },
combo_melee::Stage { combo_melee::Stage {
stage: 3, stage: 3,
@ -152,8 +152,8 @@ impl Tool {
range: 3.5, range: 3.5,
angle: 45.0, angle: 45.0,
base_buildup_duration: Duration::from_millis(10), base_buildup_duration: Duration::from_millis(10),
base_swing_duration: Duration::from_millis(10),
base_recover_duration: Duration::from_millis(10), base_recover_duration: Duration::from_millis(10),
swing_frac: 0.5,
}, },
], ],
initial_energy_gain: 0, initial_energy_gain: 0,
@ -180,8 +180,8 @@ impl Tool {
range: 3.5, range: 3.5,
angle: 45.0, angle: 45.0,
base_buildup_duration: Duration::from_millis(150), base_buildup_duration: Duration::from_millis(150),
base_swing_duration: Duration::from_millis(100),
base_recover_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100),
swing_frac: 0.5,
}, },
combo_melee::Stage { combo_melee::Stage {
stage: 2, stage: 2,
@ -192,8 +192,8 @@ impl Tool {
range: 3.5, range: 3.5,
angle: 45.0, angle: 45.0,
base_buildup_duration: Duration::from_millis(150), base_buildup_duration: Duration::from_millis(150),
base_swing_duration: Duration::from_millis(100),
base_recover_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100),
swing_frac: 0.6,
}, },
combo_melee::Stage { combo_melee::Stage {
stage: 3, stage: 3,
@ -204,8 +204,8 @@ impl Tool {
range: 3.5, range: 3.5,
angle: 45.0, angle: 45.0,
base_buildup_duration: Duration::from_millis(150), base_buildup_duration: Duration::from_millis(150),
base_swing_duration: Duration::from_millis(100),
base_recover_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(100),
swing_frac: 0.5,
}, },
], ],
initial_energy_gain: 0, initial_energy_gain: 0,

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
comp::{Attacking, CharacterState, EnergySource, StateUpdate}, comp::{Attacking, CharacterState, EnergySource, StateUpdate},
states::utils::*, states::{utils::*, wielding::StageSection},
sys::character_behavior::{CharacterBehavior, JoinData}, sys::character_behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -24,19 +24,10 @@ pub struct Stage {
pub angle: f32, pub angle: f32,
/// Initial buildup duration of stage (how long until state can deal damage) /// Initial buildup duration of stage (how long until state can deal damage)
pub base_buildup_duration: Duration, 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) /// Initial recover duration of stage (how long until character exits state)
pub base_recover_duration: Duration, 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 /// A sequence of attacks that can incrementally become faster and more
@ -94,6 +85,37 @@ impl CharacterBehavior for Data {
stage_section: self.stage_section, stage_section: self.stage_section,
}); });
} else if self.stage_section == StageSection::Buildup { } 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 // Hit attempt
data.updater.insert(data.entity, Attacking { data.updater.insert(data.entity, Attacking {
base_healthchange: -((self.stage_data[stage_index].max_damage.min( base_healthchange: -((self.stage_data[stage_index].max_damage.min(

View File

@ -3,6 +3,7 @@ use crate::{
comp::{CharacterState, StateUpdate}, comp::{CharacterState, StateUpdate},
sys::character_behavior::{CharacterBehavior, JoinData}, sys::character_behavior::{CharacterBehavior, JoinData},
}; };
use serde::{Deserialize, Serialize};
pub struct Data; pub struct Data;
@ -57,3 +58,14 @@ impl CharacterBehavior for Data {
update 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,
}

View File

@ -4,7 +4,7 @@ use super::{
}; };
use common::{ use common::{
comp::item::{Hands, ToolKind}, comp::item::{Hands, ToolKind},
states::combo_melee::StageSection, states::wielding::StageSection,
}; };
use std::f32::consts::PI; use std::f32::consts::PI;

View File

@ -4,7 +4,7 @@ use super::{
}; };
use common::{ use common::{
comp::item::{Hands, ToolKind}, comp::item::{Hands, ToolKind},
states::combo_melee::StageSection, states::wielding::StageSection,
}; };
pub struct BetaAnimation; pub struct BetaAnimation;

View File

@ -4,7 +4,7 @@ use super::{
}; };
use common::{ use common::{
comp::item::{Hands, ToolKind}, comp::item::{Hands, ToolKind},
states::combo_melee::StageSection, states::wielding::StageSection,
}; };
use std::f32::consts::PI; use std::f32::consts::PI;

View File

@ -30,7 +30,7 @@ use common::{
}, },
span, span,
state::{DeltaTime, State}, state::{DeltaTime, State},
states::combo_melee::StageSection, states::wielding::StageSection,
terrain::TerrainChunk, terrain::TerrainChunk,
vol::RectRasterableVol, vol::RectRasterableVol,
}; };
@ -915,19 +915,18 @@ impl FigureMgr {
CharacterState::ComboMelee(s) => { CharacterState::ComboMelee(s) => {
let stage_index = (s.stage - 1) as usize; let stage_index = (s.stage - 1) as usize;
let stage_time = s.timer.as_secs_f64(); let stage_time = s.timer.as_secs_f64();
let mut stage_section = Some(s.stage_section);
let stage_progress = match s.stage_section { let stage_progress = match s.stage_section {
StageSection::Buildup => { StageSection::Buildup => {
let buildup_progress = stage_time stage_time
/ s.stage_data[stage_index] / s.stage_data[stage_index]
.base_buildup_duration .base_buildup_duration
.as_secs_f64(); .as_secs_f64()
if buildup_progress < s.stage_data[stage_index].swing_frac { },
buildup_progress / (1.0 - s.stage_data[stage_index].swing_frac) StageSection::Swing => {
} else { stage_time
stage_section = Some(StageSection::Swing); / s.stage_data[stage_index]
(buildup_progress - (1.0 - s.stage_data[stage_index].swing_frac)) / s.stage_data[stage_index].swing_frac .base_swing_duration
} .as_secs_f64()
}, },
StageSection::Recover => { StageSection::Recover => {
stage_time stage_time
@ -936,26 +935,25 @@ impl FigureMgr {
.as_secs_f64() .as_secs_f64()
}, },
StageSection::Combo => stage_time / s.combo_duration.as_secs_f64(), StageSection::Combo => stage_time / s.combo_duration.as_secs_f64(),
_ => 0.0,
}; };
match s.stage { match s.stage {
1 => anim::character::AlphaAnimation::update_skeleton( 1 => anim::character::AlphaAnimation::update_skeleton(
&target_base, &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, stage_progress,
&mut state_animation_rate, &mut state_animation_rate,
skeleton_attr, skeleton_attr,
), ),
2 => anim::character::SpinAnimation::update_skeleton( 2 => anim::character::SpinAnimation::update_skeleton(
&target_base, &target_base,
(active_tool_kind, second_tool_kind, time, stage_section), (active_tool_kind, second_tool_kind, time, Some(s.stage_section)),
stage_progress, stage_progress,
&mut state_animation_rate, &mut state_animation_rate,
skeleton_attr, skeleton_attr,
), ),
_ => anim::character::BetaAnimation::update_skeleton( _ => anim::character::BetaAnimation::update_skeleton(
&target_base, &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, stage_progress,
&mut state_animation_rate, &mut state_animation_rate,
skeleton_attr, skeleton_attr,