Limit player to a single weapon at a time

This commit is contained in:
Daniel Lynn 2021-07-11 11:45:36 -05:00
parent b9f8b7ebbe
commit 62d8e1de73

View File

@ -6,6 +6,7 @@ use crate::prelude::*;
#[read_component(Enemy)]
#[read_component(Item)]
#[read_component(Carried)]
#[read_component(Weapon)]
pub fn player_input(
ecs: &mut SubWorld,
commands: &mut CommandBuffer,
@ -32,6 +33,17 @@ pub fn player_input(
.for_each(|(entity, _item, _item_pos)| {
commands.remove_component::<Point>(*entity);
commands.add_component(*entity, Carried(player));
if let Ok(e) = ecs.entry_ref(*entity) {
if e.get_component::<Weapon>().is_ok() {
<(Entity, &Carried, &Weapon)>::query()
.iter(ecs)
.filter(|(_e, c, _w)| c.0 == player)
.for_each(|(e, _c, _w)| {
commands.remove(*e);
});
}
}
});
Point::new(0, 0)