mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
4696cd2c8b
Former-commit-id: 3227221b12a674f66b011ce0ba734e226f223f34
44 lines
1022 B
Rust
44 lines
1022 B
Rust
// Library
|
|
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
|
use vek::*;
|
|
|
|
// Crate
|
|
use crate::{
|
|
comp::{
|
|
phys::{Dir, Pos, Vel},
|
|
Animation, AnimationInfo, Attacking,
|
|
},
|
|
state::DeltaTime,
|
|
terrain::TerrainMap,
|
|
vol::{ReadVol, Vox},
|
|
};
|
|
|
|
// Basic ECS AI agent system
|
|
pub struct Sys;
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
type SystemData = (
|
|
Entities<'a>,
|
|
Read<'a, DeltaTime>,
|
|
WriteStorage<'a, Attacking>,
|
|
);
|
|
|
|
fn run(&mut self, (entities, dt, mut attackings): Self::SystemData) {
|
|
for (entity, attacking) in (&entities, &mut attackings).join() {
|
|
attacking.time += dt.0;
|
|
}
|
|
|
|
let finished_attack = (&entities, &mut attackings)
|
|
.join()
|
|
.filter(|(e, a)| {
|
|
a.time > 0.5 // TODO: constant
|
|
})
|
|
.map(|(e, a)| e)
|
|
.collect::<Vec<_>>();
|
|
|
|
for entity in finished_attack {
|
|
attackings.remove(entity);
|
|
}
|
|
}
|
|
}
|