From abc1dd9997e16cfa7f803780c84ee6bf278675a5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 20 Nov 2020 11:30:48 -0600 Subject: [PATCH] Rolling can now interrupt any attack. --- common/src/comp/ability.rs | 4 ++++ common/src/states/basic_beam.rs | 9 +++++++++ common/src/states/basic_melee.rs | 11 +++++++++++ common/src/states/basic_ranged.rs | 9 +++++++++ common/src/states/charged_melee.rs | 9 +++++++++ common/src/states/charged_ranged.rs | 9 +++++++++ common/src/states/combo_melee.rs | 19 ++++++------------- common/src/states/dash_melee.rs | 8 ++------ common/src/states/leap_melee.rs | 11 +++++++++++ common/src/states/repeater_ranged.rs | 11 +++++++++++ common/src/states/shockwave.rs | 11 +++++++++++ common/src/states/spin_melee.rs | 7 ++----- common/src/states/utils.rs | 10 ++++++---- 13 files changed, 100 insertions(+), 28 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 20af926a83..020ad6425a 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -589,6 +589,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { knockback: *knockback, range: *range, max_angle: *max_angle, + ability_key: key, }, timer: Duration::default(), stage_section: StageSection::Buildup, @@ -741,6 +742,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { max_angle: *max_angle, forward_leap_strength: *forward_leap_strength, vertical_leap_strength: *vertical_leap_strength, + ability_key: key, }, timer: Duration::default(), stage_section: StageSection::Buildup, @@ -877,6 +879,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { projectile_light: *projectile_light, projectile_gravity: *projectile_gravity, projectile_speed: *projectile_speed, + ability_key: key, }, timer: Duration::default(), stage_section: StageSection::Movement, @@ -908,6 +911,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState { shockwave_duration: Duration::from_millis(*shockwave_duration), requires_ground: *requires_ground, move_efficiency: *move_efficiency, + ability_key: key, }, timer: Duration::default(), stage_section: StageSection::Buildup, diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 9ccb757db0..a6bfbd6532 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -63,6 +63,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::BasicBeam(_) => {}, + _ => { + return update; + }, + } + } if unwrap_tool_data(data).is_none() { update.character = CharacterState::Idle; diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 888aac20da..57248ff7f7 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -24,6 +24,8 @@ pub struct StaticData { pub range: f32, /// Max angle (45.0 will give you a 90.0 angle window) pub max_angle: f32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -45,6 +47,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::BasicMelee(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index 702dfa1ba7..64a1ac5125 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -48,6 +48,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::BasicRanged(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index 074a4392f8..4895971a2c 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -59,6 +59,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::ChargedMelee(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Charge => { diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 6074edd2bf..23977db133 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -63,6 +63,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::ChargedRanged(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index 78084b5eee..9ca71484b8 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -110,19 +110,10 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.3); - - let stage_index = (self.stage - 1) as usize; - - // Allows for other states to interrupt this state - if self.static_data.is_interruptible - && !ability_key_is_pressed(data, self.static_data.ability_key) - { - handle_interrupt(data, &mut update); - if ability_key_is_pressed(data, AbilityKey::Dodge) { - handle_dodge_input(data, &mut update); - if let CharacterState::Roll(roll) = &mut update.character { - roll.was_combo = Some((self.stage, self.combo)); - } + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, !self.static_data.is_interruptible); + if let CharacterState::Roll(roll) = &mut update.character { + roll.was_combo = Some((self.stage, self.combo)); } match update.character { CharacterState::ComboMelee(_) => {}, @@ -132,6 +123,8 @@ impl CharacterBehavior for Data { } } + let stage_index = (self.stage - 1) as usize; + let speed_modifer = 1.0 + self.static_data.max_speed_increase * (1.0 - self.static_data.speed_increase.powi(self.combo as i32)); diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 391f469c2b..c0b4769714 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -66,12 +66,8 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.1); - - // Allows for other states to interrupt this state - if self.static_data.is_interruptible - && !ability_key_is_pressed(data, self.static_data.ability_key) - { - handle_interrupt(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, !self.static_data.is_interruptible); match update.character { CharacterState::DashMelee(_) => {}, _ => { diff --git a/common/src/states/leap_melee.rs b/common/src/states/leap_melee.rs index db12c0ebc8..866261035b 100644 --- a/common/src/states/leap_melee.rs +++ b/common/src/states/leap_melee.rs @@ -30,6 +30,8 @@ pub struct StaticData { pub forward_leap_strength: f32, /// Affects how high the player leaps pub vertical_leap_strength: f32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -51,6 +53,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::LeapMelee(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { // Delay before leaping into the air diff --git a/common/src/states/repeater_ranged.rs b/common/src/states/repeater_ranged.rs index 1540814697..4aa26274aa 100644 --- a/common/src/states/repeater_ranged.rs +++ b/common/src/states/repeater_ranged.rs @@ -28,6 +28,8 @@ pub struct StaticData { pub projectile_light: Option, pub projectile_gravity: Option, pub projectile_speed: f32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -49,6 +51,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 1.0); handle_jump(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::RepeaterRanged(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Movement => { diff --git a/common/src/states/shockwave.rs b/common/src/states/shockwave.rs index cb3dc7fd3a..b8c7e986d9 100644 --- a/common/src/states/shockwave.rs +++ b/common/src/states/shockwave.rs @@ -33,6 +33,8 @@ pub struct StaticData { pub requires_ground: bool, /// Movement speed efficiency pub move_efficiency: f32, + /// What key is used to press ability + pub ability_key: AbilityKey, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -51,6 +53,15 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); handle_move(data, &mut update, self.static_data.move_efficiency); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, true); + match update.character { + CharacterState::Shockwave(_) => {}, + _ => { + return update; + }, + } + } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index 451328d3cb..784ecfbd30 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -71,11 +71,8 @@ impl CharacterBehavior for Data { Vec3::new(0.0, 0.0, update.vel.0.z + delta_vel_z) + data.inputs.move_dir * 5.0; } - // Allows for other states to interrupt this state - if self.static_data.is_interruptible - && !ability_key_is_pressed(data, self.static_data.ability_key) - { - handle_interrupt(data, &mut update); + if !ability_key_is_pressed(data, self.static_data.ability_key) { + handle_interrupt(data, &mut update, !self.static_data.is_interruptible); match update.character { CharacterState::SpinMelee(_) => {}, _ => { diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 3074f339d6..979cee9f70 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -420,10 +420,12 @@ pub fn unwrap_tool_data<'a>(data: &'a JoinData) -> Option<&'a Tool> { } } -pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate) { - handle_ability1_input(data, update); - handle_ability2_input(data, update); - handle_ability3_input(data, update); +pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, only_dodge: bool) { + if !only_dodge { + handle_ability1_input(data, update); + handle_ability2_input(data, update); + handle_ability3_input(data, update); + } handle_dodge_input(data, update); }