#include "hacker.h"

#include "constants.h"

hacker::hacker(RNG *rng, const feature enabled_features, const position &pos,
               const int gen_room_num):
        enemy_base{rng, enabled_features, HACKER, pos, gen_room_num, "h"} {}

const char *hacker::get_race_name() const {
        return "Hacker";
}

long_result hacker::get_hit(character *ch, const int tATK,
                            const fraction &hit_rate) {
        if (rng->trial(hit_rate)) {
                int tmp = calc_dmg(tATK, DEF);
                tmp = tmp > HP ? HP : tmp;
                HP -= tmp;

                if (HP == 0)
                        return {result::HIT, rand_str()};

                return {result::HIT, rand_str()};
        }

        return {MISS, rand_str()};
}

std::string hacker::rand_str() {
        size_t len = rng->rand_between(RAND_STR_LEN_MIN, RAND_STR_LEN_MAX);
        std::string result{""};

        for (size_t i = 0; i < len; ++i)
                result += static_cast<char>(rng->rand_between(PRINT_CHAR_MIN,
                                            PRINT_CHAR_MAX + 1));

        result += ' ';

        return result;
}
