#include "borrow_life.h"

#include <algorithm>
#include "constants.h"

borrow_life::borrow_life(const position &pos):
        potion{potion_type::BORROW_LIFE, DURATION, pos} {}

void borrow_life::apply(const enum race &race, int &HP, int &ATK,
                        int &DEF, fraction &base_hit_rate) {
        if (remaining_duration == DURATION)
                HP += GIVE_HP * (race == DROW ? DROW_POTION_MUL : 1);

        if (remaining_duration != 0)
                --remaining_duration;

        if (remaining_duration == 0) {
                HP -= LOSE_HP * (race == DROW ? DROW_POTION_MUL : 1);
                HP = HP < 0 ? 0 : HP;
        }
}

int borrow_life::get_priority() const {
        return CALC_LAST;
}

const char *borrow_life::get_name() const {
        return "BL";
}
