92 lines
2.8 KiB
Rust
92 lines
2.8 KiB
Rust
use specs::prelude::*;
|
|
|
|
use crate::{GameLog, Heals, HungerClock, HungerState, RunState, SufferDamage};
|
|
|
|
pub struct HungerSystem {}
|
|
|
|
impl<'a> System<'a> for HungerSystem {
|
|
type SystemData = (
|
|
Entities<'a>,
|
|
WriteStorage<'a, HungerClock>,
|
|
ReadExpect<'a, Entity>,
|
|
ReadExpect<'a, RunState>,
|
|
WriteStorage<'a, SufferDamage>,
|
|
WriteExpect<'a, GameLog>,
|
|
WriteStorage<'a, Heals>,
|
|
);
|
|
|
|
fn run(&mut self, data: Self::SystemData) {
|
|
let (
|
|
entities,
|
|
mut hunger_clock,
|
|
player_entity,
|
|
run_state,
|
|
mut suffer_damage,
|
|
mut game_log,
|
|
_heals,
|
|
) = data;
|
|
for (entity, mut clock) in (&entities, &mut hunger_clock).join() {
|
|
let mut proceed = false;
|
|
|
|
match *run_state {
|
|
RunState::PlayerTurn => {
|
|
if entity == *player_entity {
|
|
proceed = true;
|
|
}
|
|
}
|
|
RunState::MonsterTurn => {
|
|
if entity != *player_entity {
|
|
proceed = true;
|
|
}
|
|
}
|
|
_ => {
|
|
proceed = false;
|
|
}
|
|
}
|
|
|
|
if !proceed {
|
|
continue;
|
|
}
|
|
|
|
clock.duration -= 1;
|
|
if clock.duration > 0 {
|
|
continue;
|
|
}
|
|
|
|
match clock.state {
|
|
HungerState::WellFed => {
|
|
clock.state = HungerState::Normal;
|
|
clock.duration = 200;
|
|
if entity == *player_entity {
|
|
game_log
|
|
.entries
|
|
.push("You are no longer well-feed".to_string())
|
|
}
|
|
}
|
|
HungerState::Normal => {
|
|
clock.state = HungerState::Hungry;
|
|
clock.duration = 200;
|
|
if entity == *player_entity {
|
|
game_log.entries.push("You are hungry".to_string())
|
|
}
|
|
}
|
|
HungerState::Hungry => {
|
|
clock.state = HungerState::Starving;
|
|
clock.duration = 200;
|
|
if entity == *player_entity {
|
|
game_log.entries.push("You are Starving!".to_string())
|
|
}
|
|
}
|
|
HungerState::Starving => {
|
|
if entity == *player_entity {
|
|
game_log
|
|
.entries
|
|
.push("Your hunger pangs are getting painful".to_string())
|
|
}
|
|
SufferDamage::new_damage(&mut suffer_damage, entity, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|