#include "echoing_resilience.h"

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

echoing_resilience::echoing_resilience(const position &pos):
        potion{potion_type::ECHOING_RESIL, DURATION, pos} {}

void echoing_resilience::apply(const enum race &race, int &HP, int &ATK,
                               int &DEF, fraction &base_hit_rate) {
        if (remaining_duration != 0) {
                int tmp = GAIN_HEALTH * (race == DROW ? DROW_POTION_MUL : 1);

                if (HP < MAX_HP[race])
                        HP = std::min(HP + tmp, MAX_HP[race]);

                ATK -= LOSE_ATK * (race == DROW ? DROW_POTION_MUL : 1);
                DEF -= LOSE_DEF * (race == DROW ? DROW_POTION_MUL : 1);

                ATK = ATK < 0 ? 0 : ATK;
                DEF = DEF < 0 ? 0 : DEF;

                --remaining_duration;
        }
}

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

const char *echoing_resilience::get_name() const {
        return "ER";
}
