mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
a6439984be
Former-commit-id: c25f6fb0b594e5d61a965447359536ca17173aa7
56 lines
1.2 KiB
Rust
56 lines
1.2 KiB
Rust
use crate::state::Time;
|
|
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
|
pub struct Health {
|
|
pub current: u32,
|
|
pub maximum: u32,
|
|
pub last_change: Option<(i32, f64)>,
|
|
}
|
|
|
|
impl Health {
|
|
pub fn change_by(&mut self, amount: i32) {
|
|
self.current = (self.current as i32 + amount).max(0) as u32;
|
|
self.last_change = Some((amount, 0.0));
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
|
pub struct Stats {
|
|
pub hp: Health,
|
|
pub xp: u32,
|
|
pub is_dead: bool,
|
|
}
|
|
|
|
impl Stats {
|
|
pub fn should_die(&self) -> bool {
|
|
// TODO: Remove
|
|
self.hp.current == 0
|
|
}
|
|
}
|
|
|
|
impl Default for Stats {
|
|
fn default() -> Self {
|
|
Self {
|
|
hp: Health {
|
|
current: 100,
|
|
maximum: 100,
|
|
last_change: None,
|
|
},
|
|
xp: 0,
|
|
is_dead: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Component for Stats {
|
|
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
|
pub struct Dying;
|
|
|
|
impl Component for Dying {
|
|
type Storage = NullStorage<Self>;
|
|
}
|