diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 26f5827dfa..90bb912310 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -764,12 +764,30 @@ pub fn input_is_pressed(data: &JoinData, input: InputKind) -> bool { data.controller.queued_inputs.contains_key(&input) } -pub fn tick_attack_duraction(data: &JoinData, timer: Duration) -> Duration { - timer - .checked_add(data.dt.0 * data.stats.attack_speed_modifier) - .unwrap_or_default() -} +/// Checked `Duration` addition. Computes `timer` + `dt`, applying relevant stat +/// attack modifiers and `other_modifiers`, returning None if overflow occurred. +pub fn checked_tick_attack( + data: &JoinData, + timer: Duration, + other_modifier: Option, +) -> Option { + let tick_dur = if let Some(other_mod) = other_modifier { + data.dt.0 * data.stats.attack_speed_modifier * other_mod + } else { + data.dt.0 * data.stats.attack_speed_modifier + }; + timer.checked_add(Duration::from_secs_f32(tick_dur)) +} +/// Ticks `timer` by `dt`, applying relevant stat attack modifiers and +/// `other_modifier`. Returns `Duration::default()` if overflow occurs +pub fn tick_attack_or_default( + data: &JoinData, + timer: Duration, + other_modifier: Option, +) -> Duration { + checked_tick_attack(data, timer, other_modifier).unwrap_or_default() +} /// 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.