diff --git a/common/src/comp/stats.rs b/common/src/comp/stats.rs index def733e988..9c47b9a439 100644 --- a/common/src/comp/stats.rs +++ b/common/src/comp/stats.rs @@ -1,16 +1,17 @@ use specs::{Component, FlaggedStorage, NullStorage, VecStorage}; +use crate::state::Time; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Health { pub current: u32, pub maximum: u32, - pub last_change: Option<(i32, f64)>, + pub last_change: Option<(i32, Time)>, } impl Health { - pub fn change_by(&mut self, amount: i32, current_time: f64) { + pub fn change_by(&mut self, amount: i32, current_time: Time) { self.current = (self.current as i32 + amount).max(0) as u32; - self.last_change = Some((amount, current_time)); + self.last_change = dbg!(Some((amount, current_time))); } } diff --git a/common/src/state.rs b/common/src/state.rs index e42e78ed9a..a68687639a 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -28,7 +28,7 @@ const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0; pub struct TimeOfDay(f64); /// A resource that stores the tick (i.e: physics) time. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct Time(f64); /// A resource that stores the time since the previous tick. diff --git a/common/src/sys/action.rs b/common/src/sys/action.rs index e82bb67d95..2178c1f8fc 100644 --- a/common/src/sys/action.rs +++ b/common/src/sys/action.rs @@ -5,7 +5,7 @@ use vek::*; // Crate use crate::{ comp::{phys::Pos, Action, Actions, Control, Stats}, - state::DeltaTime, + state::{Time, DeltaTime}, }; // Basic ECS AI agent system @@ -14,13 +14,14 @@ pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, + Read<'a, Time>, Read<'a, DeltaTime>, WriteStorage<'a, Actions>, ReadStorage<'a, Pos>, WriteStorage<'a, Stats>, ); - fn run(&mut self, (entities, dt, mut actions, positions, mut stats): Self::SystemData) { + fn run(&mut self, (entities, time, dt, mut actions, positions, mut stats): Self::SystemData) { for (a, mut actions_a, pos_a) in (&entities, &mut actions, &positions).join() { for event in actions_a.0.drain(..) { match event { @@ -30,7 +31,7 @@ impl<'a> System<'a> for Sys { continue; } if pos_a.0.distance_squared(pos_b.0) < 50.0 { - &mut stat_b.hp.change_by(-60, 0.0); // TODO: variable damage and current time + &mut stat_b.hp.change_by(-60, *time); // TODO: variable damage &stat_b.hp; } }