blob: 6535a757aa7df9c6e7424b25e88ddbf1b0f709e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use specs::{
WriteStorage,
System,
Join
};
use crate::{
components::{Health, Attacked},
util
};
pub struct Attacking;
impl <'a> System<'a> for Attacking {
type SystemData = (
WriteStorage<'a, Attacked>,
WriteStorage<'a, Health>
);
fn run(&mut self, (mut victims, mut healths): Self::SystemData) {
for (health, attacked) in (&mut healths, &mut victims).join() {
for attack in attacked.attacks.drain(..) {
health.health -= attack.damage;
}
health.health = util::clamp(health.health, 0, health.maxhealth);
}
victims.clear();
}
}
|