#include "goblin.h"

#include "constants.h"

goblin::goblin(RNG *rng, const feature enabled_features):
        player_base{rng, enabled_features, race::GOBLIN} {};

const char *goblin::get_race_name() const {
        return "Goblin";
}

long_result goblin::attack(character *ch) {
        if (ch == nullptr)
                return {result::NOTHING,
                        "PC tried to attack thin air. "};

        auto res = ch->get_hit(this, ATK, base_hit_rate);

        if (ch->is_dead()) {
                gold_cnt += GAIN_GOLD;
                res.msg += "PC feels greedy. ";
        }

        return res;
}

long_result goblin::get_hit(character *ch, const int tATK,
                            const fraction &hit_rate) {
        if (rng->trial(hit_rate)) {
                int tmp = calc_dmg(tATK, DEF);
                std::string msg = "";

                if (ch->get_race() == ORC) {
                        msg += "PC feels scared. ";
                        tmp *= ORC_DMG_MUL;
                }

                tmp = tmp > HP ? HP : tmp;
                HP -= tmp;
                msg += ch->get_abbrev() + " deals " +
                       std::to_string(tmp) +
                       " damage to PC. ";

                if (HP == 0)
                        return {result::DIED,
                                msg + "PC is slain by " +
                                ch->get_abbrev() + ". "};

                return {result::HIT, msg};
        }

        return {result::MISS, ch->get_abbrev() + " tried to hit PC but missed. "};
}
