From 52c93f613e60c4f003d7c95b9c742d596717c209 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 27 Oct 2020 17:16:17 -0500 Subject: [PATCH] Addressed comments. --- common/src/combat.rs | 46 +++++++++------------------- common/src/states/basic_beam.rs | 17 +++------- common/src/states/basic_melee.rs | 21 ++++--------- common/src/states/basic_ranged.rs | 11 +++---- common/src/states/boost.rs | 2 +- common/src/states/charged_melee.rs | 31 +++++-------------- common/src/states/charged_ranged.rs | 21 ++++--------- common/src/states/combo_melee.rs | 29 +++++------------- common/src/states/dash_melee.rs | 46 ++++++---------------------- common/src/states/equipping.rs | 2 +- common/src/states/repeater_ranged.rs | 20 +++++------- common/src/states/roll.rs | 18 +++-------- common/src/states/shockwave.rs | 13 +++----- common/src/states/spin_melee.rs | 30 +++++------------- common/src/sys/beam.rs | 35 +++++++++------------ common/src/sys/melee.rs | 15 ++++----- common/src/sys/projectile.rs | 15 +++++---- common/src/sys/shockwave.rs | 14 ++++----- 18 files changed, 120 insertions(+), 266 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index e80de3abe6..bebda0aa11 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -8,14 +8,22 @@ use vek::*; pub const BLOCK_EFFICIENCY: f32 = 0.9; +/// Each section of this struct determines what damage is applied to a +/// particular target, using some identifier #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Damages { + /// Targets enemies, and all other creatures not in your group pub enemy: Option, + /// Targets people in the same group as you, and any pets you have pub group: Option, } impl Damages { pub fn new(enemy: Option, group: Option) -> Self { Damages { enemy, group } } + + pub fn get_damage(self, same_group: bool) -> Option { + if same_group { self.group } else { self.enemy } + } } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -49,11 +57,7 @@ impl Damage { damage *= 1.0 - BLOCK_EFFICIENCY } // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); damage *= 1.0 - damage_reduction; // Critical damage applies after armor for melee @@ -77,11 +81,7 @@ impl Damage { damage *= 1.0 - BLOCK_EFFICIENCY } // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); damage *= 1.0 - damage_reduction; HealthChange { @@ -96,11 +96,7 @@ impl Damage { damage *= 1.0 - BLOCK_EFFICIENCY } // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); damage *= 1.0 - damage_reduction; HealthChange { @@ -111,11 +107,7 @@ impl Damage { Damage::Shockwave(damage) => { let mut damage = damage; // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); damage *= 1.0 - damage_reduction; HealthChange { @@ -126,11 +118,7 @@ impl Damage { Damage::Energy(damage) => { let mut damage = damage; // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); damage *= 1.0 - damage_reduction; HealthChange { @@ -145,11 +133,7 @@ impl Damage { Damage::Falling(damage) => { let mut damage = damage; // Armor - let damage_reduction = if let Some(loadout) = loadout { - loadout.get_damage_reduction() - } else { - 0.0 - }; + let damage_reduction = loadout.map_or(0.0, |l| l.get_damage_reduction()); if (damage_reduction - 1.0).abs() < f32::EPSILON { damage = 0.0; } @@ -171,7 +155,7 @@ pub enum Knockback { } impl Knockback { - pub fn get_knockback(self, dir: Dir) -> Vec3 { + pub fn calculate_impulse(self, dir: Dir) -> Vec3 { match self { Knockback::Away(strength) => strength * *Dir::slerp(dir, Dir::new(Vec3::unit_z()), 0.5), Knockback::Towards(strength) => { diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 37c84d6264..4a387ba7da 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -74,14 +74,12 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::BasicBeam(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, particle_ori: Some(*data.inputs.look_dir), - offset: self.offset, + ..*self }); } else { // Creates beam @@ -97,11 +95,11 @@ impl CharacterBehavior for Data { }; // Build up update.character = CharacterState::BasicBeam(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Cast, particle_ori: Some(*data.inputs.look_dir), offset: eye_height * 0.55, + ..*self }); } }, @@ -139,14 +137,12 @@ impl CharacterBehavior for Data { ori: Ori(data.inputs.look_dir), }); update.character = CharacterState::BasicBeam(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, particle_ori: Some(*data.inputs.look_dir), - offset: self.offset, + ..*self }); // Consumes energy if there's enough left and ability key is held down @@ -156,25 +152,22 @@ impl CharacterBehavior for Data { ); } else { update.character = CharacterState::BasicBeam(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Recover, particle_ori: Some(*data.inputs.look_dir), - offset: self.offset, + ..*self }); } }, StageSection::Recover => { if self.timer < self.static_data.recover_duration { update.character = CharacterState::BasicBeam(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, particle_ori: Some(*data.inputs.look_dir), - offset: self.offset, + ..*self }); } else { // Done diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 744c30c3b8..228a10a204 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -51,31 +51,27 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to swing section of stage update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Swing, - exhausted: self.exhausted, + ..*self }); } }, StageSection::Swing => { if !self.exhausted { update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: Duration::default(), - stage_section: self.stage_section, exhausted: true, + ..*self }); // Hit attempt @@ -93,21 +89,18 @@ impl CharacterBehavior for Data { } else if self.timer < self.static_data.swing_duration { // Swings update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to recover section of stage update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Recover, - exhausted: self.exhausted, + ..*self }); } }, @@ -115,13 +108,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Recovery update.character = CharacterState::BasicMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Done diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index bb0950e605..19fff5e2b5 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -54,8 +54,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to recover section of stage @@ -63,7 +62,7 @@ impl CharacterBehavior for Data { static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Recover, - exhausted: self.exhausted, + ..*self }); } }, @@ -84,9 +83,8 @@ impl CharacterBehavior for Data { update.character = CharacterState::BasicRanged(Data { static_data: self.static_data.clone(), - timer: self.timer, - stage_section: self.stage_section, exhausted: true, + ..*self }); } else if self.timer < self.static_data.recover_duration { // Recovers @@ -96,8 +94,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Done diff --git a/common/src/states/boost.rs b/common/src/states/boost.rs index 564a714c57..4b0110c605 100644 --- a/common/src/states/boost.rs +++ b/common/src/states/boost.rs @@ -36,11 +36,11 @@ impl CharacterBehavior for Data { update.vel.0 += *data.inputs.look_dir * 500.0 * data.dt.0; } update.character = CharacterState::Boost(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), + ..*self }); } else { // Done diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index 0da5ada515..e0255e89a4 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -68,14 +68,12 @@ impl CharacterBehavior for Data { // Charge the attack update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, - stage_section: self.stage_section, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - exhausted: self.exhausted, charge_amount: charge, + ..*self }); // Consumes energy if there's enough left and RMB is held down @@ -88,14 +86,11 @@ impl CharacterBehavior for Data { { // Maintains charge update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, - stage_section: self.stage_section, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - exhausted: self.exhausted, - charge_amount: self.charge_amount, + ..*self }); // Consumes energy if there's enough left and RMB is held down @@ -106,11 +101,9 @@ impl CharacterBehavior for Data { } else { // Transitions to swing update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, stage_section: StageSection::Swing, timer: Duration::default(), - exhausted: self.exhausted, - charge_amount: self.charge_amount, + ..*self }); } }, @@ -135,35 +128,28 @@ impl CharacterBehavior for Data { // Starts swinging update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, - stage_section: self.stage_section, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), exhausted: true, - charge_amount: self.charge_amount, + ..*self }); } else if self.timer < self.static_data.swing_duration { // Swings update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, - stage_section: self.stage_section, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - exhausted: self.exhausted, - charge_amount: self.charge_amount, + ..*self }); } else { // Transitions to recover update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, stage_section: StageSection::Recover, timer: Duration::default(), - exhausted: self.exhausted, - charge_amount: self.charge_amount, + ..*self }); } }, @@ -171,14 +157,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Recovers update.character = CharacterState::ChargedMelee(Data { - static_data: self.static_data, - stage_section: self.stage_section, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - exhausted: self.exhausted, - charge_amount: self.charge_amount, + ..*self }); } else { // Done diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 3b19fa8268..036f9ac5bc 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -63,21 +63,18 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to swing section of stage update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Charge, - exhausted: self.exhausted, + ..*self }); } }, @@ -124,23 +121,21 @@ impl CharacterBehavior for Data { }); update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Recover, exhausted: true, + ..*self }); } else if self.timer < self.static_data.charge_duration && data.inputs.secondary.is_pressed() { // Charges update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); // Consumes energy if there's enough left and RMB is held down @@ -151,13 +146,11 @@ impl CharacterBehavior for Data { } else if data.inputs.secondary.is_pressed() { // Holds charge update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); // Consumes energy if there's enough left and RMB is held down @@ -171,13 +164,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Recovers update.character = CharacterState::ChargedRanged(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Done diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index ca66efae6e..285804e278 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -100,8 +100,6 @@ impl CharacterBehavior for Data { // Build up update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: self .timer .checked_add(Duration::from_secs_f32( @@ -111,18 +109,15 @@ impl CharacterBehavior for Data { * data.dt.0, )) .unwrap_or_default(), - stage_section: self.stage_section, - next_stage: self.next_stage, + ..*self }); } else { // Transitions to swing section of stage update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: Duration::default(), stage_section: StageSection::Swing, - next_stage: self.next_stage, + ..*self }); // Hit attempt @@ -158,8 +153,6 @@ impl CharacterBehavior for Data { // Swings update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: self .timer .checked_add(Duration::from_secs_f32( @@ -169,18 +162,15 @@ impl CharacterBehavior for Data { * data.dt.0, )) .unwrap_or_default(), - stage_section: self.stage_section, - next_stage: self.next_stage, + ..*self }); } else { // Transitions to recover section of stage update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: Duration::default(), stage_section: StageSection::Recover, - next_stage: self.next_stage, + ..*self }); } }, @@ -191,8 +181,6 @@ impl CharacterBehavior for Data { // Checks if state will transition to next stage after recover update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: self .timer .checked_add(Duration::from_secs_f32( @@ -205,14 +193,12 @@ impl CharacterBehavior for Data { * data.dt.0, )) .unwrap_or_default(), - stage_section: self.stage_section, next_stage: true, + ..*self }); } else { update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: self.stage, - combo: self.combo, timer: self .timer .checked_add(Duration::from_secs_f32( @@ -225,8 +211,7 @@ impl CharacterBehavior for Data { * data.dt.0, )) .unwrap_or_default(), - stage_section: self.stage_section, - next_stage: self.next_stage, + ..*self }); } } else if self.next_stage { @@ -234,10 +219,10 @@ impl CharacterBehavior for Data { update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), stage: (self.stage % self.static_data.num_stages) + 1, - combo: self.combo, timer: Duration::default(), stage_section: StageSection::Buildup, next_stage: false, + ..*self }); } else { // Done diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 820117704e..8a99b80bd9 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -81,25 +81,19 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - refresh_timer: self.refresh_timer, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to charge section of stage update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, auto_charge: !data.inputs.secondary.is_pressed(), timer: Duration::default(), - refresh_timer: self.refresh_timer, stage_section: StageSection::Charge, - exhausted: self.exhausted, + ..*self }); } }, @@ -146,20 +140,15 @@ impl CharacterBehavior for Data { }); } update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - refresh_timer: self.refresh_timer, - stage_section: self.stage_section, exhausted: true, + ..*self }) } else if self.refresh_timer < Duration::from_millis(50) { update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) @@ -168,20 +157,17 @@ impl CharacterBehavior for Data { .refresh_timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }) } else { update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), refresh_timer: Duration::default(), - stage_section: self.stage_section, exhausted: false, + ..*self }) } @@ -193,12 +179,9 @@ impl CharacterBehavior for Data { } else { // Transitions to swing section of stage update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: Duration::default(), - refresh_timer: self.refresh_timer, stage_section: StageSection::Swing, - exhausted: self.exhausted, + ..*self }); } }, @@ -206,25 +189,18 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.swing_duration { // Swings update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - refresh_timer: self.refresh_timer, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to recover section of stage update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: Duration::default(), - refresh_timer: self.refresh_timer, stage_section: StageSection::Recover, - exhausted: self.exhausted, + ..*self }); } }, @@ -232,15 +208,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Recover update.character = CharacterState::DashMelee(Data { - static_data: self.static_data, - auto_charge: self.auto_charge, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - refresh_timer: self.refresh_timer, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Done diff --git a/common/src/states/equipping.rs b/common/src/states/equipping.rs index b0e63c11ea..fac06e5351 100644 --- a/common/src/states/equipping.rs +++ b/common/src/states/equipping.rs @@ -32,11 +32,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Draw weapon update.character = CharacterState::Equipping(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), + ..*self }); } else { // Done diff --git a/common/src/states/repeater_ranged.rs b/common/src/states/repeater_ranged.rs index 5adfdde10a..b6ee044680 100644 --- a/common/src/states/repeater_ranged.rs +++ b/common/src/states/repeater_ranged.rs @@ -76,8 +76,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - reps_remaining: self.reps_remaining, + ..*self }); } else { // Transition to buildup @@ -85,7 +84,7 @@ impl CharacterBehavior for Data { static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Buildup, - reps_remaining: self.reps_remaining, + ..*self }); } }, @@ -107,8 +106,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - reps_remaining: self.reps_remaining, + ..*self }); } else { // Transition to shoot @@ -116,7 +114,7 @@ impl CharacterBehavior for Data { static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Shoot, - reps_remaining: self.reps_remaining, + ..*self }); } }, @@ -162,8 +160,8 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, reps_remaining: self.reps_remaining - 1, + ..*self }); } else if self.timer < self.static_data.shoot_duration { // Finish shooting @@ -173,8 +171,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - reps_remaining: self.reps_remaining, + ..*self }); } else { // Transition to recover @@ -182,7 +179,7 @@ impl CharacterBehavior for Data { static_data: self.static_data.clone(), timer: Duration::default(), stage_section: StageSection::Recover, - reps_remaining: self.reps_remaining, + ..*self }); } }, @@ -198,8 +195,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - reps_remaining: self.reps_remaining, + ..*self }); } else { // Done diff --git a/common/src/states/roll.rs b/common/src/states/roll.rs index 2a49f44445..cb18a441f5 100644 --- a/common/src/states/roll.rs +++ b/common/src/states/roll.rs @@ -54,21 +54,18 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::Roll(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - was_wielded: self.was_wielded, + ..*self }); } else { // Transitions to movement section of stage update.character = CharacterState::Roll(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Movement, - was_wielded: self.was_wielded, + ..*self }); } }, @@ -76,21 +73,18 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.movement_duration { // Movement update.character = CharacterState::Roll(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - was_wielded: self.was_wielded, + ..*self }); } else { // Transitions to recover section of stage update.character = CharacterState::Roll(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Recover, - was_wielded: self.was_wielded, + ..*self }); } }, @@ -98,13 +92,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Build up update.character = CharacterState::Roll(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, - was_wielded: self.was_wielded, + ..*self }); } else { // Done diff --git a/common/src/states/shockwave.rs b/common/src/states/shockwave.rs index a9bb69cd07..de0cbf3ab5 100644 --- a/common/src/states/shockwave.rs +++ b/common/src/states/shockwave.rs @@ -57,12 +57,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::Shockwave(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, + ..*self }); } else { // Attack @@ -87,9 +86,9 @@ impl CharacterBehavior for Data { // Transitions to swing update.character = CharacterState::Shockwave(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Swing, + ..*self }); } }, @@ -97,19 +96,18 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.swing_duration { // Swings update.character = CharacterState::Shockwave(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, + ..*self }); } else { // Transitions to recover update.character = CharacterState::Shockwave(Data { - static_data: self.static_data, timer: Duration::default(), stage_section: StageSection::Recover, + ..*self }); } }, @@ -117,12 +115,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.swing_duration { // Recovers update.character = CharacterState::Shockwave(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, + ..*self }); } else { // Done diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index d685d5dbb4..14c4bec054 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -80,34 +80,27 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.buildup_duration { // Build up update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - spins_remaining: self.spins_remaining, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Transitions to swing section of stage update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: Duration::default(), - spins_remaining: self.spins_remaining, stage_section: StageSection::Swing, - exhausted: self.exhausted, + ..*self }); } }, StageSection::Swing => { if !self.exhausted { update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: Duration::default(), - spins_remaining: self.spins_remaining, - stage_section: self.stage_section, exhausted: true, + ..*self }); // Hit attempt data.updater.insert(data.entity, Attacking { @@ -136,14 +129,11 @@ impl CharacterBehavior for Data { // Swings update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - spins_remaining: self.spins_remaining, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else if update.energy.current() >= self.static_data.energy_cost && (self.spins_remaining != 0 @@ -155,11 +145,10 @@ impl CharacterBehavior for Data { self.spins_remaining - 1 }; update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: Duration::default(), spins_remaining: new_spins_remaining, - stage_section: self.stage_section, exhausted: false, + ..*self }); // Consumes energy if there's enough left and RMB is held down update.energy.change_by( @@ -169,11 +158,9 @@ impl CharacterBehavior for Data { } else { // Transitions to recover section of stage update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: Duration::default(), - spins_remaining: self.spins_remaining, stage_section: StageSection::Recover, - exhausted: self.exhausted, + ..*self }); } }, @@ -181,14 +168,11 @@ impl CharacterBehavior for Data { if self.timer < self.static_data.recover_duration { // Recover update.character = CharacterState::SpinMelee(Data { - static_data: self.static_data, timer: self .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - spins_remaining: self.spins_remaining, - stage_section: self.stage_section, - exhausted: self.exhausted, + ..*self }); } else { // Done diff --git a/common/src/sys/beam.rs b/common/src/sys/beam.rs index e6abc2ecf0..ea6f5dd3b2 100644 --- a/common/src/sys/beam.rs +++ b/common/src/sys/beam.rs @@ -168,10 +168,8 @@ impl<'a> System<'a> for Sys { continue; } - let damage = if !same_group && beam_segment.damages.enemy.is_some() { - beam_segment.damages.enemy.unwrap() - } else if same_group && beam_segment.damages.group.is_some() { - beam_segment.damages.group.unwrap() + let damage = if let Some(damage) = beam_segment.damages.get_damage(same_group) { + damage } else { continue; }; @@ -182,7 +180,7 @@ impl<'a> System<'a> for Sys { let change = damage.modify_damage(block, loadouts.get(b), beam_segment.owner); - if let Damage::Energy(_) = damage { + if matches!(damage, Damage::Healing(_)) { server_emitter.emit(ServerEvent::Damage { uid: *uid_b, change, @@ -205,21 +203,18 @@ impl<'a> System<'a> for Sys { EnergySource::HitEnemy, ); } - } - if let Damage::Healing(_) = damage { - if let Some(energy_mut) = beam_owner.and_then(|o| energies.get_mut(o)) { - if energy_mut - .try_change_by( - -(beam_segment.energy_cost as i32), // Stamina use - EnergySource::Ability, - ) - .is_ok() - { - server_emitter.emit(ServerEvent::Damage { - uid: *uid_b, - change, - }); - } + } else if let Some(energy_mut) = beam_owner.and_then(|o| energies.get_mut(o)) { + if energy_mut + .try_change_by( + -(beam_segment.energy_cost as i32), // Stamina use + EnergySource::Ability, + ) + .is_ok() + { + server_emitter.emit(ServerEvent::Damage { + uid: *uid_b, + change, + }); } } // Adds entities that were hit to the hit_entities list on the beam, sees if it diff --git a/common/src/sys/melee.rs b/common/src/sys/melee.rs index 35b77e8b61..b974ca6bd4 100644 --- a/common/src/sys/melee.rs +++ b/common/src/sys/melee.rs @@ -11,7 +11,6 @@ use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage} use std::time::Duration; use vek::*; -pub const BLOCK_EFFICIENCY: f32 = 0.9; pub const BLOCK_ANGLE: f32 = 180.0; /// This system is responsible for handling accepted inputs like moving or @@ -111,10 +110,8 @@ impl<'a> System<'a> for Sys { .map(|group_a| Some(group_a) == groups.get(b)) .unwrap_or(false); - let damage = if !same_group && attack.damages.enemy.is_some() { - attack.damages.enemy.unwrap() - } else if same_group && attack.damages.group.is_some() { - attack.damages.group.unwrap() + let damage = if let Some(damage) = attack.damages.get_damage(same_group) { + damage } else { continue; }; @@ -152,10 +149,10 @@ impl<'a> System<'a> for Sys { if change.amount != 0 { let kb_dir = Dir::new((pos_b.0 - pos.0).try_normalized().unwrap_or(*ori.0)); - server_emitter.emit(ServerEvent::Knockback { - entity: b, - impulse: attack.knockback.get_knockback(kb_dir), - }); + let impulse = attack.knockback.calculate_impulse(kb_dir); + if !impulse.is_approx_zero() { + server_emitter.emit(ServerEvent::Knockback { entity: b, impulse }); + } } } } diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index 725919c551..cfae192ec9 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -100,10 +100,8 @@ impl<'a> System<'a> for Sys { if Some(other) == projectile.owner { continue; } - let damage = if !same_group && damages.enemy.is_some() { - damages.enemy.unwrap() - } else if same_group && damages.group.is_some() { - damages.group.unwrap() + let damage = if let Some(damage) = damages.get_damage(same_group) { + damage } else { continue; }; @@ -121,10 +119,11 @@ impl<'a> System<'a> for Sys { if let Some(entity) = uid_allocator.retrieve_entity_internal(other.into()) { - local_emitter.emit(LocalEvent::ApplyImpulse { - entity, - impulse: knockback.get_knockback(ori.0), - }); + let impulse = knockback.calculate_impulse(ori.0); + if !impulse.is_approx_zero() { + local_emitter + .emit(LocalEvent::ApplyImpulse { entity, impulse }); + } } }, projectile::Effect::RewardEnergy(energy) => { diff --git a/common/src/sys/shockwave.rs b/common/src/sys/shockwave.rs index 35a24691a7..0da87146bf 100644 --- a/common/src/sys/shockwave.rs +++ b/common/src/sys/shockwave.rs @@ -192,10 +192,8 @@ impl<'a> System<'a> for Sys { && (!shockwave.requires_ground || physics_state_b.on_ground); if hit { - let damage = if !same_group && shockwave.damages.enemy.is_some() { - shockwave.damages.enemy.unwrap() - } else if same_group && shockwave.damages.group.is_some() { - shockwave.damages.group.unwrap() + let damage = if let Some(damage) = shockwave.damages.get_damage(same_group) { + damage } else { continue; }; @@ -213,10 +211,10 @@ impl<'a> System<'a> for Sys { }); shockwave_hit_list.hit_entities.push(*uid_b); let kb_dir = Dir::new((pos_b.0 - pos.0).try_normalized().unwrap_or(*ori.0)); - server_emitter.emit(ServerEvent::Knockback { - entity: b, - impulse: shockwave.knockback.get_knockback(kb_dir), - }); + let impulse = shockwave.knockback.calculate_impulse(kb_dir); + if !impulse.is_approx_zero() { + server_emitter.emit(ServerEvent::Knockback { entity: b, impulse }); + } } } }