diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 13:18:50 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-02 13:18:50 +0100 |
commit | 5a675c5e6833e98b92b55396594bc0d607b98903 (patch) | |
tree | b252fafe921e7734a13d796b950e5ab817a22a1f /frontend/cmd/hit.cpp | |
parent | 671a25463419691bc6c8d11bd57d932bdea9632b (diff) |
clean up code + implement teleport consumable
Diffstat (limited to 'frontend/cmd/hit.cpp')
-rw-r--r-- | frontend/cmd/hit.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp index 94bde03..cb5c56e 100644 --- a/frontend/cmd/hit.cpp +++ b/frontend/cmd/hit.cpp @@ -6,28 +6,27 @@ #include "backend/Exception.h" #include "../GameController.h" -#include "../strings.h" +#include "../util.h" using namespace std; void GameController::cmd_hit(string & target_name) { RNG & rng = RNG::get(); Player & player = this->dungeon->get_player(); - for (Enemy * enemy : player.get_location().get_enemies()) { - if (str_lower(enemy->get_name().c_str()) != str_lower(target_name)) continue; - if (rng.rand_double() > player.get_attack()) { - lprtf("Je hebt gemist!\n"); - } else { - unsigned damage = rng.rand_int(player.weapon->get_damage()); - enemy->take_damage(damage); - lprtf("Je hebt %s geraakt en %d schade aangericht!\n", enemy->get_displayname().c_str(), damage); - } + auto it = find_if_range(player.get_location().get_enemies(), by_name_case_insensitive(target_name)); + if (!it) + throw Exception("vijand \"%s\" niet gevonden", target_name.c_str()); + Enemy & enemy = **it; - this->dungeon->update(); - return; + if (rng.rand_double() > player.get_attack()) { + lprtf("Je hebt gemist!\n"); + } else { + unsigned damage = rng.rand_int(player.weapon->get_damage()); + enemy.take_damage(damage); + lprtf("Je hebt %s geraakt en %d schade aangericht!\n", enemy.get_displayname().c_str(), damage); } - throw Exception("vijand \"%s\" niet gevonden", target_name.c_str()); + this->dungeon->update(); } |