|
|
@ -91,7 +91,7 @@ void System::death(DinkyECS::World &world) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
void System::collision(DinkyECS::World &world, Player &player) { |
|
|
|
auto& collider = world.get_the<spatial_map>(); |
|
|
|
auto& collider = world.get_the<spatial_map>(); |
|
|
|
const auto& player_position = world.get<Position>(player.entity); |
|
|
|
const auto& player_position = world.get<Position>(player.entity); |
|
|
|
auto& player_combat = world.get<Combat>(player.entity); |
|
|
|
auto& player_combat = world.get<Combat>(player.entity); |
|
|
@ -100,36 +100,23 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
if(found) { |
|
|
|
// save some keystrokes
|
|
|
|
|
|
|
|
using eGUI = Events::GUI; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto entity : nearby) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
if(world.has<Combat>(entity)) { |
|
|
|
if(world.has<Combat>(entity)) { |
|
|
|
auto& enemy_combat = world.get<Combat>(entity); |
|
|
|
auto& enemy_combat = world.get<Combat>(entity); |
|
|
|
int player_dmg = player_combat.attack(enemy_combat); |
|
|
|
|
|
|
|
|
|
|
|
Events::Combat result { |
|
|
|
if(player_dmg > 0) { |
|
|
|
player_combat.attack(enemy_combat), |
|
|
|
world.send<eGUI>(eGUI::HIT, entity); |
|
|
|
enemy_combat.attack(player_combat) |
|
|
|
} else { |
|
|
|
}; |
|
|
|
world.send<eGUI>(eGUI::MISS, entity); |
|
|
|
|
|
|
|
} |
|
|
|
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result); |
|
|
|
|
|
|
|
|
|
|
|
if(enemy_combat.hp > 0) { |
|
|
|
|
|
|
|
int enemy_dmg = enemy_combat.attack(player_combat); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(enemy_dmg > 0) { |
|
|
|
|
|
|
|
world.send<eGUI>(eGUI::HIT, player.entity); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
world.send<eGUI>(eGUI::MISS, player.entity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
world.send<eGUI>(eGUI::DEAD, entity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if(world.has<Loot>(entity)) { |
|
|
|
} else if(world.has<Loot>(entity)) { |
|
|
|
world.send<eGUI>(eGUI::LOOT, entity); |
|
|
|
auto loot = world.get<Loot>(entity); |
|
|
|
auto &loot = world.get<Loot>(entity); |
|
|
|
|
|
|
|
auto &loot_pos = world.get<Position>(entity); |
|
|
|
auto &loot_pos = world.get<Position>(entity); |
|
|
|
auto &inventory = world.get<Inventory>(player.entity); |
|
|
|
auto &inventory = world.get<Inventory>(player.entity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
world.send<Events::GUI>(Events::GUI::LOOT, entity, loot); |
|
|
|
inventory.gold += loot.amount; |
|
|
|
inventory.gold += loot.amount; |
|
|
|
collider.remove(loot_pos.location); |
|
|
|
collider.remove(loot_pos.location); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|