diff options
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/fight.rs | 3 | ||||
| -rw-r--r-- | src/systems/heal.rs | 37 | ||||
| -rw-r--r-- | src/systems/mod.rs | 4 | ||||
| -rw-r--r-- | src/systems/trapping.rs | 4 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 5 |
5 files changed, 45 insertions, 8 deletions
diff --git a/src/systems/fight.rs b/src/systems/fight.rs index 4b3c672..d0342b5 100644 --- a/src/systems/fight.rs +++ b/src/systems/fight.rs @@ -13,7 +13,6 @@ use crate::components::{ Controller, Position, Attacked, - add_attack, Fighter, Health }; @@ -42,7 +41,7 @@ impl <'a> System<'a> for Fight { for direction in directions { for ent in ground.cells.get(&(position.pos + direction.to_position())).unwrap_or(&HashSet::new()) { if healths.contains(*ent) && *ent != entity { - add_attack(&mut attacked, *ent, fighter.attack.clone()); + Attacked::add_attack(&mut attacked, *ent, fighter.attack.clone()); break; } } diff --git a/src/systems/heal.rs b/src/systems/heal.rs new file mode 100644 index 0000000..458bc17 --- /dev/null +++ b/src/systems/heal.rs @@ -0,0 +1,37 @@ + +use specs::{ + WriteStorage, + Read, + System, + Join +}; + +use crate::{ + components::{Health, Healing}, + resources::TimeStamp +}; + + +pub struct Heal; +impl <'a> System<'a> for Heal { + type SystemData = ( + WriteStorage<'a, Health>, + WriteStorage<'a, Healing>, + Read<'a, TimeStamp> + ); + fn run(&mut self, (mut healths, mut healing, timestamp): Self::SystemData) { + for (health, mut heal) in (&mut healths, &mut healing).join() { + + if let Some(next_heal) = heal.next_heal { + if next_heal <= timestamp.time { + health.heal(heal.health); + heal.next_heal = None + } + } + if health.health < health.maxhealth && heal.next_heal == None { + heal.next_heal = Some(timestamp.time + heal.delay) + } + } + } +} + diff --git a/src/systems/mod.rs b/src/systems/mod.rs index d73a578..b1d0994 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -11,6 +11,7 @@ mod useitem; mod attacking; mod trapping; mod fight; +mod heal; pub use self::{ controlinput::ControlInput, @@ -24,5 +25,6 @@ pub use self::{ useitem::Use, attacking::Attacking, trapping::Trapping, - fight::Fight + fight::Fight, + heal::Heal }; diff --git a/src/systems/trapping.rs b/src/systems/trapping.rs index 5e0921e..d6902a8 100644 --- a/src/systems/trapping.rs +++ b/src/systems/trapping.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, Attacked, add_attack, Moved, Entered, Trap, Position}, + components::{Health, Attacked, Moved, Entered, Trap, Position}, resources::Ground }; @@ -31,7 +31,7 @@ impl <'a> System<'a> for Trapping { for (entity, _entered, trap, position) in (&entities, &entereds, &traps, &positions).join() { for ent in ground.cells.get(&position.pos).unwrap(){ if ent != &entity && moves.contains(*ent) && healths.contains(*ent) { - add_attack(&mut victims, *ent, trap.attack.clone()); + Attacked::add_attack(&mut victims, *ent, trap.attack.clone()); } } } diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index c9bcfcd..4414b39 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -14,8 +14,7 @@ use crate::{ Controller, Position, Inventory, - Attacked, - add_attack + Attacked }, resources::{NewEntities}, components::item::ItemAction::{None, Build, Eat}, @@ -46,7 +45,7 @@ impl <'a> System<'a> for Use { inventory.items.remove(*rank); } Eat(health_diff) => { - add_attack(&mut attacked, ent, Attack::new(-*health_diff)); + Attacked::add_attack(&mut attacked, ent, Attack::new(-*health_diff)); inventory.items.remove(*rank); } None => {} |
