From b20f46c15dce8b196dbb8890890978947745e094 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 1 Nov 2024 17:32:53 +0100 Subject: change flow architecture --- frontend/cmd/hit.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'frontend/cmd/hit.cpp') diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp index 2f39e8a..677bf4e 100644 --- a/frontend/cmd/hit.cpp +++ b/frontend/cmd/hit.cpp @@ -2,28 +2,32 @@ #include "backend/Location.h" #include "backend/RNG.h" #include "backend/print.h" +#include "backend/Dungeon.h" #include "../GameController.h" #include "../strings.h" +#include "../Exception.h" using namespace std; -FollowupAction GameController::cmd_hit(string & target_name) { +void GameController::cmd_hit(string & target_name) { RNG & rng = RNG::get(); - for (Enemy * enemy : this->player.get_location().get_enemies()) { + 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() > this->player.get_attack()) { + if (rng.rand_double() > player.get_attack()) { lprtf("Je hebt gemist!\n"); } else { - unsigned damage = rng.rand_int(this->player.weapon->get_damage_min(), this->player.weapon->get_damage_max() + 1); + unsigned damage = rng.rand_int(player.weapon->get_damage_min(), player.weapon->get_damage_max() + 1); enemy->take_damage(damage); lprtf("Je hebt %s geraakt en %d schade aangericht!\n", enemy->get_displayname().c_str(), damage); } - return FollowupAction::UPDATE; + + this->dungeon->update(); + return; } - lprtf("Vijand \"%s\" niet gevonden.\n", target_name.c_str()); - return FollowupAction::NONE; + throw Exception("Vijand \"%s\" niet gevonden.", target_name.c_str()); } -- cgit v1.2.3