roguelike/src/healing_system.rs

20 lines
496 B
Rust
Raw Normal View History

2022-01-29 00:31:00 +01:00
use specs::prelude::*;
2022-01-29 14:14:34 +01:00
use crate::{CombatStats, Heals};
2022-01-29 00:31:00 +01:00
pub struct HealingSystem {}
impl<'a> System<'a> for HealingSystem {
2022-01-29 00:31:16 +01:00
type SystemData = (WriteStorage<'a, Heals>, WriteStorage<'a, CombatStats>);
2022-01-29 00:31:00 +01:00
fn run(&mut self, data: Self::SystemData) {
let (mut heals, mut stats) = data;
for (heal, mut stats) in (&heals, &mut stats).join() {
stats.hp = i32::min(stats.max_hp, stats.hp + heal.amount.iter().sum::<i32>());
}
heals.clear();
}
2022-01-29 00:31:16 +01:00
}