A few more fixes for how Combat works.
This commit is contained in:
parent
2a92687bc9
commit
54d0a41c52
3 changed files with 7 additions and 20 deletions
|
|
@ -303,7 +303,7 @@ void System::collision() {
|
|||
for(auto entity : nearby) {
|
||||
if(world.has<Combat>(entity)) {
|
||||
auto combat = world.get<Combat>(entity);
|
||||
if(!combat.is_dead()) {
|
||||
if(!combat.has_died) {
|
||||
combat_count++;
|
||||
world.send<game::Event>(game::Event::COMBAT_START, entity, entity);
|
||||
}
|
||||
|
|
@ -603,34 +603,22 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
|
|||
render.display();
|
||||
}
|
||||
|
||||
bool System::use_item(const string& slot_name) {
|
||||
void System::use_item(const string& slot_name) {
|
||||
auto& level = GameDB::current_level();
|
||||
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(!inventory.has(slot_name)) return false;
|
||||
if(!(player_combat.can_heal() && inventory.has(slot_name))) return;
|
||||
|
||||
auto what = inventory.get(slot_name);
|
||||
|
||||
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($F("player health now {}",
|
||||
player_combat.hp));
|
||||
|
||||
player_combat.apply_healing(*curative);
|
||||
world.remove<Curative>(what);
|
||||
return true;
|
||||
} else {
|
||||
dbc::log($F("no usable item at {}", what));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue