format
This commit is contained in:
@ -3,156 +3,154 @@
|
||||
#include <algorithm>
|
||||
|
||||
character::character(RNG &rng, const enum race &nrace):
|
||||
rng{rng},
|
||||
race{nrace}, HP{STARTING_HP[race]},
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {}
|
||||
rng{rng},
|
||||
race{nrace}, HP{STARTING_HP[race]},
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {}
|
||||
|
||||
enum race character::get_race() const {
|
||||
return race;
|
||||
return race;
|
||||
}
|
||||
|
||||
position character::get_position() const {
|
||||
return pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
int character::get_HP() const {
|
||||
return HP;
|
||||
return HP;
|
||||
}
|
||||
|
||||
int character::get_ATK() const {
|
||||
return ATK;
|
||||
return ATK;
|
||||
}
|
||||
|
||||
int character::get_DEF() const {
|
||||
return DEF;
|
||||
return DEF;
|
||||
}
|
||||
|
||||
int character::get_gold() const {
|
||||
return gold;
|
||||
return gold;
|
||||
}
|
||||
|
||||
float character::get_hitrate() const {
|
||||
return base_hit_rate;
|
||||
return base_hit_rate;
|
||||
}
|
||||
|
||||
bool character::is_hostile() const {
|
||||
return hostile;
|
||||
return hostile;
|
||||
}
|
||||
|
||||
void character::set_position(const position &npos) {
|
||||
pos = npos;
|
||||
pos = npos;
|
||||
}
|
||||
|
||||
void character::set_HP(const int nHP) {
|
||||
HP = nHP;
|
||||
HP = nHP;
|
||||
}
|
||||
|
||||
void character::set_ATK(const int nATK) {
|
||||
ATK = nATK;
|
||||
ATK = nATK;
|
||||
}
|
||||
|
||||
void character::set_DEF(const int nDEF) {
|
||||
DEF = nDEF;
|
||||
DEF = nDEF;
|
||||
}
|
||||
|
||||
void character::set_gold(const int ngold) {
|
||||
gold = ngold;
|
||||
gold = ngold;
|
||||
}
|
||||
|
||||
void character::set_hitrate(const float nhitrate) {
|
||||
base_hit_rate = nhitrate;
|
||||
base_hit_rate = nhitrate;
|
||||
}
|
||||
|
||||
void character::set_hostile(const bool is_hostile) {
|
||||
hostile = is_hostile;
|
||||
hostile = is_hostile;
|
||||
}
|
||||
|
||||
void character::apply_buff(const stat_name statn, const int amount) {
|
||||
// TODO: add checks for bounds
|
||||
switch (statn) {
|
||||
case stat_name::HP:
|
||||
HP += amount;
|
||||
break;
|
||||
// TODO: add checks for bounds
|
||||
switch (statn) {
|
||||
case stat_name::HP:
|
||||
HP += amount;
|
||||
break;
|
||||
|
||||
case stat_name::ATK:
|
||||
ATK += amount;
|
||||
break;
|
||||
case stat_name::ATK:
|
||||
ATK += amount;
|
||||
break;
|
||||
|
||||
case stat_name::DEF:
|
||||
DEF += amount;
|
||||
break;
|
||||
case stat_name::DEF:
|
||||
DEF += amount;
|
||||
break;
|
||||
|
||||
case stat_name::hostile: {
|
||||
if (amount > 0)
|
||||
hostile = true;
|
||||
else
|
||||
hostile = false;
|
||||
case stat_name::hostile: {
|
||||
if (amount > 0)
|
||||
hostile = true;
|
||||
else
|
||||
hostile = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
direction_list character::moveable(const position_list &available_positions)
|
||||
const {
|
||||
direction_list result;
|
||||
direction_list result;
|
||||
|
||||
for (int i = 0; i < DIRECTION_CNT; ++i)
|
||||
if (find(available_positions, pos + MOVE[i])
|
||||
!= available_positions.size())
|
||||
result.push_back((direction)i);
|
||||
for (int i = 0; i < DIRECTION_CNT; ++i)
|
||||
if (find(available_positions, pos + MOVE[i])
|
||||
!= available_positions.size())
|
||||
result.push_back((direction)i);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
result character::apply(direction &dir, const potion_list &potions) {
|
||||
// TODO: implement this after implementing potions
|
||||
return result::fine;
|
||||
// TODO: implement this after implementing potions
|
||||
return result::fine;
|
||||
}
|
||||
|
||||
position_list remove_from_list(const position_list &sorted_positions,
|
||||
position_list excluded) {
|
||||
std::sort(excluded.begin(), excluded.end());
|
||||
std::sort(excluded.begin(), excluded.end());
|
||||
|
||||
position_list result{sorted_positions.size() - excluded.size()};
|
||||
position_list result{sorted_positions.size() - excluded.size()};
|
||||
|
||||
auto exc = excluded.begin();
|
||||
auto exc = excluded.begin();
|
||||
|
||||
for (auto src : sorted_positions) {
|
||||
if (exc != excluded.end() && src == *exc)
|
||||
++exc;
|
||||
else
|
||||
result.push_back(src);
|
||||
}
|
||||
for (auto src : sorted_positions) {
|
||||
if (exc != excluded.end() && src == *exc)
|
||||
++exc;
|
||||
else
|
||||
result.push_back(src);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
// IMPORTANT: remember to check if player is on the stairs
|
||||
result character::move(const direction dir,
|
||||
const position_list &available_positions) {
|
||||
if (find(available_positions, pos + MOVE[dir])
|
||||
if (find(available_positions, pos + MOVE[dir])
|
||||
!= available_positions.size()) {
|
||||
pos += MOVE[dir];
|
||||
return result::moved;
|
||||
}
|
||||
pos += MOVE[dir];
|
||||
return result::moved;
|
||||
}
|
||||
|
||||
return result::fine;
|
||||
return result::fine;
|
||||
}
|
||||
|
||||
result character::move_or_attack(const direction dir,
|
||||
const position_list &available_positions,
|
||||
character_list &chlist) {
|
||||
auto res = this->move(dir, available_positions);
|
||||
auto res = this->move(dir, available_positions);
|
||||
|
||||
if (res != result::fine)
|
||||
return res;
|
||||
if (res != result::fine)
|
||||
return res;
|
||||
|
||||
return this->attack(dir, chlist);
|
||||
return this->attack(dir, chlist);
|
||||
}
|
||||
|
||||
|
||||
int calc_dmg(const int ATK, const int DEF) {
|
||||
return ceil((100 / (100 + DEF)) * ATK);
|
||||
return ceil((100 / (100 + DEF)) * ATK);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user