2022-01-24 10:58:37 -05:00
|
|
|
use std::collections::HashSet;
|
|
|
|
|
2022-01-11 10:30:32 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
|
2022-01-24 10:58:37 -05:00
|
|
|
use crate::components::{Confusion, MyTurn, StatusEffect};
|
|
|
|
use crate::effects::{add_effect, EffectType, Targets};
|
|
|
|
use crate::{colors, RunState};
|
2022-01-11 10:30:32 -05:00
|
|
|
|
|
|
|
pub struct TurnStatusSystem {}
|
|
|
|
|
|
|
|
impl<'a> System<'a> for TurnStatusSystem {
|
|
|
|
#[allow(clippy::type_complexity)]
|
|
|
|
type SystemData = (
|
|
|
|
WriteStorage<'a, MyTurn>,
|
2022-01-24 10:58:37 -05:00
|
|
|
ReadStorage<'a, Confusion>,
|
2022-01-11 10:30:32 -05:00
|
|
|
Entities<'a>,
|
|
|
|
ReadExpect<'a, RunState>,
|
2022-01-24 10:58:37 -05:00
|
|
|
ReadStorage<'a, StatusEffect>,
|
2022-01-11 10:30:32 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
fn run(&mut self, data: Self::SystemData) {
|
2022-01-24 10:58:37 -05:00
|
|
|
let (mut turns, confusion, entities, runstate, statuses) = data;
|
2022-01-11 10:30:32 -05:00
|
|
|
|
|
|
|
if *runstate != RunState::Ticking {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:58:37 -05:00
|
|
|
// 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);
|
|
|
|
}
|
2022-01-11 10:30:32 -05:00
|
|
|
|
2022-01-24 10:58:37 -05:00
|
|
|
// Find status effects affecting entities whose turn it is
|
|
|
|
let mut not_my_turn: Vec<Entity> = 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: ::rltk::to_cp437('?'),
|
|
|
|
fg: colors::CYAN,
|
|
|
|
bg: colors::BLACK,
|
|
|
|
lifespan: 200.0,
|
|
|
|
},
|
|
|
|
Targets::Single {
|
|
|
|
target: status_effect.target,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
not_my_turn.push(status_effect.target);
|
|
|
|
}
|
2022-01-11 10:30:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for e in not_my_turn {
|
|
|
|
turns.remove(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|