diff --git a/common/src/states/basic_attack.rs b/common/src/states/basic_attack.rs index b635b657dc..31343305c6 100644 --- a/common/src/states/basic_attack.rs +++ b/common/src/states/basic_attack.rs @@ -21,58 +21,50 @@ pub fn behavior(data: &JoinData) -> StateUpdate { remaining_duration, } = data.character { - handle_move(data, &mut update); - let tool_kind = data.stats.equipment.main.as_ref().map(|i| i.kind); - let can_apply_damage = !*exhausted - && if let Some(Tool(tool)) = tool_kind { - *remaining_duration < tool.attack_recover_duration() - } else { - true - }; + if let Some(Tool(tool)) = tool_kind { + handle_move(data, &mut update); - let mut new_exhausted = *exhausted; + let mut new_exhausted = *exhausted; - if can_apply_damage { - if let Some(Tool(tool)) = tool_kind { + if !*exhausted && *remaining_duration < tool.attack_recover_duration() { data.updater.insert(data.entity, Attacking { weapon: Some(tool), applied: false, hit_count: 0, }); + new_exhausted = true; } - new_exhausted = true; - } - let new_remaining_duration = remaining_duration - .checked_sub(Duration::from_secs_f32(data.dt.0)) - .unwrap_or_default(); + let new_remaining_duration = remaining_duration + .checked_sub(Duration::from_secs_f32(data.dt.0)) + .unwrap_or_default(); - if let Some(attack) = data.attacking { - if attack.applied && attack.hit_count > 0 { - data.updater.remove::(data.entity); - update.energy.change_by(100, EnergySource::HitEnemy); + if let Some(attack) = data.attacking { + if attack.applied && attack.hit_count > 0 { + data.updater.remove::(data.entity); + update.energy.change_by(100, EnergySource::HitEnemy); + } } - } - // Tick down - update.character = CharacterState::BasicAttack { - remaining_duration: new_remaining_duration, - exhausted: new_exhausted, - }; - - // Check if attack duration has expired - if new_remaining_duration == Duration::default() { - update.character = if let Some(Tool(tool)) = tool_kind { - CharacterState::Wielding { tool } - } else { - CharacterState::Idle {} + // Tick down + update.character = CharacterState::BasicAttack { + remaining_duration: new_remaining_duration, + exhausted: new_exhausted, }; - data.updater.remove::(data.entity); - } - update + // Check if attack duration has expired + if new_remaining_duration == Duration::default() { + update.character = CharacterState::Wielding { tool }; + data.updater.remove::(data.entity); + } + + update + } else { + update + } } else { + update.character = CharacterState::Idle {}; update } }