1
0
Fork 0
roguelike-game/src/hunger_system.rs

68 lines
2.3 KiB
Rust
Raw Normal View History

2021-12-24 10:38:44 -05:00
use ::specs::prelude::*;
2021-11-18 10:28:49 -05:00
use crate::colors;
use crate::components::{HungerClock, HungerState, MyTurn};
use crate::effects::{add_effect, EffectType, Targets};
use crate::gamelog::log_color_line;
2021-12-10 20:16:48 -05:00
2021-11-18 10:28:49 -05:00
pub struct HungerSystem {}
impl<'a> System<'a> for HungerSystem {
#[allow(clippy::type_complexity)]
type SystemData = (
Entities<'a>,
WriteStorage<'a, HungerClock>,
ReadExpect<'a, Entity>, // The player
ReadStorage<'a, MyTurn>,
2021-11-18 10:28:49 -05:00
);
fn run(&mut self, data: Self::SystemData) {
let (entities, mut hunger_clock, player_entity, turns) = data;
2021-11-18 10:28:49 -05:00
for (entity, mut clock, _myturn) in (&entities, &mut hunger_clock, &turns).join() {
clock.duration -= 1;
2021-11-18 10:28:49 -05:00
if clock.duration < 1 {
match clock.state {
HungerState::WellFed => {
clock.state = HungerState::Normal;
clock.duration = 200;
2021-11-18 10:28:49 -05:00
if entity == *player_entity {
log_color_line(colors::ORANGE, "You are no longer well fed");
2021-11-18 10:28:49 -05:00
}
}
HungerState::Normal => {
clock.state = HungerState::Hungry;
clock.duration = 200;
2021-11-18 10:28:49 -05:00
if entity == *player_entity {
log_color_line(colors::ORANGE, "You are hungry.");
2021-11-18 10:28:49 -05:00
}
}
HungerState::Hungry => {
clock.state = HungerState::Starving;
clock.duration = 200;
2021-11-18 10:28:49 -05:00
if entity == *player_entity {
log_color_line(colors::RED, "You are starving!");
2021-11-18 10:28:49 -05:00
}
}
HungerState::Starving => {
// Inflict damage from hunger
if entity == *player_entity {
log_color_line(colors::RED, "Your hunger pangs are getting painful!");
2021-11-18 10:28:49 -05:00
}
add_effect(
None,
EffectType::Damage { amount: 1 },
Targets::Single { target: entity },
);
2021-11-18 10:28:49 -05:00
}
}
}
}
}
}