Add hunger: Reformat
This commit is contained in:
parent
74c05f97af
commit
fdeabefd75
@ -127,7 +127,6 @@ impl Heals {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component, Debug, Clone, ConvertSaveload)]
|
||||
pub struct Ranged {
|
||||
pub range: i32,
|
||||
@ -212,6 +211,5 @@ pub struct HungerClock {
|
||||
pub duration: i32,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProvidesFood {}
|
||||
|
35
src/gui.rs
35
src/gui.rs
@ -1,14 +1,14 @@
|
||||
use rltk::{Point, VirtualKeyCode};
|
||||
use rltk::RGB;
|
||||
use rltk::Rltk;
|
||||
use rltk::RGB;
|
||||
use rltk::{Point, VirtualKeyCode};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{HungerClock, HungerState, HungerSystem, Name};
|
||||
use crate::{CombatStats, InBackpack, RunState, State, Viewshed};
|
||||
use crate::{Equipped, Map};
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::Player;
|
||||
use crate::Position;
|
||||
use crate::{CombatStats, InBackpack, RunState, State, Viewshed};
|
||||
use crate::{Equipped, Map};
|
||||
use crate::{HungerClock, HungerState, HungerSystem, Name};
|
||||
|
||||
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||
ctx.draw_box(
|
||||
@ -46,14 +46,31 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||
);
|
||||
|
||||
match hc.state {
|
||||
HungerState::WellFed => ctx.print_color(71, 42, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "Well Fed"),
|
||||
HungerState::WellFed => ctx.print_color(
|
||||
71,
|
||||
42,
|
||||
RGB::named(rltk::GREEN),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Well Fed",
|
||||
),
|
||||
HungerState::Normal => {}
|
||||
HungerState::Hungry => ctx.print_color(71, 42, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "Hungry"),
|
||||
HungerState::Starving => ctx.print_color(71, 42, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Starving"),
|
||||
HungerState::Hungry => ctx.print_color(
|
||||
71,
|
||||
42,
|
||||
RGB::named(rltk::ORANGE),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Hungry",
|
||||
),
|
||||
HungerState::Starving => ctx.print_color(
|
||||
71,
|
||||
42,
|
||||
RGB::named(rltk::RED),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Starving",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let mut y = 44;
|
||||
for s in log.entries.iter().rev() {
|
||||
if y < 49 {
|
||||
|
@ -5,10 +5,7 @@ use crate::{CombatStats, GameLog, Heals};
|
||||
pub struct HealingSystem {}
|
||||
|
||||
impl<'a> System<'a> for HealingSystem {
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Heals>,
|
||||
WriteStorage<'a, CombatStats>,
|
||||
);
|
||||
type SystemData = (WriteStorage<'a, Heals>, WriteStorage<'a, CombatStats>);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (mut heals, mut stats) = data;
|
||||
@ -19,4 +16,4 @@ impl<'a> System<'a> for HealingSystem {
|
||||
|
||||
heals.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{GameLog, Heals, HungerClock, HungerState, ProvidesHealing, RunState, SufferDamage};
|
||||
use crate::spawner::player;
|
||||
use crate::{GameLog, Heals, HungerClock, HungerState, ProvidesHealing, RunState, SufferDamage};
|
||||
|
||||
pub struct HungerSystem {}
|
||||
|
||||
@ -13,19 +13,36 @@ impl<'a> System<'a> for HungerSystem {
|
||||
ReadExpect<'a, RunState>,
|
||||
WriteStorage<'a, SufferDamage>,
|
||||
WriteExpect<'a, GameLog>,
|
||||
WriteStorage<'a, Heals>
|
||||
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;
|
||||
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 entity == *player_entity {
|
||||
proceed = true;
|
||||
}
|
||||
}
|
||||
RunState::MonsterTurn => {
|
||||
if entity != *player_entity {
|
||||
proceed = true;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
proceed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if !proceed {
|
||||
@ -42,7 +59,9 @@ impl<'a> System<'a> for HungerSystem {
|
||||
clock.state = HungerState::Normal;
|
||||
clock.duration = 200;
|
||||
if entity == *player_entity {
|
||||
game_log.entries.push("You are no longer well-feed".to_string())
|
||||
game_log
|
||||
.entries
|
||||
.push("You are no longer well-feed".to_string())
|
||||
}
|
||||
}
|
||||
HungerState::Normal => {
|
||||
@ -61,11 +80,13 @@ impl<'a> System<'a> for HungerSystem {
|
||||
}
|
||||
HungerState::Starving => {
|
||||
if entity == *player_entity {
|
||||
game_log.entries.push("Your hunger pangs are getting painful".to_string())
|
||||
game_log
|
||||
.entries
|
||||
.push("Your hunger pangs are getting painful".to_string())
|
||||
}
|
||||
SufferDamage::new_damage(&mut suffer_damage, entity, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{AreaOfEffect, CombatStats, Confusion, Consumable, Equippable, Equipped, HungerClock, HungerState, InBackpack, InflictsDamage, Map, Name, Position, ProvidesFood, ProvidesHealing, Ranged, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToRemoveItem, WantsToUseItem};
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::particle_system::ParticleBuilder;
|
||||
use crate::{
|
||||
AreaOfEffect, CombatStats, Confusion, Consumable, Equippable, Equipped, HungerClock,
|
||||
HungerState, InBackpack, InflictsDamage, Map, Name, Position, ProvidesFood, ProvidesHealing,
|
||||
Ranged, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToRemoveItem, WantsToUseItem,
|
||||
};
|
||||
|
||||
pub struct ItemCollectionSystem {}
|
||||
|
||||
@ -94,7 +98,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
||||
mut particle_builder,
|
||||
positions,
|
||||
provides_food,
|
||||
mut hunger_clocks
|
||||
mut hunger_clocks,
|
||||
) = data;
|
||||
|
||||
for (entity, use_item) in (&entities, &wants_use).join() {
|
||||
@ -144,7 +148,10 @@ impl<'a> System<'a> for ItemUseSystem {
|
||||
if let Some(hc) = hunger_clocks.get_mut(target) {
|
||||
hc.state = HungerState::WellFed;
|
||||
hc.duration = 20;
|
||||
game_log.entries.push(format!("You eat the {}.", names.get(use_item.item).unwrap().name));
|
||||
game_log.entries.push(format!(
|
||||
"You eat the {}.",
|
||||
names.get(use_item.item).unwrap().name
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ mod components;
|
||||
mod damage_system;
|
||||
mod gamelog;
|
||||
mod gui;
|
||||
mod healing_system;
|
||||
mod hunger_system;
|
||||
mod inventory_system;
|
||||
mod map;
|
||||
mod map_indexing_system;
|
||||
@ -37,8 +39,6 @@ mod rect;
|
||||
mod save_load_system;
|
||||
mod spawner;
|
||||
mod visibility_system;
|
||||
mod hunger_system;
|
||||
mod healing_system;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
pub enum RunState {
|
||||
|
@ -1,9 +1,9 @@
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{DefenseBonus, Equipped, HungerClock, HungerState, MeleePowerBonus, Position};
|
||||
use crate::components::{CombatStats, Name, SufferDamage, WantsToMelee};
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::particle_system::ParticleBuilder;
|
||||
use crate::{DefenseBonus, Equipped, HungerClock, HungerState, MeleePowerBonus, Position};
|
||||
|
||||
pub struct MeleeCombatSystem {}
|
||||
|
||||
@ -21,7 +21,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
||||
ReadStorage<'a, Equipped>,
|
||||
WriteExpect<'a, ParticleBuilder>,
|
||||
ReadStorage<'a, Position>,
|
||||
ReadStorage<'a, HungerClock>
|
||||
ReadStorage<'a, HungerClock>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
@ -37,11 +37,11 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
||||
equipped,
|
||||
mut particle_builder,
|
||||
positions,
|
||||
hunger_clock
|
||||
hunger_clock,
|
||||
) = data;
|
||||
|
||||
for (entity, wants_melee, name, stats) in
|
||||
(&entities, &wants_melee, &names, &combat_stats).join()
|
||||
(&entities, &wants_melee, &names, &combat_stats).join()
|
||||
{
|
||||
if stats.hp <= 0 {
|
||||
continue;
|
||||
@ -49,7 +49,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
||||
|
||||
let mut offensive_bonus = 0;
|
||||
for (_item_entity, power_bonus, equipped_by) in
|
||||
(&entities, &melee_bonus, &equipped).join()
|
||||
(&entities, &melee_bonus, &equipped).join()
|
||||
{
|
||||
if equipped_by.owner == entity {
|
||||
offensive_bonus += power_bonus.power;
|
||||
@ -68,7 +68,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
|
||||
|
||||
let mut defensive_bonus = 0;
|
||||
for (_item_entity, defense_bonus, equipped_by) in
|
||||
(&entities, &defense_bonus, &equipped).join()
|
||||
(&entities, &defense_bonus, &equipped).join()
|
||||
{
|
||||
if equipped_by.owner == wants_melee.target {
|
||||
defensive_bonus += defense_bonus.defense;
|
||||
|
@ -1,12 +1,12 @@
|
||||
use rltk::Point;
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::particle_system::ParticleBuilder;
|
||||
use crate::{
|
||||
components::{Monster, Position, Viewshed, WantsToMelee},
|
||||
Confusion,
|
||||
map::Map, RunState,
|
||||
map::Map,
|
||||
Confusion, RunState,
|
||||
};
|
||||
use crate::particle_system::ParticleBuilder;
|
||||
|
||||
pub struct MonsterAI {}
|
||||
|
||||
@ -23,7 +23,7 @@ impl<'a> System<'a> for MonsterAI {
|
||||
WriteStorage<'a, Position>,
|
||||
WriteStorage<'a, WantsToMelee>,
|
||||
WriteStorage<'a, Confusion>,
|
||||
WriteExpect<'a, ParticleBuilder>
|
||||
WriteExpect<'a, ParticleBuilder>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
@ -38,7 +38,7 @@ impl<'a> System<'a> for MonsterAI {
|
||||
mut position,
|
||||
mut wants_to_melee,
|
||||
mut confused,
|
||||
mut particle_builder
|
||||
mut particle_builder,
|
||||
) = data;
|
||||
|
||||
if *runstate != RunState::MonsterTurn {
|
||||
@ -46,7 +46,7 @@ impl<'a> System<'a> for MonsterAI {
|
||||
}
|
||||
|
||||
for (entity, mut viewshed, _monster, mut pos) in
|
||||
(&entities, &mut viewshed, &monster, &mut position).join()
|
||||
(&entities, &mut viewshed, &monster, &mut position).join()
|
||||
{
|
||||
let mut can_act = true;
|
||||
|
||||
@ -57,7 +57,14 @@ impl<'a> System<'a> for MonsterAI {
|
||||
}
|
||||
can_act = false;
|
||||
|
||||
particle_builder.request(pos.x, pos.y, rltk::RGB::named(rltk::MAGENTA), rltk::RGB::named(rltk::BLACK), rltk::to_cp437('?'), 200.);
|
||||
particle_builder.request(
|
||||
pos.x,
|
||||
pos.y,
|
||||
rltk::RGB::named(rltk::MAGENTA),
|
||||
rltk::RGB::named(rltk::BLACK),
|
||||
rltk::to_cp437('?'),
|
||||
200.,
|
||||
);
|
||||
}
|
||||
|
||||
if !can_act {
|
||||
|
@ -3,9 +3,13 @@ use std::cmp::{max, min};
|
||||
use rltk::{Point, Rltk, VirtualKeyCode};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{components::{CombatStats, Player, Position, Viewshed, WantsToMelee}, HungerClock, HungerState, Item, map::Map, Monster, RunState, State, TileType, WantsToPickupItem};
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::spawner::player;
|
||||
use crate::{
|
||||
components::{CombatStats, Player, Position, Viewshed, WantsToMelee},
|
||||
map::Map,
|
||||
HungerClock, HungerState, Item, Monster, RunState, State, TileType, WantsToPickupItem,
|
||||
};
|
||||
|
||||
pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
||||
let mut positions = ecs.write_storage::<Position>();
|
||||
@ -17,7 +21,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
||||
let map = ecs.fetch::<Map>();
|
||||
|
||||
for (entity, _player, pos, viewshed) in
|
||||
(&entities, &mut players, &mut positions, &mut viewsheds).join()
|
||||
(&entities, &mut players, &mut positions, &mut viewsheds).join()
|
||||
{
|
||||
if pos.x + delta_x < 1
|
||||
|| pos.x + delta_x > map.width - 1
|
||||
@ -139,8 +143,12 @@ fn skip_turn(ecs: &mut World) -> RunState {
|
||||
let mut heal_bonus = 0;
|
||||
if let Some(hc) = hunger_clock.get(*player_entity) {
|
||||
match hc.state {
|
||||
HungerState::Hungry | HungerState::Starving => {can_heal = false;}
|
||||
HungerState::WellFed => {heal_bonus = 1;}
|
||||
HungerState::Hungry | HungerState::Starving => {
|
||||
can_heal = false;
|
||||
}
|
||||
HungerState::WellFed => {
|
||||
heal_bonus = 1;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,14 @@ use rltk::{FontCharType, RandomNumberGenerator, RGB};
|
||||
use specs::prelude::*;
|
||||
use specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||
|
||||
use crate::{AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, DefenseBonus, EquipmentSlot, Equippable, HungerClock, HungerState, InflictsDamage, Item, MAP_WIDTH, MAX_MONSTER, MeleePowerBonus, Monster, Name, Player, Position, ProvidesFood, ProvidesHealing, Ranged, Renderable, SerializeMe, Viewshed};
|
||||
use crate::random_table::RandomTable;
|
||||
use crate::rect::Rect;
|
||||
use crate::{
|
||||
AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, DefenseBonus, EquipmentSlot,
|
||||
Equippable, HungerClock, HungerState, InflictsDamage, Item, MeleePowerBonus, Monster, Name,
|
||||
Player, Position, ProvidesFood, ProvidesHealing, Ranged, Renderable, SerializeMe, Viewshed,
|
||||
MAP_WIDTH, MAX_MONSTER,
|
||||
};
|
||||
|
||||
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
ecs.create_entity()
|
||||
@ -400,7 +405,6 @@ fn sabatons(ecs: &mut World, x: i32, y: i32) {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
fn rations(ecs: &mut World, x: i32, y: i32) {
|
||||
ecs.create_entity()
|
||||
.with(Position { x, y })
|
||||
@ -414,8 +418,8 @@ fn rations(ecs: &mut World, x: i32, y: i32) {
|
||||
.with(Name {
|
||||
name: "Rations".to_string(),
|
||||
})
|
||||
.with(Consumable{})
|
||||
.with(ProvidesFood{})
|
||||
.with(Consumable {})
|
||||
.with(ProvidesFood {})
|
||||
.marked::<SimpleMarker<SerializeMe>>()
|
||||
.build();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user