2019-05-19 17:58:32 +00:00
|
|
|
use crate::state::Time;
|
2019-05-19 18:22:45 +00:00
|
|
|
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
|
2019-05-13 13:58:01 +00:00
|
|
|
|
2019-05-25 22:00:38 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
2019-05-13 13:58:01 +00:00
|
|
|
pub struct Health {
|
|
|
|
pub current: u32,
|
|
|
|
pub maximum: u32,
|
2019-05-19 20:14:18 +00:00
|
|
|
pub last_change: Option<(i32, f64)>,
|
2019-05-13 13:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Health {
|
2019-05-19 20:14:18 +00:00
|
|
|
pub fn change_by(&mut self, amount: i32) {
|
2019-05-13 13:58:01 +00:00
|
|
|
self.current = (self.current as i32 + amount).max(0) as u32;
|
2019-05-19 20:14:18 +00:00
|
|
|
self.last_change = Some((amount, 0.0));
|
2019-05-13 13:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 22:00:38 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
2019-05-13 13:58:01 +00:00
|
|
|
pub struct Stats {
|
|
|
|
pub hp: Health,
|
|
|
|
pub xp: u32,
|
|
|
|
}
|
|
|
|
|
2019-05-25 21:13:38 +00:00
|
|
|
impl Stats {
|
|
|
|
pub fn is_dead(&self) -> bool {
|
|
|
|
self.hp.current == 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 13:58:01 +00:00
|
|
|
impl Default for Stats {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
hp: Health {
|
|
|
|
current: 100,
|
|
|
|
maximum: 100,
|
|
|
|
last_change: None,
|
|
|
|
},
|
|
|
|
xp: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for Stats {
|
|
|
|
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
|
|
|
}
|
2019-05-17 20:47:58 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
|
|
|
pub struct Dying;
|
|
|
|
|
|
|
|
impl Component for Dying {
|
|
|
|
type Storage = NullStorage<Self>;
|
|
|
|
}
|