mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat: tick_attack utils
This commit is contained in:
parent
eea7eead2e
commit
0b92cc5732
@ -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<f32>,
|
||||
) -> Option<Duration> {
|
||||
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<f32>,
|
||||
) -> 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.
|
||||
|
Loading…
Reference in New Issue
Block a user