84 lines
2.8 KiB
Rust
84 lines
2.8 KiB
Rust
use specs::prelude::*;
|
|
|
|
use crate::components::{HungerClock, HungerState, SufferDamage};
|
|
use crate::game_log::GameLog;
|
|
use crate::RunState;
|
|
|
|
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
|
|
ReadExpect<'a, RunState>,
|
|
WriteStorage<'a, SufferDamage>,
|
|
WriteExpect<'a, GameLog>,
|
|
);
|
|
|
|
fn run(&mut self, data: Self::SystemData) {
|
|
let (entities, mut hunger_clock, player_entity, runstate, mut inflict_damage, mut log) =
|
|
data;
|
|
|
|
for (entity, mut clock) in (&entities, &mut hunger_clock).join() {
|
|
let mut proceed = false;
|
|
|
|
match *runstate {
|
|
RunState::PlayerTurn => {
|
|
if entity == *player_entity {
|
|
proceed = true;
|
|
}
|
|
}
|
|
RunState::MonsterTurn => {
|
|
if entity != *player_entity {
|
|
proceed = true;
|
|
}
|
|
}
|
|
_ => proceed = false,
|
|
}
|
|
|
|
if proceed {
|
|
clock.duration -= 1;
|
|
|
|
if clock.duration < 1 {
|
|
match clock.state {
|
|
HungerState::WellFed => {
|
|
clock.state = HungerState::Normal;
|
|
clock.duration = 200;
|
|
|
|
if entity == *player_entity {
|
|
log.append("You are no longer well fed.");
|
|
}
|
|
}
|
|
HungerState::Normal => {
|
|
clock.state = HungerState::Hungry;
|
|
clock.duration = 200;
|
|
|
|
if entity == *player_entity {
|
|
log.append("You are hungry.");
|
|
}
|
|
}
|
|
HungerState::Hungry => {
|
|
clock.state = HungerState::Starving;
|
|
clock.duration = 200;
|
|
|
|
if entity == *player_entity {
|
|
log.append("You are starving!");
|
|
}
|
|
}
|
|
HungerState::Starving => {
|
|
// Inflict damage from hunger
|
|
if entity == *player_entity {
|
|
log.append("Your hunger pangs are getting painful!");
|
|
}
|
|
|
|
SufferDamage::new_damage(&mut inflict_damage, entity, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|