|
|
@ -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,14 +76,26 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
if(found) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
int attack = Random::uniform<int>(0,1); |
|
|
|
auto& enemy_combat = world.component<Combat>(entity); |
|
|
|
if(attack) { |
|
|
|
int player_dmg = Random::uniform<int>(1, enemy_combat.damage); |
|
|
|
const auto& enemy_dmg = world.component<Combat>(entity); |
|
|
|
enemy_combat.hp -= player_dmg; |
|
|
|
int dmg = Random::uniform<int>(1, enemy_dmg.damage); |
|
|
|
log.log(format("YOU HIT {} damage! Enemy has {} HP left.", |
|
|
|
player_combat.hp -= dmg; |
|
|
|
player_dmg, enemy_combat.hp)); |
|
|
|
log.log(format("HIT! You took {} damage.", dmg)); |
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
} else { |
|
|
|
log.log("You dodged! Run!"); |
|
|
|
int attack = Random::uniform<int>(0,1); |
|
|
|
|
|
|
|
if(attack) { |
|
|
|
|
|
|
|
int dmg = Random::uniform<int>(1, enemy_combat.damage); |
|
|
|
|
|
|
|
player_combat.hp -= dmg; |
|
|
|
|
|
|
|
log.log(format("HIT! You took {} damage.", dmg)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.log("You dodged! Run!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|