veloren_common/comp/
combo.rs

1use serde::{Deserialize, Serialize};
2use specs::{Component, DerefFlaggedStorage, VecStorage};
3
4pub const COMBO_DECAY_START: f64 = 7.5; // seconds
5
6#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
7pub struct Combo {
8    counter: u32,
9    last_increase: f64,
10}
11
12impl Default for Combo {
13    fn default() -> Self {
14        Self {
15            counter: 0,
16            last_increase: 0.0,
17        }
18    }
19}
20
21impl Combo {
22    pub fn counter(&self) -> u32 { self.counter }
23
24    pub fn last_increase(&self) -> f64 { self.last_increase }
25
26    pub fn reset(&mut self) { self.counter = 0; }
27
28    pub fn change_by(&mut self, amount: i32, time: f64) {
29        self.counter = if amount > 0 {
30            self.counter.saturating_add(amount as u32)
31        } else {
32            self.counter.saturating_sub(amount.unsigned_abs())
33        };
34        self.last_increase = time;
35    }
36}
37
38impl Component for Combo {
39    type Storage = DerefFlaggedStorage<Self, VecStorage<Self>>;
40}