- Moved calc_dmg to characters.h
- put vampire into new source files
This commit is contained in:
31
src/vampire.cc
Normal file
31
src/vampire.cc
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user