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);
|
map.neighbors(out, motion.random);
|
||||||
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
|
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
|
// we need to send this event for everything that dies
|
||||||
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
|
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);
|
auto& enemy_ai = world.get<ai::EntityAI>(entity);
|
||||||
enemy_ai.set_state("enemy_found", true);
|
enemy_ai.set_state("enemy_found", true);
|
||||||
enemy_ai.update();
|
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")) {
|
if(enemy_ai.wants_to("kill_enemy")) {
|
||||||
auto& enemy_combat = world.get<Combat>(entity);
|
result.enemy_did = enemy_combat.attack(player_combat);
|
||||||
|
|
||||||
Events::Combat result {
|
|
||||||
player_combat.attack(enemy_combat),
|
|
||||||
enemy_combat.attack(player_combat)
|
|
||||||
};
|
|
||||||
|
|
||||||
if(world.has<Animation>(entity)) {
|
if(world.has<Animation>(entity)) {
|
||||||
auto& animation = world.get<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)) {
|
if(auto snd = world.get_if<Sound>(entity)) {
|
||||||
sound::play(snd->attack);
|
sound::play(snd->attack);
|
||||||
}
|
}
|
||||||
|
|
||||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,13 +190,11 @@ TEST_CASE("Confirm EntityAI behaves as expected", "[ai-enemy]") {
|
||||||
enemy.set_state("in_combat", true);
|
enemy.set_state("in_combat", true);
|
||||||
enemy.set_state("health_good", false);
|
enemy.set_state("health_good", false);
|
||||||
enemy.update();
|
enemy.update();
|
||||||
enemy.dump();
|
|
||||||
REQUIRE(enemy.wants_to("run_away"));
|
REQUIRE(enemy.wants_to("run_away"));
|
||||||
|
|
||||||
enemy.set_state("have_item", true);
|
enemy.set_state("have_item", true);
|
||||||
enemy.set_state("have_healing", true);
|
enemy.set_state("have_healing", true);
|
||||||
enemy.set_state("in_combat", false);
|
enemy.set_state("in_combat", false);
|
||||||
enemy.update();
|
enemy.update();
|
||||||
enemy.dump();
|
|
||||||
REQUIRE(enemy.wants_to("use_healing"));
|
REQUIRE(enemy.wants_to("use_healing"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue