Add turn skipping and healing on skipped turns
This commit is contained in:
parent
f6dc758f12
commit
a51d63963f
@ -1,5 +1,5 @@
|
||||
use crate::components::{
|
||||
CombatStats, Item, Player, Position, Viewshed, WantsToMelee, WantsToPickupItem,
|
||||
CombatStats, Item, Monster, Player, Position, Viewshed, WantsToMelee, WantsToPickupItem,
|
||||
};
|
||||
use crate::{game_log::GameLog, Map, RunState, State, TileType};
|
||||
use rltk::{Point, Rltk, VirtualKeyCode};
|
||||
@ -114,6 +114,9 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState {
|
||||
}
|
||||
}
|
||||
|
||||
// Skip Turn
|
||||
VirtualKeyCode::Numpad5 | VirtualKeyCode::Space => return skip_turn(&mut gs.ecs),
|
||||
|
||||
_ => return RunState::AwaitingInput,
|
||||
},
|
||||
}
|
||||
@ -170,3 +173,33 @@ pub fn try_next_level(ecs: &mut World) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn skip_turn(ecs: &mut World) -> RunState {
|
||||
let player_entity = ecs.fetch::<Entity>();
|
||||
let viewshed_components = ecs.read_storage::<Viewshed>();
|
||||
let monsters = ecs.read_storage::<Monster>();
|
||||
|
||||
let worldmap_resource = ecs.fetch::<Map>();
|
||||
|
||||
let mut can_heal = true;
|
||||
let viewshed = viewshed_components.get(*player_entity).unwrap();
|
||||
for tile in viewshed.visible_tiles.iter() {
|
||||
let idx = worldmap_resource.xy_idx(tile.x, tile.y);
|
||||
for entity_id in worldmap_resource.tile_content[idx].iter() {
|
||||
match monsters.get(*entity_id) {
|
||||
None => {}
|
||||
Some(_) => {
|
||||
can_heal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if can_heal {
|
||||
let mut health_components = ecs.write_storage::<CombatStats>();
|
||||
let player_hp = health_components.get_mut(*player_entity).unwrap();
|
||||
player_hp.hp = i32::min(player_hp.hp + 1, player_hp.max_hp);
|
||||
}
|
||||
|
||||
RunState::PlayerTurn
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user