- Moved calc_dmg to characters.h

- put vampire into new source files
This commit is contained in:
a25liang
2024-07-02 20:39:48 -04:00
parent eea910ae33
commit 234f06191a
7 changed files with 74 additions and 15 deletions

31
src/vampire.cc Normal file
View File

@ -0,0 +1,31 @@
#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_hitrate);
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;
}