Event system now accepts any data and the GUI receives simpler events with data for them.
This commit is contained in:
parent
0e79288afc
commit
ed9d0de8e0
7 changed files with 45 additions and 57 deletions
31
systems.cpp
31
systems.cpp
|
@ -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>();
|
||||
const auto& player_position = world.get<Position>(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);
|
||||
|
||||
if(found) {
|
||||
// save some keystrokes
|
||||
using eGUI = Events::GUI;
|
||||
|
||||
for(auto entity : nearby) {
|
||||
if(world.has<Combat>(entity)) {
|
||||
auto& enemy_combat = world.get<Combat>(entity);
|
||||
int player_dmg = player_combat.attack(enemy_combat);
|
||||
|
||||
if(player_dmg > 0) {
|
||||
world.send<eGUI>(eGUI::HIT, entity);
|
||||
} else {
|
||||
world.send<eGUI>(eGUI::MISS, entity);
|
||||
}
|
||||
Events::Combat result {
|
||||
player_combat.attack(enemy_combat),
|
||||
enemy_combat.attack(player_combat)
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||
} 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 &inventory = world.get<Inventory>(player.entity);
|
||||
|
||||
world.send<Events::GUI>(Events::GUI::LOOT, entity, loot);
|
||||
inventory.gold += loot.amount;
|
||||
collider.remove(loot_pos.location);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue