31 lines
858 B
C++
31 lines
858 B
C++
#include "vampire.h"
|
|
#include <algorithm>
|
|
#include <math.h>
|
|
|
|
|
|
result vampire::attack(const direction dir, const character_list &chlist) {
|
|
position tmp{pos + MOVE[dir]};
|
|
|
|
for (auto &ch : chlist)
|
|
if (tmp == ch->get_position()) {
|
|
auto res = ch->get_hit(race, ATK, base_hit_rate);
|
|
if (res != result::miss) {
|
|
HP += GAIN_HP;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
return result::fine;
|
|
}
|
|
|
|
result vampire::get_hit(const enum race &race, const int atk,
|
|
const float hitrate) {
|
|
if (rng.rand_num() <= hitrate * (float)RAND_MAX)
|
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
|
|
|
if (HP == 0)
|
|
return result::died;
|
|
|
|
return result::hit;
|
|
}
|