From 87d825276e39dece170ee1fd6a7fa570f7cc149c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 19 Nov 2021 11:31:27 -0500 Subject: [PATCH] Finish section 3.4 --- src/melee_combat_system.rs | 11 ++++++++++- src/player.rs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/melee_combat_system.rs b/src/melee_combat_system.rs index 0a5b5b0..1f02cd1 100644 --- a/src/melee_combat_system.rs +++ b/src/melee_combat_system.rs @@ -1,5 +1,6 @@ use crate::components::{ - CombatStats, DefenseBonus, Equipped, MeleePowerBonus, Name, SufferDamage, WantsToMelee, + CombatStats, DefenseBonus, Equipped, HungerClock, HungerState, MeleePowerBonus, Name, + SufferDamage, WantsToMelee, }; use crate::{game_log::GameLog, particle_system::ParticleBuilder, Position}; use rltk::RGB; @@ -21,6 +22,7 @@ impl<'a> System<'a> for MeleeCombatSystem { ReadStorage<'a, Equipped>, WriteExpect<'a, ParticleBuilder>, ReadStorage<'a, Position>, + ReadStorage<'a, HungerClock>, ); fn run(&mut self, data: Self::SystemData) { @@ -36,6 +38,7 @@ impl<'a> System<'a> for MeleeCombatSystem { equipped, mut particle_builder, positions, + hunger_clock, ) = data; for (entity, wants_melee, name, stats) in @@ -51,6 +54,12 @@ impl<'a> System<'a> for MeleeCombatSystem { } } + if let Some(hc) = hunger_clock.get(entity) { + if hc.state == HungerState::WellFed { + offensive_bonus += 1; + } + } + let target_stats = combat_stats.get(wants_melee.target).unwrap(); if target_stats.hp > 0 { let target_name = names.get(wants_melee.target).unwrap(); diff --git a/src/player.rs b/src/player.rs index 908fde9..1fb9ead 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,5 +1,6 @@ use crate::components::{ - CombatStats, Item, Monster, Player, Position, Viewshed, WantsToMelee, WantsToPickupItem, + CombatStats, HungerClock, HungerState, Item, Monster, Player, Position, Viewshed, WantsToMelee, + WantsToPickupItem, }; use crate::{game_log::GameLog, Map, RunState, State, TileType}; use rltk::{Point, Rltk, VirtualKeyCode}; @@ -125,6 +126,16 @@ fn skip_turn(ecs: &mut World) -> RunState { } } + // Don't allow healing when hungry or starving + let hunger_clocks = ecs.read_storage::(); + if let Some(hc) = hunger_clocks.get(*player_entity) { + match hc.state { + HungerState::Hungry => can_heal = false, + HungerState::Starving => can_heal = false, + _ => {} + } + } + if can_heal { let mut health_components = ecs.write_storage::(); let player_hp = health_components.get_mut(*player_entity).unwrap();