Now you can heal yourself.
This commit is contained in:
parent
e03a63f9fb
commit
f19c1dbb20
6 changed files with 68 additions and 14 deletions
27
systems.cpp
27
systems.cpp
|
@ -590,3 +590,30 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
|
|||
|
||||
render.display();
|
||||
}
|
||||
|
||||
bool System::use_item(GameLevel& level, Entity what) {
|
||||
auto& world = *level.world;
|
||||
auto& inventory = world.get<inventory::Model>(level.player);
|
||||
auto& player_combat = world.get<Combat>(level.player);
|
||||
|
||||
if(player_combat.hp >= player_combat.max_hp) return false;
|
||||
|
||||
if(auto curative = world.get_if<Curative>(what)) {
|
||||
inventory.remove(what);
|
||||
|
||||
player_combat.hp += curative->hp;
|
||||
|
||||
if(player_combat.hp > player_combat.max_hp) {
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
}
|
||||
|
||||
dbc::log(fmt::format("player health now {}",
|
||||
player_combat.hp));
|
||||
|
||||
world.remove<Curative>(what);
|
||||
return true;
|
||||
} else {
|
||||
dbc::log(fmt::format("no usable item at {}", what));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue