|
|
@ -66,7 +66,7 @@ void System::motion(DinkyECS::World &world, Map &game_map) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
const auto& collider = world.get<spatial_map>(); |
|
|
|
auto& collider = world.get<spatial_map>(); |
|
|
|
const auto& player_position = world.component<Position>(player.entity); |
|
|
|
const auto& player_position = world.component<Position>(player.entity); |
|
|
|
auto& player_combat = world.component<Combat>(player.entity); |
|
|
|
auto& player_combat = world.component<Combat>(player.entity); |
|
|
|
auto& log = world.get<ActionLog>(); |
|
|
|
auto& log = world.get<ActionLog>(); |
|
|
@ -76,10 +76,21 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
if(found) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
|
|
|
|
auto& enemy_combat = world.component<Combat>(entity); |
|
|
|
|
|
|
|
int player_dmg = Random::uniform<int>(1, enemy_combat.damage); |
|
|
|
|
|
|
|
enemy_combat.hp -= player_dmg; |
|
|
|
|
|
|
|
log.log(format("YOU HIT {} damage! Enemy has {} HP left.", |
|
|
|
|
|
|
|
player_dmg, enemy_combat.hp)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(enemy_combat.hp <= 0) { |
|
|
|
|
|
|
|
log.log("--- ENEMY DEAD!---"); |
|
|
|
|
|
|
|
auto enemy_position = world.component<Position>(entity); |
|
|
|
|
|
|
|
collider.remove(enemy_position.location); |
|
|
|
|
|
|
|
world.remove<Motion>(entity); |
|
|
|
|
|
|
|
} else { |
|
|
|
int attack = Random::uniform<int>(0,1); |
|
|
|
int attack = Random::uniform<int>(0,1); |
|
|
|
if(attack) { |
|
|
|
if(attack) { |
|
|
|
const auto& enemy_dmg = world.component<Combat>(entity); |
|
|
|
int dmg = Random::uniform<int>(1, enemy_combat.damage); |
|
|
|
int dmg = Random::uniform<int>(1, enemy_dmg.damage); |
|
|
|
|
|
|
|
player_combat.hp -= dmg; |
|
|
|
player_combat.hp -= dmg; |
|
|
|
log.log(format("HIT! You took {} damage.", dmg)); |
|
|
|
log.log(format("HIT! You took {} damage.", dmg)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -87,6 +98,7 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) { |
|
|
|
void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) { |
|
|
|