Add hunger
This commit is contained in:
71
src/hunger_system.rs
Normal file
71
src/hunger_system.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{GameLog, Heals, HungerClock, HungerState, ProvidesHealing, RunState, SufferDamage};
|
||||
use crate::spawner::player;
|
||||
|
||||
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, mut 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user