changes to characters and potions, work in progress
This commit is contained in:
@ -2,10 +2,17 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
character::character(RNG &rng, const enum race &nrace):
|
||||
character::character(RNG *rng, const enum race &nrace):
|
||||
rng{rng},
|
||||
race{nrace}, HP{STARTING_HP[race]},
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {}
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]},
|
||||
base_hit_rate{1, 1} {}
|
||||
|
||||
void character::start_turn() {
|
||||
ATK = STARTING_ATK[race];
|
||||
DEF = STARTING_DEF[race];
|
||||
base_hit_rate = {1, 1};
|
||||
}
|
||||
|
||||
enum race character::get_race() const {
|
||||
return race;
|
||||
@ -31,7 +38,11 @@ int character::get_gold() const {
|
||||
return gold;
|
||||
}
|
||||
|
||||
float character::get_hitrate() const {
|
||||
float character::get_hitrate_real() const {
|
||||
return base_hit_rate.real();
|
||||
}
|
||||
|
||||
fraction character::get_hitrate() const {
|
||||
return base_hit_rate;
|
||||
}
|
||||
|
||||
@ -59,7 +70,7 @@ void character::set_gold(const int ngold) {
|
||||
gold = ngold;
|
||||
}
|
||||
|
||||
void character::set_hitrate(const float nhitrate) {
|
||||
void character::set_hitrate(const fraction nhitrate) {
|
||||
base_hit_rate = nhitrate;
|
||||
}
|
||||
|
||||
@ -105,11 +116,57 @@ const {
|
||||
return result;
|
||||
}
|
||||
|
||||
result character::apply(direction &dir, const potion_list &potions) {
|
||||
// TODO: implement this after implementing potions
|
||||
void character::apply(direction &dir, potion_list &plist) {
|
||||
for (size_t i = 0; i < plist.size(); ++i)
|
||||
if (pos + MOVE[dir] == plist[i]->get_pos()) {
|
||||
insert_potion(plist[i]);
|
||||
plist.erase(plist.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void character::insert_potion(potion *p) {
|
||||
effects.push_back(p);
|
||||
|
||||
for (int i = effects.size() - 1; i > 0; --i)
|
||||
if (p->get_priority() < effects[i - 1]->get_priority())
|
||||
std::swap(effects[i], effects[i - 1]);
|
||||
}
|
||||
|
||||
result character::apply_effects() {
|
||||
potion_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto p : effects) {
|
||||
p->apply(this->race, HP, ATK, DEF, base_hit_rate);
|
||||
|
||||
if (HP <= 0)
|
||||
return result::died;
|
||||
|
||||
if (p->get_duration() != 0)
|
||||
tmp.push_back(p);
|
||||
}
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
|
||||
std::swap(tmp, effects);
|
||||
|
||||
return result::fine;
|
||||
}
|
||||
|
||||
void character::discard_level_effects() {
|
||||
potion_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto p : effects)
|
||||
if (p->get_duration() != -1)
|
||||
tmp.push_back(p);
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
|
||||
std::swap(tmp, effects);
|
||||
}
|
||||
|
||||
// IMPORTANT: remember to check if player is on the stairs
|
||||
result character::move(const direction dir,
|
||||
const position_list &available_positions) {
|
||||
|
Reference in New Issue
Block a user