use std::collections::HashSet; use ::bracket_lib::prelude::*; use ::specs::prelude::*; use crate::components::{Confusion, MyTurn, StatusEffect}; use crate::effects::{add_effect, EffectType, Targets}; use crate::{colors, RunState}; pub struct TurnStatusSystem {} impl<'a> System<'a> for TurnStatusSystem { #[allow(clippy::type_complexity)] type SystemData = ( WriteStorage<'a, MyTurn>, ReadStorage<'a, Confusion>, Entities<'a>, ReadExpect<'a, RunState>, ReadStorage<'a, StatusEffect>, ); fn run(&mut self, data: Self::SystemData) { let (mut turns, confusion, entities, runstate, statuses) = data; if *runstate != RunState::Ticking { return; } // Collect a set of all entities whose turn it is let mut entity_turns = HashSet::new(); for (entity, _turn) in (&entities, &turns).join() { entity_turns.insert(entity); } // Find status effects affecting entities whose turn it is let mut not_my_turn: Vec = Vec::new(); for (effect_entity, status_effect) in (&entities, &statuses).join() { if entity_turns.contains(&status_effect.target) { // Skip turn for confusion if confusion.get(effect_entity).is_some() { add_effect( None, EffectType::Particle { glyph: to_cp437('?'), fg: colors::CYAN, bg: colors::BLACK, lifespan: 200.0, }, Targets::Single { target: status_effect.target, }, ); not_my_turn.push(status_effect.target); } } } for e in not_my_turn { turns.remove(e); } } }