From d7012045bb61f117fb7b9c51ddd03e4c54f25fe6 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 31 Oct 2024 21:40:55 +0100 Subject: more more more more WIP --- frontend/cmd/hit.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'frontend/cmd/hit.cpp') diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp index 86d596a..d3cb683 100644 --- a/frontend/cmd/hit.cpp +++ b/frontend/cmd/hit.cpp @@ -1,9 +1,29 @@ +#include "backend/Enemy.h" +#include "backend/Location.h" +#include "backend/RNG.h" +#include "backend/print.h" + #include "../Player.h" +#include "../strings.h" using namespace std; -FollowupAction Player::cmd_hit(string & argv) { - // TODO - return FollowupAction::UPDATE; +FollowupAction Player::cmd_hit(string & target_name) { + RNG & rng = RNG::get(); + for (Enemy * enemy : this->location.get_enemies()) { + if (str_lower(enemy->get_name().c_str()) != str_lower(target_name)) continue; + + if (rng.rand_double() > this->get_attack()) { + lprtf("Je hebt gemist!\n"); + } else { + unsigned damage = rng.rand_int(this->weapon->get_damage_min(), this->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; + } + + lprtf("Vijand \"%s\" niet gevonden.\n", target_name.c_str()); + return FollowupAction::NONE; } -- cgit v1.2.3