Enemies will now get scared when their health is low.
This commit is contained in:
parent
00f76dfb34
commit
c4e01775bc
2 changed files with 27 additions and 10 deletions
35
systems.cpp
35
systems.cpp
|
@ -83,6 +83,12 @@ void System::enemy_pathing(GameLevel &level) {
|
|||
map.neighbors(out, motion.random);
|
||||
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
|
||||
}
|
||||
|
||||
fmt::println("------- ARE THEY SCARED? {}", ent);
|
||||
enemy_ai.dump();
|
||||
if(enemy_ai.wants_to("run_away")) {
|
||||
dbc::log("ENEMY IS SCARED");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -150,6 +156,13 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
|
|||
}
|
||||
// we need to send this event for everything that dies
|
||||
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
|
||||
} else if(float(combat.hp) / float(combat.max_hp) < 0.5f) {
|
||||
fmt::println("ENEMY HP low: {}/{}", combat.hp, combat.max_hp);
|
||||
if(world.has<ai::EntityAI>(ent)) {
|
||||
auto& enemy_ai = world.get<ai::EntityAI>(ent);
|
||||
enemy_ai.set_state("health_good", false);
|
||||
enemy_ai.update();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -195,14 +208,20 @@ void System::combat(GameLevel &level) {
|
|||
auto& enemy_ai = world.get<ai::EntityAI>(entity);
|
||||
enemy_ai.set_state("enemy_found", true);
|
||||
enemy_ai.update();
|
||||
auto& enemy_combat = world.get<Combat>(entity);
|
||||
|
||||
Events::Combat result {
|
||||
player_combat.attack(enemy_combat), 0
|
||||
};
|
||||
|
||||
if(!enemy_combat.dead && world.has<ai::EntityAI>(entity)) {
|
||||
auto& enemy_ai = world.get<ai::EntityAI>(entity);
|
||||
enemy_ai.set_state("in_combat", true);
|
||||
enemy_ai.update();
|
||||
}
|
||||
|
||||
if(enemy_ai.wants_to("kill_enemy")) {
|
||||
auto& enemy_combat = world.get<Combat>(entity);
|
||||
|
||||
Events::Combat result {
|
||||
player_combat.attack(enemy_combat),
|
||||
enemy_combat.attack(player_combat)
|
||||
};
|
||||
result.enemy_did = enemy_combat.attack(player_combat);
|
||||
|
||||
if(world.has<Animation>(entity)) {
|
||||
auto& animation = world.get<Animation>(entity);
|
||||
|
@ -212,9 +231,9 @@ void System::combat(GameLevel &level) {
|
|||
if(auto snd = world.get_if<Sound>(entity)) {
|
||||
sound::play(snd->attack);
|
||||
}
|
||||
|
||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||
}
|
||||
|
||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue