38 lines
1014 B
C++
38 lines
1014 B
C++
#include "races.h"
|
|
|
|
#include <algorithm>
|
|
#include <math.h>
|
|
|
|
shade::shade(const position_list &available_positions):
|
|
character{race::rshade} {
|
|
pos = available_positions[rng.rand_under(available_positions.size())];
|
|
gold = 0;
|
|
hostile = true;
|
|
}
|
|
|
|
result shade::attack(const direction dir, const character_list &chlist) {
|
|
position tmp{pos + MOVE[dir]};
|
|
|
|
for (auto &ch : chlist)
|
|
if (tmp == ch->get_position()) {
|
|
return ch->get_hit(race, ATK, base_hitrate);
|
|
}
|
|
|
|
return result::fine;
|
|
}
|
|
|
|
int calc_dmg(const int ATK, const int DEF) {
|
|
return ceil((100 / (100 + DEF)) * ATK);
|
|
}
|
|
|
|
result shade::get_hit(const enum race &race, const int atk,
|
|
const float hitrate) {
|
|
if (rng.rand_num() <= hitrate * (float)RAND_MAX) // This is a hit!
|
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
|
|
|
if (HP == 0)
|
|
return result::died;
|
|
|
|
return result::hit;
|
|
}
|